This might be a simple question. As a newbie on GLSL, I would rather ask here.
Now, in the vertex shader, I can get the position in world coordinate system in the following way:
gl_Position = ftransform();
posWorld = gl_ModelViewMatrix * gl_Vertex;
The question is: now can I can the max/min value of the posWorld among all the vertices? So that I can get a range of the vertex depth, but not the range of depth buffer.
If this is not possible, how can I get the z value of near/far plane in world coordinate system?
with best regards,
Jian
Yes it is possible with OpenGL. I’m doing a similar technique for calculating object’s bounding box on GPU. Here are the steps:
You can go further optimizing from here. For example, you can get both ‘min’ and ‘max’ in one draw call by utilizing the geometry shader and negating the position for one of the output pixels.