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

WebGPURenderer: Optimize and reuse varyings #28210

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/jsm/nodes/accessors/BufferAttributeNode.js
Expand Up @@ -80,7 +80,7 @@ class BufferAttributeNode extends InputNode {

} else {

const nodeVarying = varying( this );
const nodeVarying = varying( this, `v_${propertyName}` );

output = nodeVarying.build( builder, nodeType );

Expand Down
5 changes: 3 additions & 2 deletions examples/jsm/nodes/accessors/ClippingNode.js
Expand Up @@ -5,7 +5,7 @@ import { positionView } from './PositionNode.js';
import { diffuseColor, property } from '../core/PropertyNode.js';
import { tslFn } from '../shadernode/ShaderNode.js';
import { loop } from '../utils/LoopNode.js';
import { smoothstep } from '../math/MathNode.js';
import { smoothstep } from '../math/MathNode.js';
import { uniforms } from './UniformsNode.js';

class ClippingNode extends Node {
Expand Down Expand Up @@ -78,7 +78,7 @@ class ClippingNode extends Node {

plane = clippingPlanes.element( i );

distanceToPlane.assign( positionView.dot( plane.xyz ).negate().add( plane.w ) );
distanceToPlane.assign( positionView.dot( plane.xyz ).negate().add( plane.w ) );
distanceGradient.assign( distanceToPlane.fwidth().div( 2.0 ) );

unionClipOpacity.mulAssign( smoothstep( distanceGradient.negate(), distanceGradient, distanceToPlane ).oneMinus() );
Expand Down Expand Up @@ -126,6 +126,7 @@ class ClippingNode extends Node {
} );

clipped.discard();

}

} )();
Expand Down
14 changes: 10 additions & 4 deletions examples/jsm/nodes/accessors/NormalNode.js
Expand Up @@ -23,9 +23,15 @@ class NormalNode extends Node {

}

getVaryingProperty() {

return 'v_' + this.getHash();

}

getHash( /*builder*/ ) {

return `normal-${this.scope}`;
return `normal_${ this.scope }`;

}

Expand All @@ -51,18 +57,18 @@ class NormalNode extends Node {

} else if ( scope === NormalNode.LOCAL ) {

outputNode = varying( normalGeometry );
outputNode = varying( normalGeometry, this.getVaryingProperty() );

} else if ( scope === NormalNode.VIEW ) {

const vertexNode = modelNormalMatrix.mul( normalLocal );
outputNode = normalize( varying( vertexNode ) );
outputNode = normalize( varying( vertexNode, this.getVaryingProperty() ) );

} else if ( scope === NormalNode.WORLD ) {

// To use inverseTransformDirection only inverse the param order like this: cameraViewMatrix.transformDirection( normalView )
const vertexNode = normalView.transformDirection( cameraViewMatrix );
outputNode = normalize( varying( vertexNode ) );
outputNode = normalize( varying( vertexNode, this.getVaryingProperty() ) );

}

Expand Down
4 changes: 3 additions & 1 deletion examples/jsm/nodes/accessors/StorageBufferNode.js
Expand Up @@ -58,7 +58,9 @@ class StorageBufferNode extends BufferNode {
if ( this._attribute === null ) {

this._attribute = bufferAttribute( this.value );
this._varying = varying( this._attribute );

const name = this._attribute.name ? `v_${this._attribute.name}` : null;
this._varying = varying( this._attribute, name );

}

Expand Down
6 changes: 6 additions & 0 deletions examples/jsm/nodes/accessors/TangentNode.js
Expand Up @@ -17,6 +17,12 @@ class TangentNode extends Node {

}

isGlobal() {

return true;

}

getHash( /*builder*/ ) {

return `tangent-${this.scope}`;
Expand Down
3 changes: 2 additions & 1 deletion examples/jsm/nodes/core/AttributeNode.js
Expand Up @@ -83,7 +83,8 @@ class AttributeNode extends Node {

} else {

const nodeVarying = varying( this );
const name = attributeName ? `v_${attributeName}` : null;
const nodeVarying = varying( this, name );

return nodeVarying.build( builder, nodeType );

Expand Down
4 changes: 3 additions & 1 deletion examples/jsm/nodes/core/IndexNode.js
Expand Up @@ -43,7 +43,9 @@ class IndexNode extends Node {

} else {

const nodeVarying = varying( this );
const name = propertyName && scope !== IndexNode.VERTEX && scope !== IndexNode.INSTANCE ? output : null;

const nodeVarying = varying( this, name );

output = nodeVarying.build( builder, nodeType );

Expand Down