-
-
Notifications
You must be signed in to change notification settings - Fork 36k
Description
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;
}

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

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