Hi all,
I have a question on a discussion about point light gauraud shading shader in opengl super bible. The code gets the object space position like this (mvMatrix is the modelview matrix).

vec4 pos4 = mvMatrix* vVertex;

Then the part i dont understand, it does a division by w to get pos3 as follows

vec3 pos3 = pos4.xyz/pos4.w;

Form what i think if we are not multiplying by the projection matrix the w coord. would always be 1 wouldnt it? Then why do I need this division by w?
Regards,
Mobeen

If you can be 100% sure this coordinate is always in euclidian space, then w will always be 1. But since there will have many operations on the modelview matrix, I think you can’t assert this will always be true.

If you can be 100% sure this coordinate is always in euclidian space, then w will always be 1. But since there will have many operations on the modelview matrix, I think you can’t assert this will always be true.

Um, why not? It’s a pretty legitimate assumption; most transforms are your typical scale/rotation/translation. Even sheer transforms don’t necessitate a non-1 W.

Furthermore, if it is working in some kind of homogeneous camera space, then the text around the code should probably mention that. Otherwise, it’s just a confusing no-op.