Skip to content

Commit 2f1341e

Browse files
authored
TSL: all, any, equals (#27821)
* TSL: all, any, equals * cleanup
1 parent 28cf746 commit 2f1341e

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

examples/jsm/nodes/Nodes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import * as NodeUtils from './core/NodeUtils.js';
3838
export { NodeUtils };
3939

4040
// math
41-
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';
41+
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';
4242

4343
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';
4444
export { default as CondNode, cond } from './math/CondNode.js';

examples/jsm/nodes/math/MathNode.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ class MathNode extends TempNode {
5757

5858
return 'vec3';
5959

60+
} else if ( method === MathNode.ALL ) {
61+
62+
return 'bool';
63+
64+
} else if ( method === MathNode.EQUALS ) {
65+
66+
return builder.changeComponentType( this.aNode.getNodeType( builder ), 'bool' );
67+
6068
} else if ( method === MathNode.MOD ) {
6169

6270
return this.aNode.getNodeType( builder );
@@ -195,6 +203,10 @@ class MathNode extends TempNode {
195203

196204
// 1 input
197205

206+
MathNode.ALL = 'all';
207+
MathNode.ANY = 'any';
208+
MathNode.EQUALS = 'equals';
209+
198210
MathNode.RADIANS = 'radians';
199211
MathNode.DEGREES = 'degrees';
200212
MathNode.EXP = 'exp';
@@ -256,6 +268,10 @@ export const INFINITY = float( 1e6 );
256268
export const PI = float( Math.PI );
257269
export const PI2 = float( Math.PI * 2 );
258270

271+
export const all = nodeProxy( MathNode, MathNode.ALL );
272+
export const any = nodeProxy( MathNode, MathNode.ANY );
273+
export const equals = nodeProxy( MathNode, MathNode.EQUALS );
274+
259275
export const radians = nodeProxy( MathNode, MathNode.RADIANS );
260276
export const degrees = nodeProxy( MathNode, MathNode.DEGREES );
261277
export const exp = nodeProxy( MathNode, MathNode.EXP );
@@ -315,6 +331,10 @@ export const faceForward = nodeProxy( MathNode, MathNode.FACEFORWARD );
315331
export const mixElement = ( t, e1, e2 ) => mix( e1, e2, t );
316332
export const smoothstepElement = ( x, low, high ) => smoothstep( low, high, x );
317333

334+
addNodeElement( 'all', all );
335+
addNodeElement( 'any', any );
336+
addNodeElement( 'equals', equals );
337+
318338
addNodeElement( 'radians', radians );
319339
addNodeElement( 'degrees', degrees );
320340
addNodeElement( 'exp', exp );

examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { RedFormat, RGFormat, IntType, DataTexture, RGBAFormat, FloatType } from
99

1010
const glslMethods = {
1111
[ MathNode.ATAN2 ]: 'atan',
12-
textureDimensions: 'textureSize'
12+
textureDimensions: 'textureSize',
13+
equals: 'equal'
1314
};
1415

1516
const precisionLib = {

examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ const wgslMethods = {
7777
mod_vec2: 'threejs_mod_vec2',
7878
mod_vec3: 'threejs_mod_vec3',
7979
mod_vec4: 'threejs_mod_vec4',
80+
equals_bool: 'threejs_equals_bool',
81+
equals_bvec2: 'threejs_equals_bvec2',
82+
equals_bvec3: 'threejs_equals_bvec3',
83+
equals_bvec4: 'threejs_equals_bvec4',
8084
lessThanEqual: 'threejs_lessThanEqual',
8185
greaterThan: 'threejs_greaterThan',
8286
inversesqrt: 'inverseSqrt',
@@ -109,6 +113,10 @@ fn threejs_greaterThan( a : vec3<f32>, b : vec3<f32> ) -> vec3<bool> {
109113
mod_vec2: new CodeNode( 'fn threejs_mod_vec2( x : vec2f, y : vec2f ) -> vec2f { return x - y * floor( x / y ); }' ),
110114
mod_vec3: new CodeNode( 'fn threejs_mod_vec3( x : vec3f, y : vec3f ) -> vec3f { return x - y * floor( x / y ); }' ),
111115
mod_vec4: new CodeNode( 'fn threejs_mod_vec4( x : vec4f, y : vec4f ) -> vec4f { return x - y * floor( x / y ); }' ),
116+
equals_bool: new CodeNode( 'fn threejs_equals_bool( a : bool, b : bool ) -> bool { return a == b; }' ),
117+
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 ); }' ),
118+
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 ); }' ),
119+
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 ); }' ),
112120
repeatWrapping: new CodeNode( `
113121
fn threejs_repeatWrapping( uv : vec2<f32>, dimension : vec2<u32> ) -> vec2<u32> {
114122

0 commit comments

Comments
 (0)