Sign in to follow this  
Eitsch

3D Decals using stencil

Recommended Posts

 glColorMask(0, 0, 0, 0);
glStencilFunc(GL_ALWAYS, 1, 1);
glDepthMask(GL_FALSE);

glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT);
drawDecal()
glColorMask(1, 1, 1, 1);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

glDepthMask(GL_TRUE);

glStencilFunc(GL_NOTEQUAL,1,1);
DrawTerrain();


glStencilFunc(GL_EQUAL, 1, 1);
drawDecal()


glStencilFunc(GL_ALWAYS, 1, 1);

drawTheRest();
the problem now. i can see the decal through all the mountains. how could i avoid this effect? i need good performance. thanks [Edited by - Eitsch on September 7, 2005 6:05:04 AM]

Share this post


Link to post
Share on other sites
Well as of right now, this is what you're doing...
Render decal into stencil buffer
Render terrain everywhere except where the decal was rendered in stencil buffer
Render the decal to color buffer
This will clearly always cause holes to appear in your terrain whenever a decal would be rendered to the same spot in screen space as part of your terrain.

What you should be doing for decals is just (very basically) get the polygons where it should be rendered, add decal polygons onto those and render. No need to use the stencil buffer.
There are a decent amount of resources on doing it this way out there. I don't know of any off-hand, but I'm sure [google] does.

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