-
-
Notifications
You must be signed in to change notification settings - Fork 36k
Description
I'm using a render target depthTexture to render the main scene, then would like to modify the contents of the color buffer without touching the contents of the depth buffer but it looks like once a render target has been set with a given depthTexture setting it cannot be modified later. Here's a simplified example of what I'm trying to do. In practice I'm using multiple textures and a fullscreen quad to render the second time:
const renderTarget = new WebGLRenderTarget();
const depthTexture = new DepthTexture();
// ...
renderTarget.depthTexture = depthTexture;
renderer.setRenderTarget( renderTarget );
renderer.render( scene, camera );
renderTarget.depthTexture = null;
renderer.setRenderTarget( renderTarget );
renderer.render( secondScene, camera );
Looking through the code it looks like these lines are to blame for the depth texture not updating:
three.js/src/renderers/WebGLRenderer.js
Lines 1964 to 1968 in c4d1e88
if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) { | |
textures.setupRenderTarget( renderTarget ); | |
} |
textures.setUpRenderTarget
will only get called once per render target, which is where the depth texture gets initialized and bound to the frame buffer.