Sign in to follow this  

Multi-pass, blending everything together

This topic is 3586 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

Hi, I need to do multiple passes with additive blending (summing lights). I guess the first pass should not use blending, otherwise you can look through the world. But how to "paste" the other passes on top of this first layer? I can simply enable additive blending, but that will cause Z-fighting. Another trick would be by giving a tiny offset to each layer. But in case a wall is affected by "many" lights, a thick pile of layers will stack up. And will I get problems when looking at the same wall on a large distance? Many games are using multipassing, so I assume there must be a proper way avoid these problems. Greetings, Rick

Share this post


Link to post
Share on other sites
Maybe you should try looking into the accumulation buffer.

Also, to remove the "Z-Fighting", clear the depth buffer between passes (or disable it).

Share this post


Link to post
Share on other sites
Sorry for the late reply. Had other things todo in the weekend. Ok, I tried the tips here. Well, most of them were already in the code, but it doesn't work though. This is what I do:

glDisable(GL_BLEND); // just for sure
glEnable(GL_DEPTH_TEST);
world.render_Base; // Base pass, no blending activated

// Activate additive blending
glPushAttrib( GL_ENABLE_BIT +
GL_DEPTH_BUFFER_BIT +
GL_COLOR_BUFFER_BIT);
glDepthFunc(GL_LEQUAL);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
glDisable( GL_DEPTH_TEST );

// Render the world again for each light, add everything together
world.render_PerLight;

// Disable additive blending
glPopAttrib;
glEnable( GL_DEPTH_TEST );

Notice that everything is rendered on a 16F FBO, using a 24 bit depth buffer. The Z-fighting is still there.

If I add glDisable( GL_DEPTH_TEST ); (like in the code above), the Z-fighting is gone, but I can look through my world. Strange, I would say the first pass should prevent that.

Greetings,
Rick

Share this post


Link to post
Share on other sites
enable depth test but when rendering the same object multiple times with different textures set glDepthMask(false) and then glDepthMask(true) again for the last pass,

glDepthMask() allows you to keep depth test on but not write to depth buffer, this way you can render to the color buffer as many times as you want but only write to the depth buffer once

Share this post


Link to post
Share on other sites
You can't disable the depth buffer because all those walls still need to be sorted by depth. I wouldn't recommend it but you could clear the depth buffer and sort the walls yourself, rendering from front to back. That way the rear walls would not be seen through the near walls.

It would probably be better to try offsetting the polygons on the depth buffer, try this link.

edit: redirected link to msft definition

Share this post


Link to post
Share on other sites
The glDepthMask command did the trick. At least, in this situation everything is ok. Thanks!

I was thinking about using an offset as well. But do games really use that? Sometimes you can see layers stacked on each other (terrain in Farcry for example). But will it still work when increasing the camera distance? The offset could be enlarged as well of course, but its kinda tricky to calculate a proper offset for each face in my case.

Greetings,
Rick

Share this post


Link to post
Share on other sites

This topic is 3586 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.

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