Skip to content

Commit

Permalink
Nodes: Rename remainder() to modInt(). (mrdoob#29092)
Browse files Browse the repository at this point in the history
* fix remainder operator when forceWebGL is set to true

* rename remainder to modInt and mod to modFloat

* remove % code in operatorNode

* fix MathNode

* revert modFloat back to mod

* cleanup

* add nodes export

* added deprecated version

---------

Co-authored-by: sunag <[email protected]>
  • Loading branch information
cmhhelgeson and sunag committed Aug 11, 2024
1 parent 350d1c5 commit 6114fcc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/webgpu_compute_texture.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

const computeTexture = Fn( ( { storageTexture } ) => {

const posX = instanceIndex.remainder( width );
const posX = instanceIndex.modInt( width );
const posY = instanceIndex.div( width );
const indexUV = uvec2( posX, posY );

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export { NodeUtils };
// 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, transpose, all, any, equals, rand } 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, modInt, equal, lessThan, greaterThan, lessThanEqual, greaterThanEqual, and, or, not, xor, bitAnd, bitNot, bitOr, bitXor, shiftLeft, shiftRight, remainder } from './math/OperatorNode.js';
export { default as CondNode, select, cond } from './math/CondNode.js';
export { default as HashNode, hash } from './math/HashNode.js';

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/accessors/BatchNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class BatchNode extends Node {
const getIndirectIndex = Fn( ( [ id ] ) => {

const size = textureSize( textureLoad( this.batchMesh._indirectTexture ), 0 );
const x = int( id ).remainder( int( size ) );
const x = int( id ).modInt( int( size ) );
const y = int( id ).div( int( size ) );
return textureLoad( this.batchMesh._indirectTexture, ivec2( x, y ) ).x;

Expand Down
14 changes: 12 additions & 2 deletions src/nodes/math/OperatorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export const add = nodeProxy( OperatorNode, '+' );
export const sub = nodeProxy( OperatorNode, '-' );
export const mul = nodeProxy( OperatorNode, '*' );
export const div = nodeProxy( OperatorNode, '/' );
export const remainder = nodeProxy( OperatorNode, '%' );
export const modInt = nodeProxy( OperatorNode, '%' );
export const equal = nodeProxy( OperatorNode, '==' );
export const notEqual = nodeProxy( OperatorNode, '!=' );
export const lessThan = nodeProxy( OperatorNode, '<' );
Expand All @@ -285,7 +285,7 @@ addNodeElement( 'add', add );
addNodeElement( 'sub', sub );
addNodeElement( 'mul', mul );
addNodeElement( 'div', div );
addNodeElement( 'remainder', remainder );
addNodeElement( 'modInt', modInt );
addNodeElement( 'equal', equal );
addNodeElement( 'notEqual', notEqual );
addNodeElement( 'lessThan', lessThan );
Expand All @@ -303,4 +303,14 @@ addNodeElement( 'bitXor', bitXor );
addNodeElement( 'shiftLeft', shiftLeft );
addNodeElement( 'shiftRight', shiftRight );


export const remainder = ( ...params ) => { // @deprecated, r168

console.warn( 'TSL.OperatorNode: .remainder() has been renamed to .modInt().' );
return modInt( ...params );

};

addNodeElement( 'remainder', remainder );

addNodeClass( 'OperatorNode', OperatorNode );

0 comments on commit 6114fcc

Please sign in to comment.