Przeglądaj źródła

TSL: all, any, equals (#27821)

* TSL: all, any, equals

* cleanup
sunag 1 rok temu
rodzic
commit
2f1341e570

+ 1 - 1
examples/jsm/nodes/Nodes.js

@@ -38,7 +38,7 @@ import * as NodeUtils from './core/NodeUtils.js';
 export { NodeUtils };
 export { NodeUtils };
 
 
 // math
 // math
-export { default as MathNode, PI, PI2, EPSILON, INFINITY, radians, degrees, exp, exp2, log, log2, sqrt, inverseSqrt, floor, ceil, normalize, fract, sin, cos, tan, asin, acos, atan, abs, sign, length, lengthSq, negate, oneMinus, dFdx, dFdy, round, reciprocal, trunc, fwidth, bitcast, atan2, min, max, mod, step, reflect, distance, difference, dot, cross, pow, pow2, pow3, pow4, transformDirection, mix, clamp, saturate, refract, smoothstep, faceForward, cbrt } from './math/MathNode.js';
+export { default as MathNode, PI, PI2, EPSILON, INFINITY, radians, degrees, exp, exp2, log, log2, sqrt, inverseSqrt, floor, ceil, normalize, fract, sin, cos, tan, asin, acos, atan, abs, sign, length, lengthSq, negate, oneMinus, dFdx, dFdy, round, reciprocal, trunc, fwidth, bitcast, atan2, min, max, mod, step, reflect, distance, difference, dot, cross, pow, pow2, pow3, pow4, transformDirection, mix, clamp, saturate, refract, smoothstep, faceForward, cbrt, all, any, equals } from './math/MathNode.js';
 
 
 export { default as OperatorNode, add, sub, mul, div, remainder, equal, lessThan, greaterThan, lessThanEqual, greaterThanEqual, and, or, not, xor, bitAnd, bitNot, bitOr, bitXor, shiftLeft, shiftRight } from './math/OperatorNode.js';
 export { default as OperatorNode, add, sub, mul, div, remainder, equal, lessThan, greaterThan, lessThanEqual, greaterThanEqual, and, or, not, xor, bitAnd, bitNot, bitOr, bitXor, shiftLeft, shiftRight } from './math/OperatorNode.js';
 export { default as CondNode, cond } from './math/CondNode.js';
 export { default as CondNode, cond } from './math/CondNode.js';

+ 20 - 0
examples/jsm/nodes/math/MathNode.js

@@ -57,6 +57,14 @@ class MathNode extends TempNode {
 
 
 			return 'vec3';
 			return 'vec3';
 
 
+		} else if ( method === MathNode.ALL ) {
+
+			return 'bool';
+
+		} else if ( method === MathNode.EQUALS ) {
+
+			return builder.changeComponentType( this.aNode.getNodeType( builder ), 'bool' );
+
 		} else if ( method === MathNode.MOD ) {
 		} else if ( method === MathNode.MOD ) {
 
 
 			return this.aNode.getNodeType( builder );
 			return this.aNode.getNodeType( builder );
@@ -195,6 +203,10 @@ class MathNode extends TempNode {
 
 
 // 1 input
 // 1 input
 
 
+MathNode.ALL = 'all';
+MathNode.ANY = 'any';
+MathNode.EQUALS = 'equals';
+
 MathNode.RADIANS = 'radians';
 MathNode.RADIANS = 'radians';
 MathNode.DEGREES = 'degrees';
 MathNode.DEGREES = 'degrees';
 MathNode.EXP = 'exp';
 MathNode.EXP = 'exp';
@@ -256,6 +268,10 @@ export const INFINITY = float( 1e6 );
 export const PI = float( Math.PI );
 export const PI = float( Math.PI );
 export const PI2 = float( Math.PI * 2 );
 export const PI2 = float( Math.PI * 2 );
 
 
+export const all = nodeProxy( MathNode, MathNode.ALL );
+export const any = nodeProxy( MathNode, MathNode.ANY );
+export const equals = nodeProxy( MathNode, MathNode.EQUALS );
+
 export const radians = nodeProxy( MathNode, MathNode.RADIANS );
 export const radians = nodeProxy( MathNode, MathNode.RADIANS );
 export const degrees = nodeProxy( MathNode, MathNode.DEGREES );
 export const degrees = nodeProxy( MathNode, MathNode.DEGREES );
 export const exp = nodeProxy( MathNode, MathNode.EXP );
 export const exp = nodeProxy( MathNode, MathNode.EXP );
@@ -315,6 +331,10 @@ export const faceForward = nodeProxy( MathNode, MathNode.FACEFORWARD );
 export const mixElement = ( t, e1, e2 ) => mix( e1, e2, t );
 export const mixElement = ( t, e1, e2 ) => mix( e1, e2, t );
 export const smoothstepElement = ( x, low, high ) => smoothstep( low, high, x );
 export const smoothstepElement = ( x, low, high ) => smoothstep( low, high, x );
 
 
+addNodeElement( 'all', all );
+addNodeElement( 'any', any );
+addNodeElement( 'equals', equals );
+
 addNodeElement( 'radians', radians );
 addNodeElement( 'radians', radians );
 addNodeElement( 'degrees', degrees );
 addNodeElement( 'degrees', degrees );
 addNodeElement( 'exp', exp );
 addNodeElement( 'exp', exp );

+ 2 - 1
examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js

@@ -9,7 +9,8 @@ import { RedFormat, RGFormat, IntType, DataTexture, RGBAFormat, FloatType } from
 
 
 const glslMethods = {
 const glslMethods = {
 	[ MathNode.ATAN2 ]: 'atan',
 	[ MathNode.ATAN2 ]: 'atan',
-	textureDimensions: 'textureSize'
+	textureDimensions: 'textureSize',
+	equals: 'equal'
 };
 };
 
 
 const precisionLib = {
 const precisionLib = {

+ 8 - 0
examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js

@@ -77,6 +77,10 @@ const wgslMethods = {
 	mod_vec2: 'threejs_mod_vec2',
 	mod_vec2: 'threejs_mod_vec2',
 	mod_vec3: 'threejs_mod_vec3',
 	mod_vec3: 'threejs_mod_vec3',
 	mod_vec4: 'threejs_mod_vec4',
 	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',
 	lessThanEqual: 'threejs_lessThanEqual',
 	greaterThan: 'threejs_greaterThan',
 	greaterThan: 'threejs_greaterThan',
 	inversesqrt: 'inverseSqrt',
 	inversesqrt: 'inverseSqrt',
@@ -109,6 +113,10 @@ fn threejs_greaterThan( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {
 	mod_vec2: new CodeNode( 'fn threejs_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { 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_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 ); }' ),
 	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 == a.x, b.y == b.y ); }' ),
+	equals_bvec3: new CodeNode( 'fn threejs_equals_bvec3( a : vec3f, b : vec3f ) -> vec3<bool> { return vec3<bool>( a.x == a.x, b.y == b.y, a.z == a.z ); }' ),
+	equals_bvec4: new CodeNode( 'fn threejs_equals_bvec4( a : vec4f, b : vec4f ) -> vec4<bool> { return vec4<bool>( a.x == a.x, b.y == b.y, a.z == a.z, b.w == b.w ); }' ),
 	repeatWrapping: new CodeNode( `
 	repeatWrapping: new CodeNode( `
 fn threejs_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {
 fn threejs_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {