Skip to content

WebGLRenderTarget: DepthTexture cannot be changed after initial use #19447

@gkjohnson

Description

@gkjohnson

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions