Calculating Specular and GLFlat/Smooth

update: The problem seems to be the G and B values. When I change them, nothing happens. Its weird because by default the values are 1.0,1.0,1.0,1.0 for specular lighting.

Hi guys,

first off, thanks for your help. I have been having difficulty with my glsl shader. I am suppose to implement the phoung model in the vertex shader. It seems to work for the most part, except my specular value is wrong I believe. When I run the program, my model appears red instead of white. I have two windows running. One is the opengl implementation which shows the correct output. I am trying to get my shader to match its output. Here is my code. I have gone through the red book, and can’t find anything wrong in my calculation

//calculate specular term
//for the specular term, we need to get the halfway vector between the viewer and light.
//If L · n is less than or equal to zero, there is no specular component at the vertex

if(dot(L,normal) <= 0.0)
specularTerm = specularTerm * vec4(0.0,0.0,0.0,0.0);
else{
//calculate the halfway vector and normalize it
halfwayVector =normalize(gl_LightSource[0].halfVector.xyz);

//this gives us the “s” value from opengl pg 244
//so now calculate the specular term
//(max {s · n, 0})^shininess * specularlight * specularmaterial

float maxV = max(dot(halfwayVector,normal),0.0);

//we dont want 0^0 possibility in opengl
if(maxV > 0.0)
specularTerm = pow(maxV,shine) * gl_LightSource[0].specular * specularMaterial;
else//since 0 raised to anything is 1
specularTerm = gl_LightSource[0].specular * specularMaterial;
}

Another problem I am having is with the shading type. My shader doesn’t seem to recognize when glEnable(Flat) and glEnable(smooth) are on, yet it recognizes when lights are on/off.

Here is a picture

Thanks for your help!

I think you should post the entire shader so we can see the all the terms defined, eg Light vector L

ok, here you go.

Also, everything seems to be working except the specular. if I set my specular values all to 0 then my shader matches my opengl image.

http://pastebin.com/yvAWUbiV

then my fragment shader is

varying vec4 vColor;
void main(){
gl_FragColor = vColor;
}

thanks!

See this post:

and this to tweak its behavior

Change subexpressions in your shader to null out terms (e.g. multiply one term by 0), and should be pretty simple to figure out where the red mask is coming from.

Also, print out the uniform values you think you’re feeding the shader. Betting one of those is set to a decidedly reddish value.

[QUOTE=Dark Photon;1236857]Change subexpressions in your shader to null out terms (e.g. multiply one term by 0), and should be pretty simple to figure out where the red mask is coming from.

Also, print out the uniform values you think you’re feeding the shader. Betting one of those is set to a decidedly reddish value.[/QUOTE]

wow thanks for your help! I wasn’t passing the shinyness value correctly! I fixed it and now it works! Thanks!!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.