浏览代码

WebGPURenderer: Improve bump node approach (#28165)

* Improve bump node approach

* update Hll
sunag 1 年之前
父节点
当前提交
0ecd482135
共有 1 个文件被更改,包括 7 次插入26 次删除
  1. 7 26
      examples/jsm/nodes/display/BumpMapNode.js

+ 7 - 26
examples/jsm/nodes/display/BumpMapNode.js

@@ -9,41 +9,22 @@ import { addNodeElement, tslFn, nodeProxy, float, vec2 } from '../shadernode/Sha
 // Bump Mapping Unparametrized Surfaces on the GPU by Morten S. Mikkelsen
 // Bump Mapping Unparametrized Surfaces on the GPU by Morten S. Mikkelsen
 // https://mmikk.github.io/papers3d/mm_sfgrad_bump.pdf
 // https://mmikk.github.io/papers3d/mm_sfgrad_bump.pdf
 
 
-// Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)
-
 const dHdxy_fwd = tslFn( ( { textureNode, bumpScale } ) => {
 const dHdxy_fwd = tslFn( ( { textureNode, bumpScale } ) => {
 
 
-	let texNode = textureNode;
-
-	if ( texNode.isTextureNode !== true ) {
-
-		texNode.traverse( ( node ) => {
-
-			if ( node.isTextureNode === true ) texNode = node;
-
-		} );
-
-	}
-
-	if ( texNode.isTextureNode !== true ) {
-
-		throw new Error( 'THREE.TSL: dHdxy_fwd() requires a TextureNode.' );
-
-	}
-
-	const Hll = float( textureNode );
-	const uvNode = texNode.uvNode || uv();
-
 	// It's used to preserve the same TextureNode instance
 	// It's used to preserve the same TextureNode instance
-	const sampleTexture = ( uv ) => textureNode.cache().context( { getUV: () => uv, forceUVContext: true } );
+	const sampleTexture = ( callback ) => textureNode.cache().context( { getUV: ( texNode ) => callback( texNode.uvNode || uv() ), forceUVContext: true } );
+
+	const Hll = float( sampleTexture( ( uvNode ) => uvNode ) );
 
 
 	return vec2(
 	return vec2(
-		float( sampleTexture( uvNode.add( uvNode.dFdx() ) ) ).sub( Hll ),
-		float( sampleTexture( uvNode.add( uvNode.dFdy() ) ) ).sub( Hll )
+		float( sampleTexture( ( uvNode ) => uvNode.add( uvNode.dFdx() ) ) ).sub( Hll ),
+		float( sampleTexture( ( uvNode ) => uvNode.add( uvNode.dFdy() ) ) ).sub( Hll )
 	).mul( bumpScale );
 	).mul( bumpScale );
 
 
 } );
 } );
 
 
+// Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)
+
 const perturbNormalArb = tslFn( ( inputs ) => {
 const perturbNormalArb = tslFn( ( inputs ) => {
 
 
 	const { surf_pos, surf_norm, dHdxy } = inputs;
 	const { surf_pos, surf_norm, dHdxy } = inputs;