Sign in to follow this  
snowsucks

use depth from MSAA buffer in a non MSAA buffer

Recommended Posts

snowsucks    110
Hey!

I have a situation where my forward scene requires a lot of alpha blending that is going to be dead slow in my MSAA buffer. So i was thinking about rendering the sampler heavy stuff (alpha) in one non multisampled buffer and blend this final result over my final scene. The question is, how can i use the depth buffer from the MSAA scene for depth tests in my non-MSAA render batches?

Thanks!

Share this post


Link to post
Share on other sites
theagentd    990
The easiest way is to simply loop through the samples and get the best matching blended from the five closest pixels (excluding diagonals). You could also even reduce the resolution of the alpha blending buffer (common for particles with lots of overdraw since the blurring is not noticeable for fire, smoke, etc).

Share this post


Link to post
Share on other sites
theagentd    990
Ah, damn, I realized I didn't really answer OP's question... >_<

There's no way to downsample the MSAA depth buffer in any way that makes sense. Blending the samples together would give you the average depth, which doesn't mean anything and will cause both false positives and false negatives when doing the depth test later. The easiest way is to simply take the sample closest to the center of the pixel (or simply the first sample for 2x and 4x MSAA since all samples are equally far away in those cases) and just use that as the depth for the whole pixel when rendering the particles.

When you're done with rendering your particles though you don't want to simply combine the non-MSAA particle buffer with the MSAA buffer though, since that will effectively kill the anti aliasing for particles-geometry edges. Instead, for each sample per pixel in the geometry buffer you pick a pixel from the particle buffer that best matches the depth of the MSAA sample. Note that this requires a DX10/OGL3 compatible card since you need access to individual samples.

It's kind of hard to explain the idea, but try to look up SRAA, which does pretty much the same thing but for the whole screen instead of only particles. The geometry is drawn twice, once with MSAA (only depth and normals) and once fully shaded without MSAA. The MSAA geometry buffer then checks the depth and normals of the nearby shaded pixels and picks the best matching one for each pixels. Granted, there might be no shaded sample available at all, since the MSAA pass might capture very sub-pixel geometry while the shading pass does not, in which case you will lose the anti aliasing effect.

SRAA is therefore something of a blend between MSAA (subpixel samples) and MLAA/FXAA (blending between pixels), so it's not very good for fullscreen anti aliasing in my opinion. While this limitation applies for your particles too, it's much much less noticeable. It's even pretty common to render particles at only 1/2th or even 1/4th the resolution of the geometry buffer (without MSAA) and then upscale it in almost the same way. It's also common to do this for SSAO/HBAO and volumetric lighting, where the per pixel cost is high and result is either inherently blurry (volumetric lighting) or blurred intentionally as a post-process (SSAO/HBAO). The result looks almost exactly the same anyway, and you reduce the number pixels to 1/4th or even 1/16th, allowing more overdraw.

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