Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodes: Issue with Using Depth Textures in Post Process Output #29436

Open
cmhhelgeson opened this issue Sep 18, 2024 · 2 comments
Open

Nodes: Issue with Using Depth Textures in Post Process Output #29436

cmhhelgeson opened this issue Sep 18, 2024 · 2 comments
Labels

Comments

@cmhhelgeson
Copy link
Contributor

Description

When attempting to port OutlinePassNode, I came across this issue when trying to conditionally set the color of the outline depending on the depth of the fragment within the scene.

This code properly creates the outline:

constructor() {
     this._sceneColor = texture( this._sceneRT.texture );
     this._selectedColor = texture( this._selectedRT.texture );
     this._selectedDepth = texture( this._selectedRT.depthTexture );
     this._sceneDepth = texture( this._sceneRT.depthTexture );

}

updateBefore() {

// Render scenePass, then selectedPass to create edge, then apply edge to scenePass renderTarget

}

setup() {

     const uvNode = uv();
     const edgeOverlay = Fn( () => {
          // Creates the edge
	  const edgePass = sobel( this._selectedColor.uv( uvNode ).a );

          const edgeColor = vec3( 1.0, 0.0, 0.0 ).toVar()

          //const sceneViewZ = perspectiveDepthToViewZ( this._sceneDepth, this._cameraNear, this._cameraFar );
          //const selectedViewZ = perspectiveDepthToViewZ( this._selectedDepth, this._cameraNear, this._cameraFar );

	  // Sets color dependent on edge depth
	  //edgeColor.assign( sceneViewZ.greaterThan( selectedViewZ ).select( this.visibleEdgeColor, this.hiddenEdgeColor ) );

	  // Mixes color in
	  const coloredEdgePass = edgePass.r.mix( vec3( 0.0 ), edgeColor );

	  return coloredEdgePass;

     } );

     const overlayMaterial = this._overlayMaterial || ( this._overlayMaterial = new NodeMaterial() );
     overlayMaterial.fragmentNode = edgeOverlay().context( builder.getSharedContext() );
     overlayMaterial.name = 'Overlay';
     overlayMaterial.blending = AdditiveBlending;
     overlayMaterial.depthTest = false,
     overlayMaterial.depthWrite = false,
     overlayMaterial.transparent = true;

     return this._sceneColor;

}
image

However, uncommenting the viewZ related code, produces this error in the console.

image

Reproduction steps

Reproducing this entails replicating the code added to this branch of Three.js:
https://github.com/cmhhelgeson/three.js/tree/outline_pass_node

Particularly the OutlinePassNode logic: https://github.com/cmhhelgeson/three.js/blob/outline_pass_node/src/nodes/display/OutlinePassNode.js

And the corresponding example:
https://github.com/cmhhelgeson/three.js/blob/outline_pass_node/examples/webgpu_postprocessing_outline.html

Code

.

Live example

.

Screenshots

No response

Version

r168

Device

Desktop

Browser

Chrome

OS

Windows

@Spiri0
Copy link
Contributor

Spiri0 commented Sep 18, 2024

Hi cmhhelgeson,
I remember this problem well too. I had initially solved it with a workaround but there is a more elegant way.
Does this codePen help you?

https://codepen.io/Spiri0/pen/MWMpzGd

In it you can see how you can use the scene depth texture and also the scene texture in post-processing.

@Mugen87 Mugen87 added the WebGPU label Sep 18, 2024
@cmhhelgeson
Copy link
Contributor Author

Hi cmhhelgeson, I remember this problem well too. I had initially solved it with a workaround but there is a more elegant way. Does this codePen help you?

https://codepen.io/Spiri0/pen/MWMpzGd

In it you can see how you can use the scene depth texture and also the scene texture in post-processing.

Hi Spir0, I'll have to look more closely at the code later, but I'm not sure if it helps me solve my issue. I'm explicitly not writing the depth to the renderTarget, so I can't access it with a call to getTextureNode('depth'). I'm doing this so that I can more easily apply blending to the renderTarget that renders the scene. Irrespective of whether I render to renderTarget or not, I still need to access the depth from two separate depth texture passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants