Explorar el Código

Nodes: Added frameId (#24680)

sunag hace 2 años
padre
commit
9d15d3e0db

+ 1 - 0
examples/jsm/nodes/shadernode/ShaderNodeElements.js

@@ -115,6 +115,7 @@ export const spritesheetUV = nodeProxy( SpriteSheetUVNode );
 export const timerLocal = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.LOCAL, timeScale, value ) );
 export const timerGlobal = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.GLOBAL, timeScale, value ) );
 export const timerDelta = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.DELTA, timeScale, value ) );
+export const frameId = nodeImmutable( TimerNode, TimerNode.FRAME );
 
 // geometry
 

+ 20 - 0
examples/jsm/nodes/utils/TimerNode.js

@@ -6,6 +6,7 @@ class TimerNode extends UniformNode {
 	static LOCAL = 'local';
 	static GLOBAL = 'global';
 	static DELTA = 'delta';
+	static FRAME = 'frame';
 
 	constructor( scope = TimerNode.LOCAL, scale = 1, value = 0 ) {
 
@@ -17,7 +18,22 @@ class TimerNode extends UniformNode {
 		this.updateType = NodeUpdateType.Frame;
 
 	}
+/*
+	@TODO:
+	getNodeType( builder ) {
 
+		const scope = this.scope;
+
+		if ( scope === TimerNode.FRAME ) {
+
+			return 'uint';
+
+		}
+
+		return 'float';
+
+	}
+*/
 	update( frame ) {
 
 		const scope = this.scope;
@@ -31,6 +47,10 @@ class TimerNode extends UniformNode {
 
 			this.value = frame.deltaTime * scale;
 
+		} else if ( scope === TimerNode.FRAME ) {
+
+			this.value = frame.frameId;
+
 		} else {
 
 			// global