applyMetallicRoughnessMap function

void applyMetallicRoughnessMap(
  1. Surface s,
  2. Float32List v,
  3. ShaderBindings b,
  4. FragmentContext c, {
  5. bool transformed = false,
})

glTF's ORM packing: roughness in g, metallic in b.

Implementation

void applyMetallicRoughnessMap(
  Surface s,
  Float32List v,
  ShaderBindings b,
  FragmentContext c, {
  bool transformed = false,
}) {
  final orm = b.textures['metallic_roughness_texture'];
  if (orm == null) return;
  final (u: mu, v: mv, footprint: uv) = mapUv(
    kMapMetallicRoughness,
    v,
    b,
    c,
    transformed: transformed,
  );
  final texel = orm.sample(mu, mv, du: uv.du, dv: uv.dv);
  s.metallic = (s.metallic * texel.z).clamp(0.0, 1.0);
  s.roughness = (s.roughness * texel.y).clamp(0.02, 1.0);
}