Skip to main content
GameDev.net gamedev.net
🔒 Locked

Shadow mapping and multipass z-fighting

Started by ZiM Oct 20, 2005 at 11:21 AM 1 replies 1.3k views
Original Post
ZiM
ZiM
Hi, I have implemented shadow mapping using GLSL vertex/pixel shaders in my 3D app. From the light's point of view, only back-facing polygons are rendered to the depth maps. When rendering the scene from camera's PoV, the scene is rendered once for each light source per frame and their contributions are accumulated in the framebuffer using additive blending. I decided to use 6 user clip planes to cull away geometry that's not within the spotlight's frustum and this gives significant performance boost. The problem is that user clip planes generate new vertices which causes z-fighting between pixels from different rendering passes. The image below illustrates this problem: http://img180.imageshack.us/my.php?image=snapshot029mt.jpg The smaller spotlight gets rendered first, and the larger spotlight rendered at next pass is z-fighting with it. Only solution that comes to mind is to increment glPolygonOffset a bit for each pass, eg: glEnable(GL_POLYGON_OFFSET_FILL); for(int i = 0; i < numlights; i++) { glPolygonOffset(1, i); // Render the scene here... } But this seems little awkward to me, not to mention some other problems it might pose. My question is, is there any better solution?
Optus
Optus
Try writing to depth for only the first pass. For subsequent passes, enable desired blend mode and call glDepthMask(false); to disable depth writing. Leave depth testing on for the whole rendering procedure, though.
ZiM
ZiM
Quote:

Try writing to depth for only the first pass. For subsequent passes, enable desired blend mode and call glDepthMask(false); to disable depth writing. Leave depth testing on for the whole rendering procedure, though.


Disabling the depth writes for subsequent passes feels to be much better solution. Thanks, Optus!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.