Skip to content

Commit aa7f5b9

Browse files
Mugen87sunag
andauthored
Normal: Don't flip normals when using flat shading. (#30823)
* FrontFacingNode: Don't flip normals when using flat shading. * Normal: Don't flip normals when using flat shading. * Add fix to `transformedClearcoatNormalView` as well. * updates --------- Co-authored-by: sunag <[email protected]>
1 parent b3cb0cd commit aa7f5b9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/nodes/accessors/Normal.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,13 @@ export const transformedNormalView = /*@__PURE__*/ ( Fn( ( builder ) => {
8383

8484
// Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
8585

86-
return builder.context.setupNormal().context( { getUV: null } );
86+
let node = builder.context.setupNormal().context( { getUV: null } );
8787

88-
}, 'vec3' ).once() )().mul( faceDirection ).toVar( 'transformedNormalView' );
88+
if ( builder.material.flatShading !== true ) node = node.mul( faceDirection );
89+
90+
return node;
91+
92+
}, 'vec3' ).once() )().toVar( 'transformedNormalView' );
8993

9094
/**
9195
* TSL object that represents the transformed vertex normal in world space of the current rendered object.
@@ -105,9 +109,13 @@ export const transformedClearcoatNormalView = /*@__PURE__*/ ( Fn( ( builder ) =>
105109

106110
// Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
107111

108-
return builder.context.setupClearcoatNormal().context( { getUV: null } );
112+
let node = builder.context.setupClearcoatNormal().context( { getUV: null } );
113+
114+
if ( builder.material.flatShading !== true ) node = node.mul( faceDirection );
115+
116+
return node;
109117

110-
}, 'vec3' ).once() )().mul( faceDirection ).toVar( 'transformedClearcoatNormalView' );
118+
}, 'vec3' ).once() )().toVar( 'transformedClearcoatNormalView' );
111119

112120
/**
113121
* Transforms the normal with the given matrix.

src/nodes/display/FrontFacingNode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class FrontFacingNode extends Node {
3838

3939
const { renderer, material } = builder;
4040

41+
if ( material.flatShading === true ) return 'true';
42+
4143
if ( renderer.coordinateSystem === WebGLCoordinateSystem ) {
4244

4345
if ( material.side === BackSide ) {

0 commit comments

Comments
 (0)