In OpenGL vertex shader, gl_Position doesn't get homogenized
I was expecting gl_Position to automatically get homogenized (divided by w), but it seems not working.. Why do the followings make different results?
1) void main() { vec4 p; ... omitted ... gl_Position = projectionMatrix * p; }
2) ... same as above ... p = projectionMatrix * p; gl_Position = p / p.w;
I think the two are supposed to generate the same results, but it seems it's not the case. 1 doesn't开发者_如何转开发 work while 2 is working as expected.. Could it possibly be a precision problem? Am I missing something? This is driving me almost crazy.. helps needed. Many thanks in advance!
the perspective divide cannot be done before clipping, which happens after the vertex shader is completed. So there is no reason that you could observe the w divide in the vertex shader.
The GL will do the perspective divide before the rasterization of the triangles, before the fragment shader runs, though.
What are you trying to do that does not work ?
From the GLSL spec 1.2:
The variable gl_Position is available only in the vertex language and is intended for writing the homogeneous vertex position.
So it's not automatically homogenized.
精彩评论