Hello, I’d like to know what the vector inNormal stands for and on what space it is??
can anyone tell me if what i am stating in comments is right??
vec4 position = vec4(inPosition, 1.0); // position of vertex in model space
vec4 vertexViewSpace = gl_WorldViewMatrix * position; // pposition of the vertex in view Space
vec4 vertexCameraSpace = vertexViewSpace - vec4(g_CameraPosition,0.0); // negative vector between vertex and camera
vec4 normal = gl_WorldViewMatrix * vec4(inNormal,1.0); // normal vector of the vertex in the view sapce (aka camera space??) [/java]
inNormal is the normal vector of the vertex in model space.
But normals are bit particular. Usualy you need them in view space (most of the time for lighting) and for this you need to multiply them by the inverse transpose worldview matrix.
We have a convenient global uniform called g_NormalMatrix for this.
I’m doing this :
teh shader is behaving a weird way, its as if the whole model gets the frag color all the time… not the fragments
and My model is always Black I don’t understand why the dot product of the two normalized vectors is always inf to 0.5 ;/
vertex shader : [java]
position = g_WorldMatrix * vec4(inPosition, 1.0); // position of the vertex
varyingNormalDirection = normalize(vec3(vec4(inNormal, 0.0) * g_NormalMatrix)); // normal in world space,[/java]
I don’t have time to explain too much atm and didn’t look at the logic completely. But In your vert shader you are converting it to eye space (not world space like your comment describes), you are also multiplying them the wrong way round.
g_NormalMatrix converts normals to eye/view space, not world space! (as you have found out)
What you have will work if you have uniform scale (the scale for x, y, and z are the same). If you don’t then you will get inconsistent results. You will want to use g_WorldMatrixInverseTranspose to be sure it will work. Its also a 3x3 matrix, so you can multiply it with the inNormal directly.