Skip to content

Commit

Permalink
TSL: PassNode - Revision linearDepth property (#28737)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag authored Jun 24, 2024
1 parent fe079ef commit 1d3c9bd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions examples/jsm/nodes/display/PassNode.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addNodeClass } from '../core/Node.js';
import TempNode from '../core/TempNode.js';
import TextureNode from '../accessors/TextureNode.js';
import { default as TextureNode/*, texture*/ } from '../accessors/TextureNode.js';
import { NodeUpdateType } from '../core/constants.js';
import { nodeObject } from '../shadernode/ShaderNode.js';
import { uniform } from '../core/UniformNode.js';
Expand Down Expand Up @@ -67,7 +67,7 @@ class PassNode extends TempNode {
this._textureNode = nodeObject( new PassTextureNode( this, renderTarget.texture ) );
this._depthTextureNode = nodeObject( new PassTextureNode( this, depthTexture ) );

this._depthNode = null;
this._linearDepthNode = null;
this._viewZNode = null;
this._cameraNear = uniform( 0 );
this._cameraFar = uniform( 0 );
Expand Down Expand Up @@ -109,24 +109,26 @@ class PassNode extends TempNode {

}

getDepthNode() {
getLinearDepthNode() {

if ( this._depthNode === null ) {
if ( this._linearDepthNode === null ) {

const cameraNear = this._cameraNear;
const cameraFar = this._cameraFar;

this._depthNode = viewZToOrthographicDepth( this.getViewZNode(), cameraNear, cameraFar );
// TODO: just if ( builder.camera.isPerspectiveCamera )

this._linearDepthNode = viewZToOrthographicDepth( this.getViewZNode(), cameraNear, cameraFar );

}

return this._depthNode;
return this._linearDepthNode;

}

setup() {

return this.scope === PassNode.COLOR ? this.getTextureNode() : this.getDepthNode();
return this.scope === PassNode.COLOR ? this.getTextureNode() : this.getLinearDepthNode();

}

Expand Down
4 changes: 2 additions & 2 deletions examples/webgpu_backdrop_water.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@

const scenePass = pass( scene, camera );
const scenePassColor = scenePass.getTextureNode();
const scenePassDepth = scenePass.getDepthNode().remapClamp( .3, .5 );
const scenePassDepth = scenePass.getLinearDepthNode().remapClamp( .3, .5 );

const waterMask = objectPosition( camera ).y.greaterThan( 0 );

const scenePassColorBlurred = scenePassColor.gaussianBlur();
scenePassColorBlurred.directionNode = waterMask.cond( scenePassDepth, scenePass.getDepthNode().mul( 5 ) );
scenePassColorBlurred.directionNode = waterMask.cond( scenePassDepth, scenePass.getLinearDepthNode().mul( 5 ) );

const vignet = viewportTopLeft.distance( .5 ).mul( 1.35 ).clamp().oneMinus();

Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_reflection.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@

const scenePass = pass( scene, camera );
const scenePassColor = scenePass.getTextureNode();
const scenePassDepth = scenePass.getDepthNode().remapClamp( .3, .5 );
const scenePassDepth = scenePass.getLinearDepthNode().remapClamp( .3, .5 );

const scenePassColorBlurred = scenePassColor.gaussianBlur();
scenePassColorBlurred.directionNode = scenePassDepth;
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_skinning_instancing.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@

const scenePass = pass( scene, camera );
const scenePassColor = scenePass.getTextureNode();
const scenePassDepth = scenePass.getDepthNode().remapClamp( .15, .3 );
const scenePassDepth = scenePass.getLinearDepthNode().remapClamp( .15, .3 );

const scenePassColorBlurred = scenePassColor.gaussianBlur();
scenePassColorBlurred.directionNode = scenePassDepth;
Expand Down

0 comments on commit 1d3c9bd

Please sign in to comment.