Răsfoiți Sursa

WGSLNodeBuilder: Fix out-of-bounds access with `textureLoad()`. (#32817)

Michael Herzog 1 lună în urmă
părinte
comite
e1c93eecd5
2 a modificat fișierele cu 4 adăugiri și 2 ștergeri
  1. 1 1
      src/math/MathUtils.js
  2. 3 1
      src/renderers/webgpu/nodes/WGSLNodeBuilder.js

+ 1 - 1
src/math/MathUtils.js

@@ -177,7 +177,7 @@ function smoothstep( x, min, max ) {
 
 /**
  * A [variation on smoothstep](https://en.wikipedia.org/wiki/Smoothstep#Variations)
- * that has zero 1st and 2nd order derivatives at `x=0` and `x=1`. 
+ * that has zero 1st and 2nd order derivatives at `x=0` and `x=1`.
  *
  * @param {number} x - The value to evaluate based on its position between `min` and `max`.
  * @param {number} min - The min value. Any `x` value below `min` will be `0`. `min` must be lower than `max`.

+ 3 - 1
src/renderers/webgpu/nodes/WGSLNodeBuilder.js

@@ -525,7 +525,9 @@ class WGSLNodeBuilder extends NodeBuilder {
 
 		}
 
-		uvSnippet = `${ vecType }<u32>( ${ wrapFunction }( ${ uvSnippet } ) * ${ vecType }<f32>( ${ textureDimension } ) )`;
+		const textureDimensionMargin = ( vecType === 'vec3' ) ? 'vec3<u32>(1,1,1)' : 'vec2<u32>(1,1)';
+
+		uvSnippet = `${ vecType }<u32>( ${ wrapFunction }( ${ uvSnippet } ) * ${ vecType }<f32>( ${ textureDimension } - ${ textureDimensionMargin } ) )`;
 
 		return this.generateTextureLoad( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet, null );
 

粤ICP备19079148号