ShaderMaterial constructor

ShaderMaterial({
  1. Shader? fragmentShader,
  2. Shader? radianceCubeFragmentShader,
  3. Shader? vertexShader,
  4. Shader? skinnedVertexShader,
  5. Shader? depthVertexShader,
  6. bool useEnvironment = false,
  7. CullMode cullingMode = gpu.CullMode.backFace,
  8. WindingOrder windingOrder = gpu.WindingOrder.clockwise,
  9. bool isOpaqueOverride = true,
  10. Set<RenderInput> sceneInputs = const {},
  11. List<ShaderInstanceAttribute> instanceAttributes = const [],
})

Creates a ShaderMaterial wrapping fragmentShader.

The shader is typically loaded from a .shaderbundle produced by flutter_gpu_shaders. May be omitted at construction and assigned later via setFragmentShader; rendering throws until a shader is set. Set useEnvironment to true to have the engine bind the scene environment's IBL textures by their standard names, and pass instanceAttributes to widen the instance record this material's instanced meshes carry.

Implementation

ShaderMaterial({
  gpu.Shader? fragmentShader,
  gpu.Shader? radianceCubeFragmentShader,
  gpu.Shader? vertexShader,
  gpu.Shader? skinnedVertexShader,
  gpu.Shader? depthVertexShader,
  this.useEnvironment = false,
  this.cullingMode = gpu.CullMode.backFace,
  this.windingOrder = gpu.WindingOrder.clockwise,
  this.isOpaqueOverride = true,
  Set<RenderInput> sceneInputs = const {},
  List<ShaderInstanceAttribute> instanceAttributes = const [],
}) : _sceneInputs = _normalizeSceneInputs(sceneInputs),
     _instanceAttributes = _buildInstanceAttributes(instanceAttributes) {
  // A material constructed with inputs is not in the frame's cached summary
  // yet. Attaching it to a mounted mesh invalidates through the mesh
  // component, but constructing before the first render does not, so cover
  // the declaration itself.
  if (_sceneInputs.isNotEmpty) {
    markMaterialSceneInputsChanged();
  }
  if (fragmentShader != null) {
    setFragmentShader(fragmentShader);
  }
  setRadianceCubeFragmentShader(radianceCubeFragmentShader);
  setVertexShader(vertexShader);
  setVertexShader(skinnedVertexShader, variant: MeshVariant.skinned);
  setVertexShader(depthVertexShader, variant: MeshVariant.depth);
}