Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/jsm/tsl/math/Bayer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions src/nodes/accessors/BatchNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class BatchNode extends Node {

const getIndirectIndex = Fn( ( [ id ] ) => {

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

Expand All @@ -91,11 +91,11 @@ class BatchNode extends Node {

const matricesTexture = this.batchMesh._matricesTexture;

const size = textureSize( textureLoad( matricesTexture ), 0 );
const size = int( textureSize( textureLoad( matricesTexture ), 0 ).x );
const j = float( indirectId ).mul( 4 ).toInt().toVar();

const x = j.modInt( size );
const y = j.div( int( size ) );
const x = j.mod( size );
const y = j.div( size );
const batchingMatrix = mat4(
textureLoad( matricesTexture, ivec2( x, y ) ),
textureLoad( matricesTexture, ivec2( x.add( 1 ), y ) ),
Expand All @@ -110,9 +110,9 @@ class BatchNode extends Node {

const getBatchingColor = Fn( ( [ id ] ) => {

const size = textureSize( textureLoad( colorsTexture ), 0 ).x;
const size = int( textureSize( textureLoad( colorsTexture ), 0 ).x );
const j = id;
const x = j.modInt( size );
const x = j.mod( size );
const y = j.div( size );
return textureLoad( colorsTexture, ivec2( x, y ) ).rgb;

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/accessors/Normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const normalLocal = /*@__PURE__*/ ( Fn( ( builder ) => {

if ( builder.geometry.hasAttribute( 'normal' ) === false ) {

console.warn( 'TSL.NormalNode: Vertex attribute "normal" not found on geometry.' );
console.warn( 'THREE.TSL: Vertex attribute "normal" not found on geometry.' );

return vec3( 0, 1, 0 );

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/accessors/StorageTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { NodeAccess } from '../core/constants.js';
*
* const computeTexture = Fn( ( { storageTexture } ) => {
*
* const posX = instanceIndex.modInt( width );
* const posX = instanceIndex.mod( width );
* const posY = instanceIndex.div( width );
* const indexUV = uvec2( posX, posY );
*
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/accessors/UniformArrayNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export const uniformArray = ( values, nodeType ) => nodeObject( new UniformArray
*/
export const uniforms = ( values, nodeType ) => { // @deprecated, r168

console.warn( 'TSL.UniformArrayNode: uniforms() has been renamed to uniformArray().' );
console.warn( 'THREE.TSL: uniforms() has been renamed to uniformArray().' );
return nodeObject( new UniformArrayNode( values, nodeType ) );

};
32 changes: 23 additions & 9 deletions src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,6 @@ class NodeBuilder {
*/
this.bindings = { vertex: {}, fragment: {}, compute: {} };


/**
* This dictionary holds the declarations for each shader stage.
*
* @type {Object}
*/
this.declarations = { vertex: {}, fragment: {}, compute: {} };

/**
* This dictionary maintains the binding indices per bind group.
*
Expand Down Expand Up @@ -329,6 +321,13 @@ class NodeBuilder {
*/
this.vars = {};

/**
* This dictionary holds the declarations for each shader stage.
*
* @type {Object}
*/
this.declarations = {};

/**
* Current code flow.
* All code generated in this stack will be stored in `.flow`.
Expand Down Expand Up @@ -1417,6 +1416,18 @@ class NodeBuilder {

}

/**
* Returns the type is an integer type.
*
* @param {string} type - The type.
* @return {boolean} Whether the type is an integer type or not.
*/
isInteger( type ) {

return /int|uint|(i|u)vec/.test( type );

}

/**
* Returns the type for a given buffer attribute.
*
Expand Down Expand Up @@ -1857,7 +1868,7 @@ class NodeBuilder {
registerDeclaration( node ) {

const shaderStage = this.shaderStage;
const declarations = this.declarations[ shaderStage ];
const declarations = this.declarations[ shaderStage ] || ( this.declarations[ shaderStage ] = {} );

const property = this.getPropertyName( node );

Expand Down Expand Up @@ -2171,6 +2182,7 @@ class NodeBuilder {

const previousFlow = this.flow;
const previousVars = this.vars;
const previousDeclarations = this.declarations;
const previousCache = this.cache;
const previousBuildStage = this.buildStage;
const previousStack = this.stack;
Expand All @@ -2181,6 +2193,7 @@ class NodeBuilder {

this.flow = flow;
this.vars = {};
this.declarations = {};
this.cache = new NodeCache();
this.stack = stack();

Expand All @@ -2196,6 +2209,7 @@ class NodeBuilder {

this.flow = previousFlow;
this.vars = previousVars;
this.declarations = previousDeclarations;
this.cache = previousCache;
this.stack = previousStack;

Expand Down
4 changes: 2 additions & 2 deletions src/nodes/core/StackNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class StackNode extends Node {
*/
else( ...params ) { // @deprecated, r168

console.warn( 'TSL.StackNode: .else() has been renamed to .Else().' );
console.warn( 'THREE.TSL: .else() has been renamed to .Else().' );
return this.Else( ...params );

}
Expand All @@ -185,7 +185,7 @@ class StackNode extends Node {
*/
elseif( ...params ) { // @deprecated, r168

console.warn( 'TSL.StackNode: .elseif() has been renamed to .ElseIf().' );
console.warn( 'THREE.TSL: .elseif() has been renamed to .ElseIf().' );
return this.ElseIf( ...params );

}
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/core/VaryingNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ addMethodChaining( 'toVertexStage', vertexStage );

addMethodChaining( 'varying', ( ...params ) => { // @deprecated, r173

console.warn( 'TSL.VaryingNode: .varying() has been renamed to .toVarying().' );
console.warn( 'THREE.TSL: .varying() has been renamed to .toVarying().' );
return varying( ...params );

} );

addMethodChaining( 'vertexStage', ( ...params ) => { // @deprecated, r173

console.warn( 'TSL.VaryingNode: .vertexStage() has been renamed to .toVertexStage().' );
console.warn( 'THREE.TSL: .vertexStage() has been renamed to .toVertexStage().' );
return varying( ...params );

} );
6 changes: 3 additions & 3 deletions src/nodes/display/ScreenNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export const viewportUV = /*@__PURE__*/ viewportCoordinate.div( viewportSize );
*/
export const viewportResolution = /*@__PURE__*/ ( Fn( () => { // @deprecated, r169

console.warn( 'TSL.ViewportNode: "viewportResolution" is deprecated. Use "screenSize" instead.' );
console.warn( 'THREE.TSL: "viewportResolution" is deprecated. Use "screenSize" instead.' );

return screenSize;

Expand All @@ -266,7 +266,7 @@ export const viewportResolution = /*@__PURE__*/ ( Fn( () => { // @deprecated, r1
*/
export const viewportTopLeft = /*@__PURE__*/ ( Fn( () => { // @deprecated, r168

console.warn( 'TSL.ViewportNode: "viewportTopLeft" is deprecated. Use "screenUV" instead.' );
console.warn( 'THREE.TSL: "viewportTopLeft" is deprecated. Use "screenUV" instead.' );

return screenUV;

Expand All @@ -279,7 +279,7 @@ export const viewportTopLeft = /*@__PURE__*/ ( Fn( () => { // @deprecated, r168
*/
export const viewportBottomLeft = /*@__PURE__*/ ( Fn( () => { // @deprecated, r168

console.warn( 'TSL.ViewportNode: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.' );
console.warn( 'THREE.TSL: "viewportBottomLeft" is deprecated. Use "screenUV.flipY()" instead.' );

return screenUV.flipY();

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/gpgpu/ComputeBuiltinNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const numWorkgroups = /*@__PURE__*/ computeBuiltin( 'numWorkgroups', 'uve
* // Execute 12 compute threads with a workgroup size of 3.
* const computeFn = Fn( () => {
*
* If( workgroupId.x.modInt( 2 ).equal( 0 ), () => {
* If( workgroupId.x.mod( 2 ).equal( 0 ), () => {
*
* storageBuffer.element( instanceIndex ).assign( instanceIndex );
*
Expand Down
18 changes: 14 additions & 4 deletions src/nodes/gpgpu/ComputeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,14 @@ class ComputeNode extends Node {

const result = this.computeNode.setup( builder );

const properties = builder.getNodeProperties( this );
properties.outputComputeNode = result.outputNode;
if ( result ) {

result.outputNode = null;
const properties = builder.getNodeProperties( this );
properties.outputComputeNode = result.outputNode;

result.outputNode = null;

}

return result;

Expand All @@ -182,7 +186,13 @@ class ComputeNode extends Node {

if ( shaderStage === 'compute' ) {

this.computeNode.build( builder, 'void' );
const snippet = this.computeNode.build( builder, 'void' );

if ( snippet !== '' ) {

builder.addLineFlowCode( snippet, this );

}

} else {

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/math/ConditionalNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ addMethodChaining( 'select', select );
*/
export const cond = ( ...params ) => { // @deprecated, r168

console.warn( 'TSL.ConditionalNode: cond() has been renamed to select().' );
console.warn( 'THREE.TSL: cond() has been renamed to select().' );
return select( ...params );

};
Expand Down
23 changes: 3 additions & 20 deletions src/nodes/math/MathNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import TempNode from '../core/TempNode.js';
import { sub, mul, div, equal } from './OperatorNode.js';
import { sub, mul, div, mod, equal } from './OperatorNode.js';
import { addMethodChaining, nodeObject, nodeProxy, float, vec2, vec3, vec4, Fn } from '../tsl/TSLCore.js';
import { WebGLCoordinateSystem, WebGPUCoordinateSystem } from '../../constants.js';

Expand Down Expand Up @@ -152,10 +152,6 @@ class MathNode extends TempNode {

return builder.changeComponentType( this.aNode.getNodeType( builder ), 'bool' );

} else if ( method === MathNode.MOD ) {

return this.aNode.getNodeType( builder );

} else {

return this.getInputType( builder );
Expand Down Expand Up @@ -219,7 +215,7 @@ class MathNode extends TempNode {

const params = [];

if ( method === MathNode.CROSS || method === MathNode.MOD ) {
if ( method === MathNode.CROSS ) {

params.push(
a.build( builder, type ),
Expand All @@ -233,7 +229,7 @@ class MathNode extends TempNode {
b.build( builder, inputType )
);

} else if ( ( coordinateSystem === WebGLCoordinateSystem && ( method === MathNode.MIN || method === MathNode.MAX ) ) || method === MathNode.MOD ) {
} else if ( coordinateSystem === WebGLCoordinateSystem && ( method === MathNode.MIN || method === MathNode.MAX ) ) {

params.push(
a.build( builder, inputType ),
Expand Down Expand Up @@ -336,7 +332,6 @@ MathNode.BITCAST = 'bitcast';
MathNode.EQUALS = 'equals';
MathNode.MIN = 'min';
MathNode.MAX = 'max';
MathNode.MOD = 'mod';
MathNode.STEP = 'step';
MathNode.REFLECT = 'reflect';
MathNode.DISTANCE = 'distance';
Expand Down Expand Up @@ -762,17 +757,6 @@ export const min = /*@__PURE__*/ nodeProxy( MathNode, MathNode.MIN ).setParamete
*/
export const max = /*@__PURE__*/ nodeProxy( MathNode, MathNode.MAX ).setParameterLength( 2, Infinity );

/**
* Computes the remainder of dividing the first node by the second one.
*
* @tsl
* @function
* @param {Node | number} x - The y parameter.
* @param {Node | number} y - The x parameter.
* @returns {Node}
*/
export const mod = /*@__PURE__*/ nodeProxy( MathNode, MathNode.MOD ).setParameterLength( 2 );

/**
* Generate a step function by comparing two values.
*
Expand Down Expand Up @@ -1084,7 +1068,6 @@ addMethodChaining( 'fwidth', fwidth );
addMethodChaining( 'atan2', atan2 );
addMethodChaining( 'min', min );
addMethodChaining( 'max', max );
addMethodChaining( 'mod', mod );
addMethodChaining( 'step', step );
addMethodChaining( 'reflect', reflect );
addMethodChaining( 'distance', distance );
Expand Down
Loading