-
-
Notifications
You must be signed in to change notification settings - Fork 56
Description
It would be nice to have access to the depth buffer for a few reasons:
- Users may be interested in this information, e.g. VIsualizing a triangular terrain model using pygfx #318.
- Extension of the previous point: it may be valuable picking info.
- Post-processing steps may want to use it, e.g. for ambient occlusion.
At the moment, this is not feasible, for the following reasons:
- If you render an overlay over a scene, the overlay needs the depth buffer, which is reset.
- Clearing the depth buffer happens for the full buffer, not the viewport. This is problematic with subplots.
- Some blend modes use the depth-buffer twice (only weighted_plus right now).
For the first point, we could add an abstraction that a pass is an overlay that does not touch the depth buffer. Not sure how this'd look exactly, but I think we could make this work.
I looked a bit into resolving the second point, by only clearing the depth buffer when the clear buffer is also cleared. But for some reason the depth buffer is auto-cleared to zeros for transparent passes. This means that if there is a transparency pass, any screenshots to be black, and all but the first subplot will fail. I've not yet found out why this happens. Maybe some obscure mechanism of depth buffers that I don't know of, or a driver bug ...
Anyway, even if that would work, the third point would still pose a problem.
A solution that I'm pretty sure would work is to add another render target to render the final depth together with the color. This feels a bit awkward, because we'd basically be writing depth twice, plus it costs extra memory (maybe 16bit is enough, so its not so bad).