Skip to content

[pull] dev from mrdoob:dev #658

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

Merged
merged 5 commits into from
Jul 15, 2025
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
2 changes: 1 addition & 1 deletion examples/jsm/postprocessing/GTAOPass.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ class GTAOPass extends Pass {

cache.set( object, object.visible );

if ( object.isPoints || object.isLine ) object.visible = false;
if ( object.isPoints || object.isLine || object.isLine2 ) object.visible = false;

} );

Expand Down
71 changes: 20 additions & 51 deletions examples/jsm/tsl/display/TRAAPassNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color, Vector2, NearestFilter, Matrix4, RendererUtils, PassNode, QuadMesh, NodeMaterial } from 'three/webgpu';
import { add, float, If, Loop, int, Fn, min, max, clamp, nodeObject, texture, uniform, uv, vec2, vec4, luminance, output, mrt, textureLoad, screenCoordinate } from 'three/tsl';
import { add, float, If, Loop, int, Fn, min, max, clamp, nodeObject, texture, uniform, uv, vec2, vec4, luminance } from 'three/tsl';

const _quadMesh = /*@__PURE__*/ new QuadMesh();
const _size = /*@__PURE__*/ new Vector2();
Expand Down Expand Up @@ -105,15 +105,6 @@ class TRAAPassNode extends PassNode {
*/
this._historyRenderTarget = null;

/**
* The MRT for the transfer step.
*
* @private
* @type {?MRTNode}
* @default null
*/
this._transferMRT = null;

/**
* Material used for the resolve step.
*
Expand Down Expand Up @@ -213,21 +204,29 @@ class TRAAPassNode extends PassNode {

// configure velocity

const currentMRT = this.getMRT();
const velocityOutput = currentMRT.get( 'velocity' );
const mrt = this.getMRT();
const velocityOutput = mrt.get( 'velocity' );

if ( velocityOutput !== undefined ) {

velocityOutput.setProjectionMatrix( this._originalProjectionMatrix );
velocityOutput.setProjectionMatrix( this._originalProjectionMatrix );

} else {

throw new Error( 'THREE:TRAAPassNode: Missing velocity output in MRT configuration.' );

}

// render sample

renderer.setMRT( currentMRT );
renderer.setMRT( mrt );

renderer.setClearColor( this.clearColor, this.clearAlpha );
renderer.setRenderTarget( this._sampleRenderTarget );
renderer.render( scene, camera );

renderer.setRenderTarget( null );
renderer.setMRT( this._transferMRT );
renderer.setMRT( null );

// every time when the dimensions change we need fresh history data. Copy the sample
// into the history and final render target (no AA happens at that point).
Expand Down Expand Up @@ -313,49 +312,19 @@ class TRAAPassNode extends PassNode {
this._sampleRenderTarget.texture.minFiler = NearestFilter;
this._sampleRenderTarget.texture.magFilter = NearestFilter;

const currentMRT = this.getMRT();

if ( currentMRT === null ) {

throw new Error( 'THREE:TRAAPassNode: Missing MRT configuration.' );
const velocityTarget = this._sampleRenderTarget.texture.clone();
velocityTarget.isRenderTargetTexture = true;
velocityTarget.name = 'velocity';

} else if ( currentMRT.has( 'velocity' ) === false ) {

throw new Error( 'THREE:TRAAPassNode: Missing velocity output in MRT configuration.' );

}

this._texturesIndex = currentMRT.getIndexes( this.renderTarget );

const transferNodes = {};

for ( const name in this._texturesIndex ) {

if ( name === 'output' ) {

transferNodes[ name ] = output;

} else {

const index = this._texturesIndex[ name ];

transferNodes[ name ] = textureLoad( this._sampleRenderTarget.textures[ index ], screenCoordinate );

}

}

this._transferMRT = mrt( transferNodes );
this._sampleRenderTarget.textures.push( velocityTarget ); // for MRT

}

// textures

const velocityIndex = this._texturesIndex[ 'velocity' ];

const historyTexture = texture( this._historyRenderTarget.texture );
const sampleTexture = texture( this._sampleRenderTarget.textures[ 0 ] );
const velocityTexture = texture( this._sampleRenderTarget.textures[ velocityIndex ] );
const velocityTexture = texture( this._sampleRenderTarget.textures[ 1 ] );
const depthTexture = texture( this._sampleRenderTarget.depthTexture );

const resolve = Fn( () => {
Expand Down Expand Up @@ -426,7 +395,7 @@ class TRAAPassNode extends PassNode {

// materials

this._resolveMaterial.colorNode = resolve();
this._resolveMaterial.fragmentNode = resolve();

return super.setup( builder );

Expand Down
27 changes: 0 additions & 27 deletions src/nodes/core/MRTNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,33 +112,6 @@ class MRTNode extends OutputStructNode {

}

/**
* Returns the indexes of the MRT outputs in the current render target.
*
* @param {RenderTarget} renderTarget - The render target to get the indexes for.
* @return {Array<number>} The indexes of the MRT outputs.
*/
getIndexes( renderTarget ) {

const textures = renderTarget.textures;
const indexLib = {};

for ( const name in this.outputNodes ) {

const index = getTextureIndex( textures, name );

if ( index !== - 1 ) {

indexLib[ name ] = index;

}

}

return indexLib;

}

setup( builder ) {

const outputNodes = this.outputNodes;
Expand Down
6 changes: 6 additions & 0 deletions src/renderers/common/Textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ class Textures extends DataMap {
target.height = image.videoHeight || 1;
target.depth = 1;

} else if ( image instanceof VideoFrame ) {

target.width = image.displayWidth || 1;
target.height = image.displayHeight || 1;
target.depth = 1;

} else {

target.width = image.width || 1;
Expand Down
21 changes: 1 addition & 20 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { NodeAccess } from '../../../nodes/core/constants.js';
import VarNode from '../../../nodes/core/VarNode.js';
import ExpressionNode from '../../../nodes/code/ExpressionNode.js';

import { NoColorSpace, FloatType, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter, SRGBColorSpace } from '../../../constants.js';
import { FloatType, RepeatWrapping, ClampToEdgeWrapping, MirroredRepeatWrapping, NearestFilter } from '../../../constants.js';

// GPUShaderStage is not defined in browsers not supporting WebGPU
const GPUShaderStage = ( typeof self !== 'undefined' ) ? self.GPUShaderStage : { VERTEX: 1, FRAGMENT: 2, COMPUTE: 4 };
Expand Down Expand Up @@ -211,25 +211,6 @@ class WGSLNodeBuilder extends NodeBuilder {

}

/**
* Checks if the given texture requires a manual conversion to the working color space.
*
* @param {Texture} texture - The texture to check.
* @return {boolean} Whether the given texture requires a conversion to working color space or not.
*/
needsToWorkingColorSpace( texture ) {

if ( texture.isVideoTexture && texture.colorSpace === SRGBColorSpace ) {

// Video textures are always in sRGB color space, so no conversion is needed
return false;

}

return texture.colorSpace !== NoColorSpace;

}

/**
* Generates the WGSL snippet for sampled textures.
*
Expand Down
12 changes: 11 additions & 1 deletion src/textures/Source.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,23 @@ class Source {

}

/**
* Returns the dimensions of the source into the given target vector.
*
* @param {(Vector2|Vector3)} target - The target object the result is written into.
* @return {(Vector2|Vector3)} The dimensions of the source.
*/
getSize( target ) {

const data = this.data;

if ( data instanceof HTMLVideoElement ) {

target.set( data.videoWidth, data.videoHeight );
target.set( data.videoWidth, data.videoHeight, 0 );

} else if ( data instanceof VideoFrame ) {

target.set( data.displayHeight, data.displayWidth, 0 );

} else if ( data !== null ) {

Expand Down