Archived

This topic is now archived and is closed to further replies.

Stencil problem(decals)

This topic is 5016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve got some decals steched over the terrain. And to avoid z-fighting, I use the following algorithm. pd3dDevice->SetRenderState( D3DRS_STENCILENABLE, TRUE ); pd3dDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS ); pd3dDevice->SetRenderState( D3DRS_STENCILREF, 0x1 ); pd3dDevice->SetRenderState( D3DRS_STENCILMASK, 0xffffffff ); pd3dDevice->SetRenderState( D3DRS_STENCILWRITEMASK,0xffffffff ); pd3dDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_REPLACE ); pd3dDevice->SetRenderState( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP ); pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE ); Render the decal to place the mask. pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ZERO ); pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE ); pd3dDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_EQUAL ); pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP ); pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE ); pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ZERO ); Re-render the decal to be "above" the terrain. But z-fighting problem still encounters. How to do it right? Anyone can help, please!!! ThanX in advance.

Share this post


Link to post
Share on other sites
Dont use the stencil buffer for decals IMO.

Just modify the project matrix slightly to fix the z-fighting. Push the near and far clip plane slightly forward/backwards (dont remember which) then render your decal, then render your wall after restoring the near and far clip back. Youll have to mess with how much you move the planes, but it should be a small amount. This should work better than using the stencil buffer (all your doing is changing a matrix)

-Vulcan

Share this post


Link to post
Share on other sites
Noooooooooo! z-bias is bad! (well, in D3D it is)
Look here (scroll down a bit) for why
http://tomsdxfaq.blogspot.com/

In essence: z-bias is so loosely defined you''ll have hell getting it to work correctly in many cases.
Vulcan''s suggestion for nudging the near & far clip planes is an easier, more consistent way to fix the issue.

-Mezz

Share this post


Link to post
Share on other sites