Skip to content
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
30 changes: 25 additions & 5 deletions examples/jsm/tsl/display/TRAANode.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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',
Expand All @@ -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 ), () => {

Expand All @@ -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 );

};

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading