bind method

  1. @override
void bind(
  1. RenderPass pass,
  2. TransientWriter transientsBuffer,
  3. Lighting lighting
)
override

Binds this material's render-pass state, uniforms, and textures.

The base implementation enables back-face culling with counter-clockwise winding (matching the glTF convention). Subclasses must call super.bind and then bind any per-material uniforms and textures expected by their fragment shader. lighting carries the IBL EnvironmentMap (and its intensity) plus the analytic lights and shadow resources that materials shade against.

Implementation

@override
void bind(
  gpu.RenderPass pass,
  TransientWriter transientsBuffer,
  Lighting lighting,
) {
  super.bind(pass, transientsBuffer, lighting);

  var fragInfo = Float32List.fromList([
    baseColorFactor.r, baseColorFactor.g,
    baseColorFactor.b, baseColorFactor.a, // color
    vertexColorWeight, // vertex_color_weight
    lodFade, // fade
  ]);
  pass.bindUniform(
    fragmentShader.getUniformSlot("FragInfo"),
    transientsBuffer.emplace(ByteData.sublistView(fragInfo)),
  );
  final transform = _textureTransformScratch
    ..[0] = baseColorTextureTransform.offset.x
    ..[1] = baseColorTextureTransform.offset.y
    ..[2] = baseColorTextureTransform.scale.x
    ..[3] = baseColorTextureTransform.scale.y
    ..[4] = math.cos(baseColorTextureTransform.rotation)
    ..[5] = math.sin(baseColorTextureTransform.rotation)
    ..[6] = baseColorTextureTexCoord.clamp(0, 1).toDouble();
  pass.bindUniform(
    fragmentShader.getUniformSlot('TextureTransform'),
    transientsBuffer.emplace(ByteData.sublistView(transform)),
  );
  pass.bindTexture(
    fragmentShader.getUniformSlot('base_color_texture'),
    Material.whitePlaceholder(resolveTextureSource(baseColorTexture)),
    sampler:
        textureSourceSampler(baseColorTexture) ??
        gpu.SamplerOptions(
          widthAddressMode: gpu.SamplerAddressMode.repeat,
          heightAddressMode: gpu.SamplerAddressMode.repeat,
        ),
  );
  // The unlit shader carries the FogInfo block (fog.glsl) too.
  EngineLightingUniforms.bindFog(
    pass,
    fragmentShader,
    transientsBuffer,
    lighting,
  );
}