question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebGPUTextureRenderer: Get Depth buffer as TextureNode

See original GitHub issue

Is your feature request related to a problem? Please describe.

For advanced post-processing with a fullscreen quad like in the webgpu_rtt.html example, it is also necessary to have access to the depth buffer of the Rendertarget from the WebGPUTextureRenderer. If I did not miss anything, it is currently not possible to access the depth buffer.

Describe the solution you’d like

It would be great to have something for the WebGPUTextureRenderer like:

let depthTextureNode = new Nodes.TextureNode( textureRenderer.getDepthTexture() );

Describe alternatives you’ve considered

Similar as in the webgl_depth_texture.html example, I tried to get a DepthTexture from a RenderTarget, which didn´t work:

    //create a WebGPUTextureRenderer and set a DepthTexture
    textureRenderer = new WebGPUTextureRenderer(renderer);
    textureRenderer.setSize(window.innerWidth * window.devicePixelRatio, window.innerHeight * window.devicePixelRatio);

    let depthTexture = new THREE.DepthTexture();
    textureRenderer.renderTarget.texture.minFilter = THREE.NearestFilter;
    textureRenderer.renderTarget.texture.magFilter = THREE.NearestFilter;
    textureRenderer.renderTarget.stencilBuffer = false;
    textureRenderer.renderTarget.depthTexture = depthTexture;
    textureRenderer.renderTarget.depthTexture.format = THREE.DepthFormat;
    textureRenderer.renderTarget.depthTexture.type = THREE.UnsignedShortType;

    // set up FX
    cameraFX = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
    sceneFX = new THREE.Scene();
    const geometryFX = new THREE.PlaneGeometry(2, 2);
    const materialFX = new Nodes.MeshBasicNodeMaterial({
        side: THREE.DoubleSide
    });

    // this returns an error: "Multiple aspects selected in [TextureView] While validating [BindGroupDescriptor] against [BindGroupLayout]"
    materialFX.colorNode = new Nodes.OperatorNode( '*', new Nodes.TextureNode( textureRenderer.renderTarget.depthTexture ), new Nodes.ColorNode( new THREE.Color("green") ) );
    
    const quad = new THREE.Mesh(geometryFX, materialFX);
    sceneFX.add(quad);

Additional context

@sunag , maybe you could have a look at this? Many thanks in advance!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
geolehmanncommented, Mar 23, 2022

Many thanks, I’ll try it out today!

1reaction
sunagcommented, Mar 8, 2022

@geolehmann No problems, anyway it’s important to have some examples using WGSL with textures.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebGL Rendering to a Texture
Behind the scenes they create a color texture, a depth buffer, a framebuffer and then they bind it as the current framebuffer. You...
Read more >
WebGL: Will zero-alpha pixels in a texture necessarily update ...
I'm trying to render a texture which has a mix of fully-transparent pixels, and fully-opaque pixels. It seems like my only option is...
Read more >
WebGLRenderer#depth – three.js docs
Copies all pixels of a texture to an existing texture starting from the given position. Enables access to WebGLRenderingContext.texSubImage2D. # .
Read more >
Depth Renderer | Babylon.js Documentation
DepthRenderer is a tool used to generate depth texture (a texture that contains depth buffer and which can be used to read scene...
Read more >
CS 4621: Lecture 8 -- Exhibit #2: Depth Buffer and FBO
In the past 2 exhibits, we render 2D scenes to a texture. WebGL is primarily used for 3D rendering, and we can certainly...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found