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,
) {
  pass.setCullMode(cullingMode);
  pass.setWindingOrder(windingOrder);

  // The variant the pipeline was built from, which differs from
  // [fragmentShader] when an environment-sampling material supplied a
  // cube-layout twin and the bound environment uses that layout.
  final shader = fragmentShaderForLighting(lighting);

  for (final entry in _uniformBlocks.entries) {
    final slot = shader.getUniformSlot(entry.key);
    assert(_checkBlock(slot, entry.key, entry.value, ShaderStage.fragment));
    pass.bindUniform(slot, transientsBuffer.emplace(entry.value));
  }

  for (final entry in _textures.entries) {
    // An empty render texture (no completed frame yet) binds the white
    // placeholder so the sampler slot is never left dangling.
    final resolved = _resolveShaderTexture(entry.value.source);
    pass.bindTexture(
      shader.getUniformSlot(entry.key),
      Material.whitePlaceholder(resolved),
      sampler:
          entry.value.sampler ??
          _shaderTextureSampler(entry.value.source) ??
          gpu.SamplerOptions(),
    );
  }

  if (useEnvironment) {
    _bindEnvironmentTextures(pass, shader, lighting);
  }
}