Not sure where to post these types of questions I will try here.
I am learning GLSL stuff and I am having a little trouble with my specular component.
Many tutorials I have read use gl_LightSource[0].halfVector to compute the specular color of the pixel, but mine always seems to return zero.
Can someone take a peek below at when I am doing? The code works properly in Shader Designer, but the model appears solid red in Irrlicht.
Maybe there is somthing I need to do with the light in Irrlicht? Or maybe someone can show me how to compute the half vector myself?
Code: Select all
//my vert
varying vec3 Normal;
varying vec3 Light;
varying vec3 HalfVector;
void main (void)
{
Normal = normalize(gl_NormalMatrix * gl_Normal);
Light = normalize(gl_LightSource[0].position.xyz);
vec4 pos = gl_ModelViewMatrix*gl_Vertex;
/////////////////////////////////////////////////////////////
///this is where I retrieve the light's half vector/////////
HalfVector = normalize(gl_LightSource[0].halfVector.xyz);//
//////////////////////////////////////////////////////////
gl_Position = ftransform();
}
Code: Select all
// my frag
varying vec3 Normal;
varying vec3 Light;
varying vec3 HalfVector;
void main(void)
{
Normal = normalize(Normal);
float Diffuse = max(dot(Normal, Light),0.0);
///////////////////////////////////////////////////////////////
// This is where I use the half vector to get the spec ///////
float Specular = pow(max(dot(Normal,HalfVector),0.0), 8.0);//
////////////////////////////////////////////////////////////
gl_FragColor = (vec4(0,0,1,1) * Diffuse)+Specular;
///////////////////////////////////////////////////////////
//This is my debug line, turning the mesh red//////
//if the spec calculation returns zero //////
if (Specular == 0) gl_FragColor = vec4(1,0,0,1);
}
