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
4 changes: 2 additions & 2 deletions src/materials/nodes/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,9 @@ class NodeMaterial extends Material {

builder.addStack();

const mvp = subBuild( this.setupVertex( builder ), 'VERTEX' );
const mvp = this.setupVertex( builder );

const vertexNode = this.vertexNode || mvp;
const vertexNode = subBuild( this.vertexNode || mvp, 'VERTEX' );

builder.context.clipSpace = vertexNode;

Expand Down
1 change: 0 additions & 1 deletion src/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export { default as RemapNode } from './utils/RemapNode.js';
export { default as RotateNode } from './utils/RotateNode.js';
export { default as SetNode } from './utils/SetNode.js';
export { default as SplitNode } from './utils/SplitNode.js';
export { default as SpriteSheetUVNode } from './utils/SpriteSheetUVNode.js';
export { default as StorageArrayElementNode } from './utils/StorageArrayElementNode.js';
export { default as ReflectorNode } from './utils/ReflectorNode.js';
export { default as RTTNode } from './utils/RTTNode.js';
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/TSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export * from './utils/UVUtils.js';
export * from './utils/SpriteUtils.js';
export * from './utils/ViewportUtils.js';
export * from './utils/RotateNode.js';
export * from './utils/SpriteSheetUVNode.js';
export * from './utils/SpriteSheetUV.js';
export * from './utils/Timer.js';
export * from './utils/TriplanarTextures.js';
export * from './utils/ReflectorNode.js';
Expand Down
4 changes: 2 additions & 2 deletions src/nodes/accessors/Position.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const positionWorld = /*@__PURE__*/ ( Fn( ( builder ) => {

return modelWorldMatrix.mul( positionLocal ).xyz.toVarying( builder.getSubBuildProperty( 'v_positionWorld' ) );

}, 'vec3' ).once( [ 'POSITION' ] ) )();
}, 'vec3' ).once( [ 'POSITION', 'VERTEX' ] ) )();

/**
* TSL object that represents the position world direction of the current rendered object.
Expand Down Expand Up @@ -103,7 +103,7 @@ export const positionView = /*@__PURE__*/ ( Fn( ( builder ) => {

return builder.context.setupPositionView().toVarying( 'v_positionView' );

}, 'vec3' ).once( [ 'POSITION' ] ) )();
}, 'vec3' ).once( [ 'POSITION', 'VERTEX' ] ) )();

/**
* TSL object that represents the position view direction of the current rendered object.
Expand Down
2 changes: 1 addition & 1 deletion src/nodes/core/VaryingNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class VaryingNode extends Node {
*
* @type {Node}
*/
this.node = node;
this.node = subBuild( node, 'VERTEX' );

/**
* The name of the varying in the shader. If no name is defined,
Expand Down
35 changes: 35 additions & 0 deletions src/nodes/utils/SpriteSheetUV.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { uv } from '../accessors/UV.js';
import { Fn, float, vec2 } from '../tsl/TSLBase.js';

/**
* TSL function for computing texture coordinates for animated sprite sheets.
*
* ```js
* const uvNode = spritesheetUV( vec2( 6, 6 ), uv(), time.mul( animationSpeed ) );
*
* material.colorNode = texture( spriteSheet, uvNode );
* ```
*
* @tsl
* @function
* @param {Node<vec2>} countNode - The node that defines the number of sprites in the x and y direction (e.g 6x6).
* @param {?Node<vec2>} [uvNode=uv()] - The uv node.
* @param {?Node<float>} [frameNode=float(0)] - The node that defines the current frame/sprite.
* @returns {Node<vec2>}
*/
export const spritesheetUV = /*@__PURE__*/ Fn( ( [ countNode, uvNode = uv(), frameNode = float( 0 ) ] ) => {

const width = countNode.x;
const height = countNode.y;

const frameNum = frameNode.mod( width.mul( height ) ).floor();

const column = frameNum.mod( width );
const row = height.sub( frameNum.add( 1 ).div( width ).ceil() );

const scale = countNode.reciprocal();
const uvFrameOffset = vec2( column, row );

return uvNode.add( uvFrameOffset ).mul( scale );

} );
90 changes: 0 additions & 90 deletions src/nodes/utils/SpriteSheetUVNode.js

This file was deleted.