PDA

View Full Version : Vertex culling without GL_EXT_cull_vertex



tabor25
07-05-2007, 02:32 AM
Hello,

i draw a sphere in wireframe mode with face culling on. I also want to draw the vertices of the wireframe by using glVertex3fv. I cannot use the extension GL_EXT_cull_vertex for vertex culling. Because i have the normal for each vertex, it must be possible to decide wich vertex has to be drawn and wich not. Can i accomplish this task by using a vertex shader? If yes, is it possible to prevent drawing the vertex after it reached the vertex shader executing the culling test. If i can't use a vertex shader, how do i get the eye vector in object space to do the scalar product with the vertex normal?

k_szczech
07-05-2007, 04:10 AM
You can use a combination of vertex and fragment shader.
Note that OpenGL does not draw vertices - it draws fragments.
In your vertex shader you decide if vertex should be drawn or not, and pass the result to fragment shader as varying variable.
In your shader you should use discard keyword if vertex shouldn't be drawn.

thinks
07-05-2007, 01:50 PM
Another option would be to translate the vertex to be behind the camera (or anywhere outside the clipping planes) if you find in the vertex shader that you do not wish do draw it.

tabor25
07-06-2007, 12:11 AM
For the first i did it on the cpu side. i calculate the eye vector once and do a dot product vor every vertex-normal. With the dot products result i can decide to draw the vertex or not. Thank you very much for your answers. Because i never used shaders before, this was the quickest but maybe not the fastest way.