diff --git a/examples/jsm/tsl/display/TRAANode.js b/examples/jsm/tsl/display/TRAANode.js index 19baa234c504a7..ea2c2a41dd38a8 100644 --- a/examples/jsm/tsl/display/TRAANode.js +++ b/examples/jsm/tsl/display/TRAANode.js @@ -1,5 +1,5 @@ -import { HalfFloatType, Vector2, RenderTarget, RendererUtils, QuadMesh, NodeMaterial, TempNode, NodeUpdateType, Matrix4, DepthTexture } from 'three/webgpu'; -import { add, float, If, Fn, max, texture, uniform, uv, vec2, vec4, luminance, convertToTexture, passTexture, velocity, getViewPosition, viewZToPerspectiveDepth, struct, ivec2, mix } from 'three/tsl'; +import { HalfFloatType, Vector2, RenderTarget, RendererUtils, QuadMesh, NodeMaterial, TempNode, NodeUpdateType, Matrix4, DepthTexture, FloatType } from 'three/webgpu'; +import { add, float, If, Fn, max, texture, uniform, uv, vec2, vec4, luminance, convertToTexture, passTexture, velocity, getViewPosition, viewZToPerspectiveDepth, struct, ivec2, mix, logarithmicDepthToViewZ, viewZToOrthographicDepth } from 'three/tsl'; const _quadMesh = /*@__PURE__*/ new QuadMesh(); const _size = /*@__PURE__*/ new Vector2(); @@ -463,6 +463,12 @@ class TRAANode extends TempNode { } + if ( builder.renderer.reversedDepthBuffer === true ) { + + this._historyRenderTarget.depthTexture.type = FloatType; + + } + if ( builder.context.velocity !== undefined ) { this._velocityNode = builder.context.velocity; @@ -473,6 +479,14 @@ class TRAANode extends TempNode { } + const logarithmicToPerspectiveDepth = ( depth ) => { + + const { x: near, y: far } = this._cameraNearFar; + const viewZ = logarithmicDepthToViewZ( depth, near, far ); + return viewZToPerspectiveDepth( viewZ, near, far ); + + }; + const currentDepthStruct = struct( { closestDepth: 'float', @@ -493,7 +507,10 @@ class TRAANode extends TempNode { for ( let y = - 1; y <= 1; ++ y ) { const neighbor = positionTexel.add( vec2( x, y ) ).toVar(); - const depth = this.depthNode.load( neighbor ).r.toVar(); + let depth = this.depthNode.load( neighbor ).r; + if ( builder.renderer.reversedDepthBuffer ) depth = depth.oneMinus(); + if ( builder.renderer.logarithmicDepthBuffer ) depth = logarithmicToPerspectiveDepth( depth ); + depth = depth.toVar(); If( depth.lessThan( closestDepth ), () => { @@ -519,11 +536,14 @@ class TRAANode extends TempNode { // Samples a previous depth and reproject it using the current camera matrices. const samplePreviousDepth = ( uv ) => { - const depth = this._previousDepthNode.sample( uv ).r; + let depth = this._previousDepthNode.sample( uv ).r; + if ( builder.renderer.logarithmicDepthBuffer ) depth = logarithmicToPerspectiveDepth( depth ); const positionView = getViewPosition( uv, depth, this._previousCameraProjectionMatrixInverse ); const positionWorld = this._previousCameraWorldMatrix.mul( vec4( positionView, 1 ) ).xyz; const viewZ = this._cameraWorldMatrixInverse.mul( vec4( positionWorld, 1 ) ).z; - return viewZToPerspectiveDepth( viewZ, this._cameraNearFar.x, this._cameraNearFar.y ); + return this.camera.isOrthographicCamera + ? viewZToOrthographicDepth( viewZ, this._cameraNearFar.x, this._cameraNearFar.y ) + : viewZToPerspectiveDepth( viewZ, this._cameraNearFar.x, this._cameraNearFar.y ); }; diff --git a/package-lock.json b/package-lock.json index 628fbdad5f35e6..cb3aae8dfffb6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1197,9 +1197,9 @@ } }, "node_modules/basic-ftp": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-5.2.1.tgz", - "integrity": "sha512-0yaL8JdxTknKDILitVpfYfV2Ob6yb3udX/hK97M7I3jOeznBNxQPtVvTUtnhUkyHlxFWyr5Lvknmgzoc7jf+1Q==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-5.2.2.tgz", + "integrity": "sha512-1tDrzKsdCg70WGvbFss/ulVAxupNauGnOlgpyjKzeQxzyllBLS0CGLV7tjIXTK3ZQA9/FBEm9qyFFN1bciA6pw==", "dev": true, "license": "MIT", "engines": {