Hello
I’ve been dealing with an issue for some days now. I have the following situation in my render loop:
- Render
scene1
to a render target - Render
scene2
I need the depth buffer from the first render to be applied to the second render so that the objects in scene2
are occluded by scene1
objects. The main goal is to get the benefits of the early depth testing as the scene2
objects are very likely to be fragment-shader expensive.
renderer.autoClearDepth = false;
allows the depth buffer to remain for the second render, but only if the first render is to default frame buffer and not a render target. This is the case regardless of whether I set depthBuffer: true
on RenderTarget
settings.
I understand I can render the depth of scene1
and do my own Z-testing by comparing depths in the fragment shader of scene2
objects, but that’s still a texture lookup and requires me to modify the shaders of scene2
objects. That’s why im looking to take advantage of the built-in depth testing.
Is there a way to achieve this in Three.js
?
I know there are ways in raw webgl
to do something like this, as shown in WebGL2 Copy depth value to default renderbuffer error - Stack Overflow, but it is problematic to me working with both, as Three.js hides some internal webgl
stuff like framebuffers of textures etc. However if you know how to make that work as an alternative I’d very much appreciate that as well
If necessary I can write more details about the rendering process, but I dont want to make this a wall of text. I’ll just mention that scene1
renders to an MRT in case it’s important.
Thank you for reading!