Sign in to follow this  
Eitsch

Stencil visiblity test

Recommended Posts

is it possible to use the stencil buffer to determine if a vertex is in a specified region? my idea: - render a cube or what which should be the visible region to stencil - bool render_object = wouldVertexPassTheStencilTest(glVertex()) and then render if render_object was true. so i would have a visiblity test with only one glVertexCall (a point) hope you understand me ..... thanks eitsch

Share this post


Link to post
Share on other sites
Stencil buffer (actually, like all other buffers) operates on pixels - not vertices. Anyway, you can use it for determining particular fragments of the screen where 'rendering is allowed' (it can be your 'visible region'). For example, you can render a shape of your cockpit HUD to the stencil buffer and then draw the outside world without worrying that some parts of the HUD will become covered by other objects. Maybe it wasn't the best example but I hope that you get the idea. ;) Probably more intuitive usage of stencil buffer it is specyfing screen regions for reflections and shadows.

Putting it simply, here are OpenGL commands related to the stencil test :

glEnable(GL_STENCIL_TEST); // must be enabled in order to perform the stencil test

glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF); // specifies the stencil function (in this case the test always passes and writes '1' to the stencil buffer - useful when drawing regions to the buffer)

glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); // says what to do when 1) stencil test fails 2) depth test fails 3) both stencil and depth test succeded

For more information I suggest googling or looking into The Red Book.

Hope it helps!

Share this post


Link to post
Share on other sites
Another thing is that it's usually a bad idea to read something from the video card because it stalls the pipeline. If the region you want to test a vertex against is in screen space, a better way would be to use gluProject to get the screen space coordinates of the vertex and just check if that's within the region.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this