Skip to content

Commit 23d9a43

Browse files
authored
TSL: Overloaded atan2 to atan (#30131)
* overloaded atan2 * update dependencies: `atan2` to `atan`
1 parent ec02bf7 commit 23d9a43

File tree

8 files changed

+42
-32
lines changed

8 files changed

+42
-32
lines changed

examples/webgpu_animation_retargeting.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<script type="module">
2626

2727
import * as THREE from 'three';
28-
import { color, screenUV, hue, reflector, time, Fn, vec2, length, atan2, float, sin, cos, vec3, sub, mul, pow, blendDodge, normalWorld } from 'three/tsl';
28+
import { color, screenUV, hue, reflector, time, Fn, vec2, length, atan, float, sin, cos, vec3, sub, mul, pow, blendDodge, normalWorld } from 'three/tsl';
2929

3030
import Stats from 'three/addons/libs/stats.module.js';
3131

@@ -63,7 +63,7 @@
6363
// forked from https://www.shadertoy.com/view/7ly3D1
6464

6565
const suv = vec2( suv_immutable );
66-
const uv = vec2( length( suv ), atan2( suv.y, suv.x ) );
66+
const uv = vec2( length( suv ), atan( suv.y, suv.x ) );
6767
const offset = float( float( .1 ).mul( sin( uv.y.mul( 10. ).sub( time.mul( .6 ) ) ) ).mul( cos( uv.y.mul( 48. ).add( time.mul( .3 ) ) ) ).mul( cos( uv.y.mul( 3.7 ).add( time ) ) ) );
6868
const rays = vec3( vec3( sin( uv.y.mul( 150. ).add( time ) ).mul( .5 ).add( .5 ) ).mul( vec3( sin( uv.y.mul( 80. ).sub( time.mul( 0.6 ) ) ).mul( .5 ).add( .5 ) ) ).mul( vec3( sin( uv.y.mul( 45. ).add( time.mul( 0.8 ) ) ).mul( .5 ).add( .5 ) ) ).mul( vec3( sub( 1., cos( uv.y.add( mul( 22., time ).sub( pow( uv.x.add( offset ), .3 ).mul( 60. ) ) ) ) ) ) ).mul( vec3( uv.x.mul( 2. ) ) ) );
6969

examples/webgpu_tsl_angular_slicing.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<script type="module">
2929

3030
import * as THREE from 'three';
31-
import { If, PI2, atan2, color, frontFacing, output, positionLocal, Fn, uniform, vec4 } from 'three/tsl';
31+
import { If, PI2, atan, color, frontFacing, output, positionLocal, Fn, uniform, vec4 } from 'three/tsl';
3232

3333
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
3434
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
@@ -80,7 +80,7 @@
8080

8181
const inAngle = Fn( ( [ position, angleStart, angleArc ] ) => {
8282

83-
const angle = atan2( position.y, position.x ).sub( angleStart ).mod( PI2 ).toVar();
83+
const angle = atan( position.y, position.x ).sub( angleStart ).mod( PI2 ).toVar();
8484
return angle.greaterThan( 0 ).and( angle.lessThan( angleArc ) );
8585

8686
} );

examples/webgpu_tsl_vfx_linkedparticles.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<script type="module">
2929

3030
import * as THREE from 'three';
31-
import { atan2, cos, float, max, min, mix, PI, PI2, sin, vec2, vec3, color, Fn, hash, hue, If, instanceIndex, Loop, mx_fractal_noise_float, mx_fractal_noise_vec3, pass, pcurve, storage, deltaTime, time, uv, uniform } from 'three/tsl';
31+
import { atan, cos, float, max, min, mix, PI, PI2, sin, vec2, vec3, color, Fn, hash, hue, If, instanceIndex, Loop, mx_fractal_noise_float, mx_fractal_noise_vec3, pass, pcurve, storage, deltaTime, time, uv, uniform } from 'three/tsl';
3232
import { bloom } from 'three/addons/tsl/display/BloomNode.js';
3333

3434
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
@@ -127,7 +127,7 @@
127127
particleMaterial.depthWrite = false;
128128
particleMaterial.positionNode = particlePositions.toAttribute();
129129
particleMaterial.scaleNode = vec2( particleSize );
130-
particleMaterial.rotationNode = atan2( particleVelocities.toAttribute().y, particleVelocities.toAttribute().x );
130+
particleMaterial.rotationNode = atan( particleVelocities.toAttribute().y, particleVelocities.toAttribute().x );
131131

132132
particleMaterial.colorNode = /*#__PURE__*/ Fn( () => {
133133

@@ -396,7 +396,7 @@
396396

397397
}
398398

399-
function onWindowResize( e ) {
399+
function onWindowResize() {
400400

401401
camera.aspect = window.innerWidth / window.innerHeight;
402402
camera.updateProjectionMatrix();
@@ -419,11 +419,11 @@
419419

420420
}
421421

422-
async function animate() {
422+
function animate() {
423423

424424
// compute particles
425-
await renderer.computeAsync( updateParticles );
426-
await renderer.computeAsync( spawnParticles );
425+
renderer.compute( updateParticles );
426+
renderer.compute( spawnParticles );
427427

428428
// update particle index for next spawn
429429
spawnIndex.value = ( spawnIndex.value + nbToSpawn.value ) % nbParticles;
@@ -448,7 +448,7 @@
448448

449449
controls.update();
450450

451-
postProcessing.renderAsync();
451+
postProcessing.render();
452452

453453
}
454454

examples/webgpu_tsl_vfx_tornado.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<script type="module">
2929

3030
import * as THREE from 'three';
31-
import { luminance, cos, float, min, time, atan2, uniform, pass, PI, PI2, color, positionLocal, oneMinus, sin, texture, Fn, uv, vec2, vec3, vec4 } from 'three/tsl';
31+
import { luminance, cos, float, min, time, atan, uniform, pass, PI, PI2, color, positionLocal, oneMinus, sin, texture, Fn, uv, vec2, vec3, vec4 } from 'three/tsl';
3232
import { bloom } from 'three/addons/tsl/display/BloomNode.js';
3333

3434
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
@@ -58,7 +58,7 @@
5858

5959
const centeredUv = uv.sub( 0.5 ).toVar();
6060
const distanceToCenter = centeredUv.length();
61-
const angle = atan2( centeredUv.y, centeredUv.x );
61+
const angle = atan( centeredUv.y, centeredUv.x );
6262
const radialUv = vec2( angle.add( PI ).div( PI2 ), distanceToCenter ).toVar();
6363
radialUv.mulAssign( multiplier );
6464
radialUv.x.addAssign( rotation );
@@ -79,7 +79,7 @@
7979

8080
const twistedCylinder = Fn( ( [ position, parabolStrength, parabolOffset, parabolAmplitude, time ] ) => {
8181

82-
const angle = atan2( position.z, position.x ).toVar();
82+
const angle = atan( position.z, position.x ).toVar();
8383
const elevation = position.y;
8484

8585
// parabol

src/nodes/math/MathNode.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import TempNode from '../core/TempNode.js';
22
import { sub, mul, div } from './OperatorNode.js';
33
import { addMethodChaining, nodeObject, nodeProxy, float, vec2, vec3, vec4, Fn } from '../tsl/TSLCore.js';
4+
import { WebGLCoordinateSystem, WebGPUCoordinateSystem } from '../../constants.js';
45

56
/** @module MathNode **/
67

@@ -140,7 +141,7 @@ class MathNode extends TempNode {
140141

141142
generate( builder, output ) {
142143

143-
const method = this.method;
144+
let method = this.method;
144145

145146
const type = this.getNodeType( builder );
146147
const inputType = this.getInputType( builder );
@@ -149,7 +150,7 @@ class MathNode extends TempNode {
149150
const b = this.bNode;
150151
const c = this.cNode;
151152

152-
const isWebGL = builder.renderer.isWebGLRenderer === true;
153+
const coordinateSystem = builder.renderer.coordinateSystem;
153154

154155
if ( method === MathNode.TRANSFORM_DIRECTION ) {
155156

@@ -200,14 +201,14 @@ class MathNode extends TempNode {
200201
b.build( builder, type )
201202
);
202203

203-
} else if ( isWebGL && method === MathNode.STEP ) {
204+
} else if ( coordinateSystem === WebGLCoordinateSystem && method === MathNode.STEP ) {
204205

205206
params.push(
206207
a.build( builder, builder.getTypeLength( a.getNodeType( builder ) ) === 1 ? 'float' : inputType ),
207208
b.build( builder, inputType )
208209
);
209210

210-
} else if ( ( isWebGL && ( method === MathNode.MIN || method === MathNode.MAX ) ) || method === MathNode.MOD ) {
211+
} else if ( ( coordinateSystem === WebGLCoordinateSystem && ( method === MathNode.MIN || method === MathNode.MAX ) ) || method === MathNode.MOD ) {
211212

212213
params.push(
213214
a.build( builder, inputType ),
@@ -232,6 +233,12 @@ class MathNode extends TempNode {
232233

233234
} else {
234235

236+
if ( coordinateSystem === WebGPUCoordinateSystem && method === MathNode.ATAN && b !== null ) {
237+
238+
method = 'atan2';
239+
240+
}
241+
235242
params.push( a.build( builder, inputType ) );
236243
if ( b !== null ) params.push( b.build( builder, inputType ) );
237244
if ( c !== null ) params.push( c.build( builder, inputType ) );
@@ -302,7 +309,6 @@ MathNode.TRANSPOSE = 'transpose';
302309

303310
MathNode.BITCAST = 'bitcast';
304311
MathNode.EQUALS = 'equals';
305-
MathNode.ATAN2 = 'atan2';
306312
MathNode.MIN = 'min';
307313
MathNode.MAX = 'max';
308314
MathNode.MOD = 'mod';
@@ -665,16 +671,6 @@ export const bitcast = /*@__PURE__*/ nodeProxy( MathNode, MathNode.BITCAST );
665671
*/
666672
export const equals = /*@__PURE__*/ nodeProxy( MathNode, MathNode.EQUALS );
667673

668-
/**
669-
* Returns the arc-tangent of the quotient of its parameters.
670-
*
671-
* @function
672-
* @param {Node | Number} x - The y parameter.
673-
* @param {Node | Number} y - The x parameter.
674-
* @returns {Node}
675-
*/
676-
export const atan2 = /*@__PURE__*/ nodeProxy( MathNode, MathNode.ATAN2 );
677-
678674
/**
679675
* Returns the lesser of two values.
680676
*
@@ -932,6 +928,21 @@ export const mixElement = ( t, e1, e2 ) => mix( e1, e2, t );
932928
*/
933929
export const smoothstepElement = ( x, low, high ) => smoothstep( low, high, x );
934930

931+
/**
932+
* Returns the arc-tangent of the quotient of its parameters.
933+
*
934+
* @function
935+
* @param {Node | Number} y - The y parameter.
936+
* @param {Node | Number} x - The x parameter.
937+
* @returns {Node}
938+
*/
939+
export const atan2 = ( y, x ) => { // @deprecated, r172
940+
941+
console.warn( 'THREE.TSL: "atan2" is overloaded. Use "atan" instead.' );
942+
return atan( y, x );
943+
944+
};
945+
935946
addMethodChaining( 'all', all );
936947
addMethodChaining( 'any', any );
937948
addMethodChaining( 'equals', equals );

src/nodes/utils/EquirectUVNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class EquirectUVNode extends TempNode {
4545

4646
const dir = this.dirNode;
4747

48-
const u = dir.z.atan2( dir.x ).mul( 1 / ( Math.PI * 2 ) ).add( 0.5 );
48+
const u = dir.z.atan( dir.x ).mul( 1 / ( Math.PI * 2 ) ).add( 0.5 );
4949
const v = dir.y.clamp( - 1.0, 1.0 ).asin().mul( 1 / Math.PI ).add( 0.5 );
5050

5151
return vec2( u, v );

src/nodes/utils/FunctionOverloadingNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Node from '../core/Node.js';
2-
import { nodeProxy } from '../tsl/TSLBase.js';
2+
import { nodeProxy } from '../tsl/TSLCore.js';
33

44
/** @module FunctionOverloadingNode **/
55

src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { NoColorSpace, ByteType, ShortType, RGBAIntegerFormat, RGBIntegerFormat,
99
import { DataTexture } from '../../../textures/DataTexture.js';
1010

1111
const glslMethods = {
12-
atan2: 'atan',
1312
textureDimensions: 'textureSize',
1413
equals: 'equal'
1514
};

0 commit comments

Comments
 (0)