materialVertexShader method

  1. @override
Shader? materialVertexShader(
  1. String variant
)

The vertex shader this material supplies for a geometry's variant ('unskinned' / 'skinned' for the color pass, 'depth' for the position-only depth/shadow pass; see Geometry.materialVertexVariant), or null to use the engine's standard vertex shader for the geometry.

The base class supplies none, so drawing is unchanged. A .fmat with a vertex { } block (see PreprocessedMaterial) returns the matching generated variant, which the encoder pairs with this material's fragment shader.

Implementation

@override
gpu.Shader? materialVertexShader(String variant) {
  final kind = MeshVariant.fromName(variant);
  final shader = _vertexShaders[kind];
  // Falling back to the engine's shader is fine when the fragment shader
  // only reads engine varyings, and fatal when it reads one this material's
  // own vertex shader writes: the engine's does not write it, and pipeline
  // creation fails with a backend interface error naming an anonymous
  // location. Say which variant is missing while the author can still act
  // on it. Debug-only, and once per variant.
  assert(() {
    if (shader == null && _vertexShaders.isNotEmpty) {
      _warnMissingVertexVariant(kind);
    }
    return true;
  }());
  return shader;
}