|
@@ -31,7 +31,7 @@ const supports = {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const wgslFnOpLib = {
|
|
const wgslFnOpLib = {
|
|
|
- '^^': 'threejs_xor'
|
|
|
|
|
|
|
+ '^^': 'tsl_xor'
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const wgslTypeLib = {
|
|
const wgslTypeLib = {
|
|
@@ -73,37 +73,17 @@ const wgslTypeLib = {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const wgslPolyfill = {
|
|
const wgslPolyfill = {
|
|
|
- threejs_xor: new CodeNode( `
|
|
|
|
|
-fn threejs_xor( a : bool, b : bool ) -> bool {
|
|
|
|
|
-
|
|
|
|
|
- return ( a || b ) && !( a && b );
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|
|
|
-` ),
|
|
|
|
|
- lessThanEqual: new CodeNode( `
|
|
|
|
|
-fn threejs_lessThanEqual( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {
|
|
|
|
|
-
|
|
|
|
|
- return vec3<bool>( a.x <= b.x, a.y <= b.y, a.z <= b.z );
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|
|
|
-` ),
|
|
|
|
|
- greaterThan: new CodeNode( `
|
|
|
|
|
-fn threejs_greaterThan( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {
|
|
|
|
|
-
|
|
|
|
|
- return vec3<bool>( a.x > b.x, a.y > b.y, a.z > b.z );
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|
|
|
-` ),
|
|
|
|
|
- mod_float: new CodeNode( 'fn threejs_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }' ),
|
|
|
|
|
- mod_vec2: new CodeNode( 'fn threejs_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }' ),
|
|
|
|
|
- mod_vec3: new CodeNode( 'fn threejs_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }' ),
|
|
|
|
|
- mod_vec4: new CodeNode( 'fn threejs_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }' ),
|
|
|
|
|
- equals_bool: new CodeNode( 'fn threejs_equals_bool( a : bool, b : bool ) -> bool { return a == b; }' ),
|
|
|
|
|
- equals_bvec2: new CodeNode( 'fn threejs_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }' ),
|
|
|
|
|
- equals_bvec3: new CodeNode( 'fn threejs_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }' ),
|
|
|
|
|
- equals_bvec4: new CodeNode( 'fn threejs_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }' ),
|
|
|
|
|
|
|
+ tsl_xor: new CodeNode( 'fn tsl_xor( a : bool, b : bool ) -> bool { return ( a || b ) && !( a && b ); }' ),
|
|
|
|
|
+ mod_float: new CodeNode( 'fn tsl_mod_float( x : f32, y : f32 ) -> f32 { return x - y * floor( x / y ); }' ),
|
|
|
|
|
+ mod_vec2: new CodeNode( 'fn tsl_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }' ),
|
|
|
|
|
+ mod_vec3: new CodeNode( 'fn tsl_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }' ),
|
|
|
|
|
+ mod_vec4: new CodeNode( 'fn tsl_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }' ),
|
|
|
|
|
+ equals_bool: new CodeNode( 'fn tsl_equals_bool( a : bool, b : bool ) -> bool { return a == b; }' ),
|
|
|
|
|
+ equals_bvec2: new CodeNode( 'fn tsl_equals_bvec2( a : vec2f, b : vec2f ) -> vec2<bool> { return vec2<bool>( a.x == b.x, a.y == b.y ); }' ),
|
|
|
|
|
+ equals_bvec3: new CodeNode( 'fn tsl_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == b.x, a.y == b.y, a.z == b.z ); }' ),
|
|
|
|
|
+ equals_bvec4: new CodeNode( 'fn tsl_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == b.x, a.y == b.y, a.z == b.z, a.w == b.w ); }' ),
|
|
|
repeatWrapping: new CodeNode( `
|
|
repeatWrapping: new CodeNode( `
|
|
|
-fn threejs_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {
|
|
|
|
|
|
|
+fn tsl_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {
|
|
|
|
|
|
|
|
let uvScaled = vec2<u32>( uv * vec2<f32>( dimension ) );
|
|
let uvScaled = vec2<u32>( uv * vec2<f32>( dimension ) );
|
|
|
|
|
|
|
@@ -112,7 +92,7 @@ fn threejs_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32>
|
|
|
}
|
|
}
|
|
|
` ),
|
|
` ),
|
|
|
biquadraticTexture: new CodeNode( `
|
|
biquadraticTexture: new CodeNode( `
|
|
|
-fn threejs_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {
|
|
|
|
|
|
|
+fn tsl_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32 ) -> vec4f {
|
|
|
|
|
|
|
|
let res = vec2f( textureDimensions( map, level ) );
|
|
let res = vec2f( textureDimensions( map, level ) );
|
|
|
|
|
|
|
@@ -139,16 +119,14 @@ fn threejs_biquadraticTexture( map : texture_2d<f32>, coord : vec2f, level : i32
|
|
|
const wgslMethods = {
|
|
const wgslMethods = {
|
|
|
dFdx: 'dpdx',
|
|
dFdx: 'dpdx',
|
|
|
dFdy: '- dpdy',
|
|
dFdy: '- dpdy',
|
|
|
- mod_float: 'threejs_mod_float',
|
|
|
|
|
- mod_vec2: 'threejs_mod_vec2',
|
|
|
|
|
- mod_vec3: 'threejs_mod_vec3',
|
|
|
|
|
- mod_vec4: 'threejs_mod_vec4',
|
|
|
|
|
- equals_bool: 'threejs_equals_bool',
|
|
|
|
|
- equals_bvec2: 'threejs_equals_bvec2',
|
|
|
|
|
- equals_bvec3: 'threejs_equals_bvec3',
|
|
|
|
|
- equals_bvec4: 'threejs_equals_bvec4',
|
|
|
|
|
- lessThanEqual: 'threejs_lessThanEqual',
|
|
|
|
|
- greaterThan: 'threejs_greaterThan',
|
|
|
|
|
|
|
+ mod_float: 'tsl_mod_float',
|
|
|
|
|
+ mod_vec2: 'tsl_mod_vec2',
|
|
|
|
|
+ mod_vec3: 'tsl_mod_vec3',
|
|
|
|
|
+ mod_vec4: 'tsl_mod_vec4',
|
|
|
|
|
+ equals_bool: 'tsl_equals_bool',
|
|
|
|
|
+ equals_bvec2: 'tsl_equals_bvec2',
|
|
|
|
|
+ equals_bvec3: 'tsl_equals_bvec3',
|
|
|
|
|
+ equals_bvec4: 'tsl_equals_bvec4',
|
|
|
inversesqrt: 'inverseSqrt',
|
|
inversesqrt: 'inverseSqrt',
|
|
|
bitcast: 'bitcast<f32>'
|
|
bitcast: 'bitcast<f32>'
|
|
|
};
|
|
};
|
|
@@ -157,15 +135,15 @@ const wgslMethods = {
|
|
|
|
|
|
|
|
if ( /Windows/g.test( navigator.userAgent ) ) {
|
|
if ( /Windows/g.test( navigator.userAgent ) ) {
|
|
|
|
|
|
|
|
- wgslPolyfill.pow_float = new CodeNode( 'fn threejs_pow_float( a : f32, b : f32 ) -> f32 { return select( -pow( -a, b ), pow( a, b ), a > 0.0 ); }' );
|
|
|
|
|
- wgslPolyfill.pow_vec2 = new CodeNode( 'fn threejs_pow_vec2( a : vec2f, b : vec2f ) -> vec2f { return vec2f( threejs_pow_float( a.x, b.x ), threejs_pow_float( a.y, b.y ) ); }', [ wgslPolyfill.pow_float ] );
|
|
|
|
|
- wgslPolyfill.pow_vec3 = new CodeNode( 'fn threejs_pow_vec3( a : vec3f, b : vec3f ) -> vec3f { return vec3f( threejs_pow_float( a.x, b.x ), threejs_pow_float( a.y, b.y ), threejs_pow_float( a.z, b.z ) ); }', [ wgslPolyfill.pow_float ] );
|
|
|
|
|
- wgslPolyfill.pow_vec4 = new CodeNode( 'fn threejs_pow_vec4( a : vec4f, b : vec4f ) -> vec4f { return vec4f( threejs_pow_float( a.x, b.x ), threejs_pow_float( a.y, b.y ), threejs_pow_float( a.z, b.z ), threejs_pow_float( a.w, b.w ) ); }', [ wgslPolyfill.pow_float ] );
|
|
|
|
|
|
|
+ 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 = 'threejs_pow_float';
|
|
|
|
|
- wgslMethods.pow_vec2 = 'threejs_pow_vec2';
|
|
|
|
|
- wgslMethods.pow_vec3 = 'threejs_pow_vec3';
|
|
|
|
|
- wgslMethods.pow_vec4 = 'threejs_pow_vec4';
|
|
|
|
|
|
|
+ wgslMethods.pow_float = 'tsl_pow_float';
|
|
|
|
|
+ wgslMethods.pow_vec2 = 'tsl_pow_vec2';
|
|
|
|
|
+ wgslMethods.pow_vec3 = 'tsl_pow_vec3';
|
|
|
|
|
+ wgslMethods.pow_vec4 = 'tsl_pow_vec4';
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -253,7 +231,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
|
|
|
|
|
this._include( 'biquadraticTexture' );
|
|
this._include( 'biquadraticTexture' );
|
|
|
|
|
|
|
|
- return `threejs_biquadraticTexture( ${ textureProperty }, ${ uvSnippet }, i32( ${ levelSnippet } ) )`;
|
|
|
|
|
|
|
+ return `tsl_biquadraticTexture( ${ textureProperty }, ${ uvSnippet }, i32( ${ levelSnippet } ) )`;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -263,7 +241,7 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
|
|
|
|
|
const dimension = texture.isMultisampleRenderTargetTexture === true ? `textureDimensions( ${ textureProperty } )` : `textureDimensions( ${ textureProperty }, 0 )`;
|
|
const dimension = texture.isMultisampleRenderTargetTexture === true ? `textureDimensions( ${ textureProperty } )` : `textureDimensions( ${ textureProperty }, 0 )`;
|
|
|
|
|
|
|
|
- return `textureLoad( ${ textureProperty }, threejs_repeatWrapping( ${ uvSnippet }, ${ dimension } ), i32( ${ levelSnippet } ) )`;
|
|
|
|
|
|
|
+ return `textureLoad( ${ textureProperty }, tsl_repeatWrapping( ${ uvSnippet }, ${ dimension } ), i32( ${ levelSnippet } ) )`;
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|