Переглянути джерело

TSL: Refine `pow2/3/4` implementation and remove the polyfill for `pow` on Windows (#31720)

* Change pow2, pow3, pow4 implementations, remove polyfill

* Address non-integer powers of negative bases

* E2E: Fix screenshot
Shota Matsuda 4 місяців тому
батько
коміт
36c9890a51

BIN
examples/screenshots/webgpu_tsl_galaxy.jpg


+ 1 - 1
examples/webgpu_tsl_galaxy.html

@@ -68,7 +68,7 @@
 					sin( angle )
 					sin( angle )
 				).mul( radius );
 				).mul( radius );
 
 
-				const randomOffset = range( vec3( - 1 ), vec3( 1 ) ).pow( 3 ).mul( radiusRatio ).add( 0.2 );
+				const randomOffset = range( vec3( - 1 ), vec3( 1 ) ).pow3().mul( radiusRatio ).add( 0.2 );
 
 
 				material.positionNode = position.add( randomOffset );
 				material.positionNode = position.add( randomOffset );
 
 

+ 1 - 1
examples/webgpu_tsl_vfx_flames.html

@@ -136,7 +136,7 @@
 					// main UV
 					// main UV
 					const mainUv = uv().toVar();
 					const mainUv = uv().toVar();
 					mainUv.assign( spherizeUV( mainUv, 10 ).mul( 0.6 ).add( 0.2 ) ); // spherize
 					mainUv.assign( spherizeUV( mainUv, 10 ).mul( 0.6 ).add( 0.2 ) ); // spherize
-					mainUv.assign( mainUv.pow( vec2( 1, 3 ) ) ); // stretch
+					mainUv.assign( mainUv.abs().pow( vec2( 1, 3 ) ).mul( mainUv.sign() ) ); // stretch
 					mainUv.assign( mainUv.mul( 2, 1 ).sub( vec2( 0.5, 0 ) ) ); // scale
 					mainUv.assign( mainUv.mul( 2, 1 ).sub( vec2( 0.5, 0 ) ) ); // scale
 
 
 					// perlin noise
 					// perlin noise

+ 3 - 3
src/nodes/math/MathNode.js

@@ -900,7 +900,7 @@ export const pow = /*@__PURE__*/ nodeProxyIntent( MathNode, MathNode.POW ).setPa
  * @param {Node | number} x - The first parameter.
  * @param {Node | number} x - The first parameter.
  * @returns {Node}
  * @returns {Node}
  */
  */
-export const pow2 = /*@__PURE__*/ nodeProxyIntent( MathNode, MathNode.POW, 2 ).setParameterLength( 1 );
+export const pow2 = ( x ) => mul( x, x );
 
 
 /**
 /**
  * Returns the cube of the parameter.
  * Returns the cube of the parameter.
@@ -910,7 +910,7 @@ export const pow2 = /*@__PURE__*/ nodeProxyIntent( MathNode, MathNode.POW, 2 ).s
  * @param {Node | number} x - The first parameter.
  * @param {Node | number} x - The first parameter.
  * @returns {Node}
  * @returns {Node}
  */
  */
-export const pow3 = /*@__PURE__*/ nodeProxyIntent( MathNode, MathNode.POW, 3 ).setParameterLength( 1 );
+export const pow3 = ( x ) => mul( x, x, x );
 
 
 /**
 /**
  * Returns the fourth power of the parameter.
  * Returns the fourth power of the parameter.
@@ -920,7 +920,7 @@ export const pow3 = /*@__PURE__*/ nodeProxyIntent( MathNode, MathNode.POW, 3 ).s
  * @param {Node | number} x - The first parameter.
  * @param {Node | number} x - The first parameter.
  * @returns {Node}
  * @returns {Node}
  */
  */
-export const pow4 = /*@__PURE__*/ nodeProxyIntent( MathNode, MathNode.POW, 4 ).setParameterLength( 1 );
+export const pow4 = ( x ) => mul( x, x, x, x );
 
 
 /**
 /**
  * Transforms the direction of a vector by a matrix and then normalizes the result.
  * Transforms the direction of a vector by a matrix and then normalizes the result.

+ 0 - 16
src/renderers/webgpu/nodes/WGSLNodeBuilder.js

@@ -131,22 +131,6 @@ const wgslMethods = {
 	bitcast: 'bitcast<f32>'
 	bitcast: 'bitcast<f32>'
 };
 };
 
 
-// WebGPU issue: does not support pow() with negative base on Windows
-
-if ( typeof navigator !== 'undefined' && /Windows/g.test( navigator.userAgent ) ) {
-
-	wgslPolyfill.pow_float = new CodeNode( 'fn tsl_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }' );
-	wgslPolyfill.pow_vec2 = new CodeNode( 'fn tsl_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ) ); }', [ wgslPolyfill.pow_float ] );
-	wgslPolyfill.pow_vec3 = new CodeNode( 'fn tsl_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ) ); }', [ wgslPolyfill.pow_float ] );
-	wgslPolyfill.pow_vec4 = new CodeNode( 'fn tsl_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( tsl_pow_float( a.x, b.x ), tsl_pow_float( a.y, b.y ), tsl_pow_float( a.z, b.z ), tsl_pow_float( a.w, b.w ) ); }', [ wgslPolyfill.pow_float ] );
-
-	wgslMethods.pow_float = 'tsl_pow_float';
-	wgslMethods.pow_vec2 = 'tsl_pow_vec2';
-	wgslMethods.pow_vec3 = 'tsl_pow_vec3';
-	wgslMethods.pow_vec4 = 'tsl_pow_vec4';
-
-}
-
 //
 //
 
 
 let diagnostics = '';
 let diagnostics = '';

粤ICP备19079148号