Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualtrevex

Posted 24 December 2012 - 03:49 AM

Thanks alot indeed I forgot to set the VertexBuffer and since the vertices of my cube are quite similar, I didn't notice that. Can't believe I haven't noticed that...

The only thing left now is a bug in my lighting code, some surfaces stay black... The scene currently uses a single directional light for testing!
float3 CalcLighting(in float3 normal, in float3 position, in float3 diffuseAlbedo, in float3 specularAlbedo, in float specularPower, uniform int gLightingMode) 
{  
float3 L = 0; 
float attenuation = 1.0f; 
if (gLightingMode == POINTLIGHT || gLightingMode == SPOTLIGHT)
{
L = LightPos - position; 
float dist = length(L); 
attenuation = max(0, 1.0f - (dist / LightRange.x)); 
L /= dist;
}
else if (gLightingMode == DIRECTIONALLIGHT)
{
L = -LightDirection; }if (gLightingMode == SPOTLIGHT)
{
float3 L2 = LightDirection; 
float rho = dot(-L, L2); 
attenuation *= saturate((rho - SpotlightAngles.y) / (SpotlightAngles.x - SpotlightAngles.y)); 
}
float nDotL = saturate(dot(normal, L)); 
float3 diffuse = nDotL * LightColor * diffuseAlbedo;
float3 V = CameraPos - position; 
float3 H = normalize(L + V);
float3 specular = pow(saturate(dot(normal, H)), specularPower) * LightColor * specularAlbedo.xyz * nDotL; 
return (diffuse + specular) * attenuation;
}
The basic algorithm is basically out of a book so I assumed there would be nothing wrong the only thing I changed is using if and a uniform to embed it in an effects file.

The Buffers are filled with informations and there is nothing missing, these are values of a black pixel that is supposed to have some color:
11h3rxj.png

EDIT:

Lighting Shader Code on pastebin http://pastebin.com/8gbYBLCX, because the code tags seem to be buggy currently either escaping html as well or completly breaking formating

#2trevex

Posted 24 December 2012 - 03:47 AM

Thanks alot indeed I forgot to set the VertexBuffer and since the vertices of my cube are quite similar, I didn't notice that. Can't believe I haven't noticed that...

The only thing left now is a bug in my lighting code, some surfaces stay black... The scene currently uses a single directional light for testing!

 

float3 CalcLighting(in float3 normal, in float3 position, in float3 diffuseAlbedo, in float3 specularAlbedo, in float specularPower, uniform int gLightingMode) {  float3 L = 0; float attenuation = 1.0f; if (gLightingMode == POINTLIGHT || gLightingMode == SPOTLIGHT){L = LightPos - position; float dist = length(L); attenuation = max(0, 1.0f - (dist / LightRange.x)); L /= dist;}else if (gLightingMode == DIRECTIONALLIGHT){L = -LightDirection; }if (gLightingMode == SPOTLIGHT){float3 L2 = LightDirection; float rho = dot(-L, L2); attenuation *= saturate((rho - SpotlightAngles.y) / (SpotlightAngles.x - SpotlightAngles.y)); }float nDotL = saturate(dot(normal, L)); float3 diffuse = nDotL * LightColor * diffuseAlbedo;float3 V = CameraPos - position; float3 H = normalize(L + V); float3 specular = pow(saturate(dot(normal, H)), specularPower) * LightColor * specularAlbedo.xyz * nDotL; return (diffuse + specular) * attenuation; }

The basic algorithm is basically out of a book so I assumed there would be nothing wrong the only thing I changed is using if and a uniform to embed it in an effects file.

The Buffers are filled with informations and there is nothing missing, these are values of a black pixel that is supposed to have some color:
11h3rxj.png

EDIT:

Lighting Shader Code on pastebin http://pastebin.com/8gbYBLCX, because the code tags seem to be buggy currently either escaping html as well or completly breaking formating


#1trevex

Posted 24 December 2012 - 03:41 AM

Thanks alot indeed I forgot to set the VertexBuffer and since the vertices of my cube are quite similar, I didn't notice that. Can't believe I haven't noticed that...

 

The only thing left now is a bug in my lighting code, some surfaces stay black... The scene currently uses a single directional light for testing!

 

 
</p><div>float3 CalcLighting(in float3 normal, in float3 position, in float3 diffuseAlbedo, in float3 specularAlbedo, in float specularPower, uniform int gLightingMode) </div>
<div>{  </div>
<div>float3 L = 0; </div>
<div>float attenuation = 1.0f; </div>
<div>if (gLightingMode == POINTLIGHT || gLightingMode == SPOTLIGHT)</div>
<div>{</div>
<div>L = LightPos - position; </div>
<div>float dist = length(L); </div>
<div>attenuation = max(0, 1.0f - (dist / LightRange.x)); </div>
<div>L /= dist;</div>
<div>}</div>
<div>else if (gLightingMode == DIRECTIONALLIGHT)</div>
<div>{</div>
<div>L = -LightDirection; </div>
<div>}</div>
<div>if (gLightingMode == SPOTLIGHT)</div>
<div>{</div>
<div>float3 L2 = LightDirection; </div>
<div>float rho = dot(-L, L2); </div>
<div>attenuation *= saturate((rho - SpotlightAngles.y) / (SpotlightAngles.x - SpotlightAngles.y)); </div>
<div>}</div>
<div>float nDotL = saturate(dot(normal, L)); </div>
<div>float3 diffuse = nDotL * LightColor * diffuseAlbedo;</div>
<div>float3 V = CameraPos - position; </div>
<div>float3 H = normalize(L + V); </div>
<div>float3 specular = pow(saturate(dot(normal, H)), specularPower) * LightColor * specularAlbedo.xyz * nDotL; </div>
<div>return (diffuse + specular) * attenuation; </div>
<div>} </div>

 

The basic algorithm is basically out of a book so I assumed there would be nothing wrong the only thing I changed is using if and a uniform to embed it in an effects file.

 

The Buffers are filled with informations and there is nothing missing, these are values of a black pixel that is supposed to have some color:

11h3rxj.png


PARTNERS