bind method
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);
// A camera-facing quad's winding flips with the viewing angle, so cull
// nothing rather than guess a front face.
pass.setCullMode(gpu.CullMode.none);
// Sprites keep the encoder's translucent depth state: the lessEqual test
// (so opaque geometry occludes them) with depth writes off (so the
// overlapping instances of one instanced draw do not self-occlude).
final fragInfo = Float32List(6);
fragInfo[0] = tint.r;
fragInfo[1] = tint.g;
fragInfo[2] = tint.b;
fragInfo[3] = tint.a;
fragInfo[4] = blendMode == SpriteBlendMode.additive ? 1.0 : 0.0;
fragInfo[5] = 0.0; // soft (reserved)
pass.bindUniform(
fragmentShader.getUniformSlot('FragInfo'),
transientsBuffer.emplace(ByteData.sublistView(fragInfo)),
);
pass.bindTexture(
fragmentShader.getUniformSlot('base_color_texture'),
Material.whitePlaceholder(resolveTextureSource(colorTexture)),
sampler: textureSourceSampler(colorTexture) ?? sampler,
);
}