Skip to content

Commit

Permalink
WebGPURenderer: Support Instance and Skinning without normals (#29134)
Browse files Browse the repository at this point in the history
  • Loading branch information
RenaudRohlinger authored Aug 14, 2024
1 parent 9187311 commit 3ce950f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
18 changes: 11 additions & 7 deletions src/nodes/accessors/InstanceNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class InstanceNode extends Node {

}

setup( /*builder*/ ) {
setup( builder ) {

let instanceMatrixNode = this.instanceMatrixNode;
let instanceColorNode = this.instanceColorNode;
Expand Down Expand Up @@ -91,19 +91,23 @@ class InstanceNode extends Node {
// POSITION

const instancePosition = instanceMatrixNode.mul( positionLocal ).xyz;
positionLocal.assign( instancePosition );

// NORMAL

const m = mat3( instanceMatrixNode );
if ( builder.hasGeometryAttribute( 'normal' ) ) {

const transformedNormal = normalLocal.div( vec3( m[ 0 ].dot( m[ 0 ] ), m[ 1 ].dot( m[ 1 ] ), m[ 2 ].dot( m[ 2 ] ) ) );
const m = mat3( instanceMatrixNode );

const instanceNormal = m.mul( transformedNormal ).xyz;
const transformedNormal = normalLocal.div( vec3( m[ 0 ].dot( m[ 0 ] ), m[ 1 ].dot( m[ 1 ] ), m[ 2 ].dot( m[ 2 ] ) ) );

// ASSIGNS
const instanceNormal = m.mul( transformedNormal ).xyz;

positionLocal.assign( instancePosition );
normalLocal.assign( instanceNormal );
// ASSIGNS

normalLocal.assign( instanceNormal );

}

// COLOR

Expand Down
15 changes: 11 additions & 4 deletions src/nodes/accessors/SkinningNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,21 @@ class SkinningNode extends Node {
}

const skinPosition = this.getSkinnedPosition();
const skinNormal = this.getSkinnedNormal();


positionLocal.assign( skinPosition );
normalLocal.assign( skinNormal );

if ( builder.hasGeometryAttribute( 'tangent' ) ) {
if ( builder.hasGeometryAttribute( 'normal' ) ) {

const skinNormal = this.getSkinnedNormal();

normalLocal.assign( skinNormal );

if ( builder.hasGeometryAttribute( 'tangent' ) ) {

tangentLocal.assign( skinNormal );

tangentLocal.assign( skinNormal );
}

}

Expand Down

0 comments on commit 3ce950f

Please sign in to comment.