Vexator
04-06-2008, 11:47 AM
i have recently switched from deferred rendering to classic multi-pass forward rendering and added decals and particle systems, so, for the first time, I have to handle transparency in a multi-pass environment.
i have read numerous threads both here and on the gamedev forums, but didn't get a satisfying answer. they all agree that it's not a simple task, but while some say it's possible to do using blending alone, others talk about using a separate frame buffer for translucent meshes.. etc.
keep in mind that i only need transparency for decals and particles, i. e. simple quads that are already sorted from back to front. in all other cases like water and glass, i have to use separate buffers anyway to store what's behind.
this is what i do so far:
in the initial pass i render depth and ambient light; first come opaque meshes with blending disabled, then come decals and particles sorted back to front with transparency blending enabled ( glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ). then i enable additive blending ( glBlendFunc(GL_ONE, GL_ONE) )and render my lighting passes.
this obviously is wrong or insufficent:
http://www.desertsatori.com/vexator/0.jpg http://www.desertsatori.com/vexator/1.jpg
if no lights are enabled, the decal blends fine (left picture), but if i enable a light source then there is no lighting where the decal should be transparent (compare the box's shadow in the top right).
i have tried any possible blend mode combination without success, so it seems i have to do more. but what?
thanks!
i have read numerous threads both here and on the gamedev forums, but didn't get a satisfying answer. they all agree that it's not a simple task, but while some say it's possible to do using blending alone, others talk about using a separate frame buffer for translucent meshes.. etc.
keep in mind that i only need transparency for decals and particles, i. e. simple quads that are already sorted from back to front. in all other cases like water and glass, i have to use separate buffers anyway to store what's behind.
this is what i do so far:
in the initial pass i render depth and ambient light; first come opaque meshes with blending disabled, then come decals and particles sorted back to front with transparency blending enabled ( glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ). then i enable additive blending ( glBlendFunc(GL_ONE, GL_ONE) )and render my lighting passes.
this obviously is wrong or insufficent:
http://www.desertsatori.com/vexator/0.jpg http://www.desertsatori.com/vexator/1.jpg
if no lights are enabled, the decal blends fine (left picture), but if i enable a light source then there is no lighting where the decal should be transparent (compare the box's shadow in the top right).
i have tried any possible blend mode combination without success, so it seems i have to do more. but what?
thanks!