Просмотр исходного кода

Examples: Fix `webgpu_tsl_procedural_terrain` warning (#29574)

* ShadowNode: Use `transformedNormalWorld`

* getGeometryRoughness: Return 0. if there is no normal buffer

* update screenshot
sunag 1 год назад
Родитель
Сommit
234489183c

BIN
examples/screenshots/webgpu_tsl_procedural_terrain.jpg


+ 8 - 2
src/nodes/functions/material/getGeometryRoughness.js

@@ -1,7 +1,13 @@
 import { normalView } from '../../accessors/Normal.js';
-import { Fn } from '../../tsl/TSLBase.js';
+import { float, Fn } from '../../tsl/TSLBase.js';
 
-const getGeometryRoughness = /*@__PURE__*/ Fn( () => {
+const getGeometryRoughness = /*@__PURE__*/ Fn( ( builder ) => {
+
+	if ( builder.geometry.hasAttribute( 'normal' ) === false ) {
+
+		return float( 0 );
+
+	}
 
 	const dxy = normalView.dFdx().abs().max( normalView.dFdy().abs() );
 	const geometryRoughness = dxy.x.max( dxy.y ).max( dxy.z );

+ 2 - 2
src/nodes/lighting/ShadowNode.js

@@ -5,7 +5,7 @@ import { float, vec2, vec3, vec4, If, int, Fn, nodeObject } from '../tsl/TSLBase
 import { reference } from '../accessors/ReferenceNode.js';
 import { texture } from '../accessors/TextureNode.js';
 import { positionWorld } from '../accessors/Position.js';
-import { normalWorld } from '../accessors/Normal.js';
+import { transformedNormalWorld } from '../accessors/Normal.js';
 import { mix, fract, step, max, clamp, sqrt } from '../math/MathNode.js';
 import { add, sub } from '../math/OperatorNode.js';
 import { DepthTexture } from '../../textures/DepthTexture.js';
@@ -289,7 +289,7 @@ class ShadowNode extends Node {
 
 		const position = object.material.shadowPositionNode || positionWorld;
 
-		let shadowCoord = uniform( shadow.matrix ).setGroup( renderGroup ).mul( position.add( normalWorld.mul( normalBias ) ) );
+		let shadowCoord = uniform( shadow.matrix ).setGroup( renderGroup ).mul( position.add( transformedNormalWorld.mul( normalBias ) ) );
 
 		let coordZ;
 

粤ICP备19079148号