Storing min and max depth in depth buffer

Started by
4 comments, last by dpadam450 2 years, 10 months ago

Obviously it's not possible to store two values in a one channel texture like a depth buffer, but does anyone know if it's somehow possible to keep track of both min and max depth values when rendering?

Advertisement

I think it depends on whether you need the true min/max depth per-pixel (including pixels that aren't visible because they're behind the final depth), or if you just want the min/max depth of a tile of pixels in your final depth buffer (probably more common).

The former would probably require you to render your entire scene twice with different depth-write modes (e.g. clear buffer 1 to “far” and use a mode to take “nearer” depths, and clear buffer 2 to “near” and use a mode to take “further” depths). You could do these as depth-only passes, then render your actual scene using depth-equals testing and the “near” depth buffer. There might be some extensions I don't know about to various rendering APIs (probably not DX11) that allow this operation natively, but I'm not aware of them.

The latter could be a simple post-process of your final scene's depth where you have an output image (probably at half or quarter res of depth buffer) that you write into by taking the min and max of all depth values in the associated depth tile's pixels and storing those. This is a common operation for building min- or max- depth pyramids for various rendering techniques (e.g. occlusion), and is supported in hardware by some consoles.

Thanks for the helpful response, that’s along the lines of what I was thinking. I’m experimenting with some different shadow mapping ideas and one of them involved storing two values when doing the depth pass from the light. On paper, however, it didn’t quite work as I’d anticipated.

I think this idea of stochastic depth buffers is highly interesting (if your goal would be soft shadows, for example): https://graphics.tudelft.nl/Publications-new/2021/VSE21/SDAO.pdf

I've never heard of a technique to do this but there possibly could be some weird way to do it. You can't really have a million pixels trying to write to the same 2 floats to tracking min/max. This would stall all the pixel pipelines.

Best way I know is to take your depth buffer afterwards and downsample while storing the results each time until you get a single texel.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement