code: function replace(match, start, end, snippet) {
          var unroll = '';
          // Try to treat as define
          if (isNaN(start)) {
              if (start in defines) {
                  start = defines[start];
              }
              else {
                  start = lightNumberDefines[start];
              }
          }
          if (isNaN(end)) {
              if (end in defines) {
                  end = defines[end];
              }
              else {
                  end = lightNumberDefines[end];
              }
          }
          // TODO Error checking
  
          for (var idx = parseInt(start); idx < parseInt(end); idx++) {
              // PENDING Add scope?
              unroll += '{'
                  + snippet
                      .replace(/float\s*\(\s*_idx_\s*\)/g, idx.toFixed(1))
                      .replace(/_idx_/g, idx)
              + '}';
          }
  
          return unroll;
      }
docs: Loop use _idx_ and increased with _idx_++ will be unrolled Use {{ }} to match the pair so the if statement will not be affected Write like following for (int _idx_ = 0; _idx_ < 4; _idx_++) {{ vec3 color = texture2D(textures[_idx_], uv).rgb; }}