@@ -1053,6 +1053,55 @@ class NodeBuilder {
10531053
10541054 }
10551055
1056+ /**
1057+ * Generates the array declaration string.
1058+ *
1059+ * @param {String } type - The type.
1060+ * @param {Number? } [count] - The count.
1061+ * @return {String } The generated value as a shader string.
1062+ */
1063+ generateArrayDeclaration ( type , count ) {
1064+
1065+ return this . getType ( type ) + '[ ' + count + ' ]' ;
1066+
1067+ }
1068+
1069+ /**
1070+ * Generates the array shader string for the given type and value.
1071+ *
1072+ * @param {String } type - The type.
1073+ * @param {Number? } [count] - The count.
1074+ * @param {Array<Node>? } [values=null] - The default values.
1075+ * @return {String } The generated value as a shader string.
1076+ */
1077+ generateArray ( type , count , values = null ) {
1078+
1079+ let snippet = this . generateArrayDeclaration ( type , count ) + '( ' ;
1080+
1081+ for ( let i = 0 ; i < count ; i ++ ) {
1082+
1083+ const value = values ? values [ i ] : null ;
1084+
1085+ if ( value !== null ) {
1086+
1087+ snippet += value . build ( this , type ) ;
1088+
1089+ } else {
1090+
1091+ snippet += this . generateConst ( type ) ;
1092+
1093+ }
1094+
1095+ if ( i < count - 1 ) snippet += ', ' ;
1096+
1097+ }
1098+
1099+ snippet += ' )' ;
1100+
1101+ return snippet ;
1102+
1103+ }
1104+
10561105 /**
10571106 * Generates the shader string for the given type and value.
10581107 *
@@ -1604,6 +1653,23 @@ class NodeBuilder {
16041653
16051654 }
16061655
1656+ /**
1657+ * Returns the array length.
1658+ *
1659+ * @param {Node } node - The node.
1660+ * @return {Number? } The array length.
1661+ */
1662+ getArrayCount ( node ) {
1663+
1664+ let count = null ;
1665+
1666+ if ( node . isArrayNode ) count = node . count ;
1667+ else if ( node . isVarNode && node . node . isArrayNode ) count = node . node . count ;
1668+
1669+ return count ;
1670+
1671+ }
1672+
16071673 /**
16081674 * Returns an instance of {@link NodeVar} for the given variable node.
16091675 *
@@ -1636,7 +1702,11 @@ class NodeBuilder {
16361702
16371703 }
16381704
1639- nodeVar = new NodeVar ( name , type , readOnly ) ;
1705+ //
1706+
1707+ const count = this . getArrayCount ( node ) ;
1708+
1709+ nodeVar = new NodeVar ( name , type , readOnly , count ) ;
16401710
16411711 if ( ! readOnly ) {
16421712
@@ -1671,6 +1741,24 @@ class NodeBuilder {
16711741 return this . isDeterministic ( node . aNode ) &&
16721742 ( node . bNode ? this . isDeterministic ( node . bNode ) : true ) ;
16731743
1744+ } else if ( node . isArrayNode ) {
1745+
1746+ if ( node . values !== null ) {
1747+
1748+ for ( const n of node . values ) {
1749+
1750+ if ( ! this . isDeterministic ( n ) ) {
1751+
1752+ return false ;
1753+
1754+ }
1755+
1756+ }
1757+
1758+ }
1759+
1760+ return true ;
1761+
16741762 } else if ( node . isConstNode ) {
16751763
16761764 return true ;
@@ -2134,11 +2222,12 @@ class NodeBuilder {
21342222 *
21352223 * @param {String } type - The variable's type.
21362224 * @param {String } name - The variable's name.
2225+ * @param {Number? } [count=null] - The array length.
21372226 * @return {String } The shader string.
21382227 */
2139- getVar ( type , name ) {
2228+ getVar ( type , name , count = null ) {
21402229
2141- return `${ this . getType ( type ) } ${ name } ` ;
2230+ return `${ count !== null ? this . generateArrayDeclaration ( type , count ) : this . getType ( type ) } ${ name } ` ;
21422231
21432232 }
21442233
0 commit comments