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

TSL: PassNode - Revision linearDepth property #28737

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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