getUniforms method

  1. @override
dynamic getUniforms(
  1. dynamic shaderStage
)
override

Implementation

@override
getUniforms(shaderStage) {
  var uniforms = this.uniforms[shaderStage];

  var bindingSnippets = [];
		var bufferSnippets = [];
		var groupSnippets = [];

  var index = this.bindingsOffset[shaderStage];

  for (var uniform in uniforms) {
    if (uniform.type == 'texture') {
      if (shaderStage == 'fragment') {
        bindingSnippets.add( "@group( 0 ) @binding( ${index ++} ) var ${uniform.name}_sampler : sampler;" );
      }

      bindingSnippets.add( "@group( 0 ) @binding( ${index ++} ) var ${uniform.name} : texture_2d<f32>;" );
    } else if ( uniform.type == 'cubeTexture' ) {

				if ( shaderStage == 'fragment' ) {

					bindingSnippets.add( "@group( 0 ) @binding( ${index ++} ) var ${uniform.name}_sampler : sampler;" );

				}

				bindingSnippets.add( "@group( 0 ) @binding( ${index ++} ) var ${uniform.name} : texture_cube<f32>;" );
    } else if (uniform.type == 'buffer') {
      var bufferNode = uniform.node;
      var bufferType = this.getType(bufferNode.bufferType);
      var bufferCount = bufferNode.bufferCount;

      var bufferSnippet = "\t${uniform.name} : array< ${bufferType}, ${bufferCount} >\n";

      bufferSnippets.add( this._getWGSLUniforms( 'NodeBuffer', bufferSnippet, index ++ ) );
    } else {
      var vectorType = this.getType(this.getVectorType(uniform.type));

      if (uniform.value is List) {
        var length = uniform.value.length;

        groupSnippets.add( "uniform ${vectorType}[ ${length} ] ${uniform.name}" );
      } else {
        groupSnippets.add( "\t${uniform.name} : ${ vectorType}" );
      }
    }
  }

  var code = bindingSnippets.join( '\n' );
		code += bufferSnippets.join( ',\n' );

  if (groupSnippets.length > 0) {
    code += this._getWGSLUniforms( 'NodeUniforms', groupSnippets.join( ',\n' ), index ++ );
  }

  return code;
}