Kaynağa Gözat

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 <sunagbrasil@gmail.com>
Michael Herzog 1 yıl önce
ebeveyn
işleme
aa7f5b9699

+ 12 - 4
src/nodes/accessors/Normal.js

@@ -83,9 +83,13 @@ export const transformedNormalView = /*@__PURE__*/ ( Fn( ( builder ) => {
 
 	// Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
 
-	return builder.context.setupNormal().context( { getUV: null } );
+	let node = builder.context.setupNormal().context( { getUV: null } );
 
-}, 'vec3' ).once() )().mul( faceDirection ).toVar( 'transformedNormalView' );
+	if ( builder.material.flatShading !== true ) node = node.mul( faceDirection );
+
+	return node;
+
+}, 'vec3' ).once() )().toVar( 'transformedNormalView' );
 
 /**
  * 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 ) =>
 
 	// Use getUV context to avoid side effects from nodes overwriting getUV in the context (e.g. EnvironmentNode)
 
-	return builder.context.setupClearcoatNormal().context( { getUV: null } );
+	let node = builder.context.setupClearcoatNormal().context( { getUV: null } );
+
+	if ( builder.material.flatShading !== true ) node = node.mul( faceDirection );
+
+	return node;
 
-}, 'vec3' ).once() )().mul( faceDirection ).toVar( 'transformedClearcoatNormalView' );
+}, 'vec3' ).once() )().toVar( 'transformedClearcoatNormalView' );
 
 /**
  * Transforms the normal with the given matrix.

+ 2 - 0
src/nodes/display/FrontFacingNode.js

@@ -38,6 +38,8 @@ class FrontFacingNode extends Node {
 
 		const { renderer, material } = builder;
 
+		if ( material.flatShading === true ) return 'true';
+
 		if ( renderer.coordinateSystem === WebGLCoordinateSystem ) {
 
 			if ( material.side === BackSide ) {

粤ICP备19079148号