applyOcclusionMap function

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

glTF's occlusionStrength lerps between ignoring the map and applying it in full, which is why this is a mix and not a multiply.

Implementation

void applyOcclusionMap(
  Surface s,
  Float32List v,
  ShaderBindings b,
  FragmentContext c, {
  bool transformed = false,
}) {
  final map = b.textures['occlusion_texture'];
  if (map == null) return;
  final (u: mu, v: mv, footprint: uv) = mapUv(
    kMapOcclusion,
    v,
    b,
    c,
    transformed: transformed,
  );
  final occlusion = map.sample(mu, mv, du: uv.du, dv: uv.dv).x;
  final strength = b
      .vec4('FragInfo', 'material2', Vector4.zero())
      .z
      .clamp(0.0, 1.0);
  s.occlusion = 1.0 + (occlusion - 1.0) * strength;
}