|
|
@@ -1,5 +1,6 @@
|
|
|
import Node from './Node.js';
|
|
|
import { addMethodChaining, getCurrentStack, nodeProxy } from '../tsl/TSLCore.js';
|
|
|
+import { error } from '../../utils.js';
|
|
|
|
|
|
/**
|
|
|
* Class for representing shader variables as nodes. Variables are created from
|
|
|
@@ -146,14 +147,43 @@ class VarNode extends Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ isAssign( builder ) {
|
|
|
+
|
|
|
+ const properties = builder.getNodeProperties( this );
|
|
|
+
|
|
|
+ let assign = properties.assign;
|
|
|
+
|
|
|
+ if ( assign !== true ) {
|
|
|
+
|
|
|
+ if ( this.node.isShaderCallNodeInternal && this.node.shaderNode.getLayout() === null ) {
|
|
|
+
|
|
|
+ if ( builder.fnCall && builder.fnCall.shaderNode ) {
|
|
|
+
|
|
|
+ const shaderNodeData = builder.getDataFromNode( this.node.shaderNode );
|
|
|
+
|
|
|
+ if ( shaderNodeData.hasLoop ) {
|
|
|
+
|
|
|
+ assign = true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return assign;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
build( ...params ) {
|
|
|
|
|
|
if ( this.intent === true ) {
|
|
|
|
|
|
const builder = params[ 0 ];
|
|
|
- const properties = builder.getNodeProperties( this );
|
|
|
|
|
|
- if ( properties.assign !== true ) {
|
|
|
+ if ( this.isAssign( builder ) !== true ) {
|
|
|
|
|
|
return this.node.build( ...params );
|
|
|
|
|
|
@@ -183,7 +213,23 @@ class VarNode extends Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
- const vectorType = builder.getVectorType( this.getNodeType( builder ) );
|
|
|
+ const nodeType = this.getNodeType( builder );
|
|
|
+
|
|
|
+ if ( nodeType == 'void' ) {
|
|
|
+
|
|
|
+ if ( this.intent !== true ) {
|
|
|
+
|
|
|
+ error( 'TSL: ".toVar()" can not be used with void type.' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ const snippet = node.build( builder );
|
|
|
+
|
|
|
+ return snippet;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ const vectorType = builder.getVectorType( nodeType );
|
|
|
const snippet = node.build( builder, vectorType );
|
|
|
|
|
|
const nodeVar = builder.getVarFromNode( this, name, vectorType, undefined, shouldTreatAsReadOnly );
|