mapUv function

({UvFootprint footprint, double u, double v}) mapUv(
  1. int slot,
  2. Float32List v,
  3. ShaderBindings b,
  4. FragmentContext c, {
  5. bool transformed = false,
})

MapUv(slot): where map slot is read, with the footprint there — C8.

The vertex's own coordinate unless transformed, which only the layered stage is: every other stage's MapUv is a macro for v_texcoord, and reading LayerInfo here for them would read whatever an earlier layered draw left in the encoder. The footprint is the vertex coordinate's carried through the matrix, which is what a GPU's derivative of the transformed coordinate is. The identity reads both back to the bit.

Implementation

({double u, double v, UvFootprint footprint}) mapUv(
  int slot,
  Float32List v,
  ShaderBindings b,
  FragmentContext c, {
  bool transformed = false,
}) {
  final plain = uvFootprint(c, bias: materialLodBias(b));
  final rows = transformed ? b.read('LayerInfo', 'uv_transform') : null;
  if (rows == null || rows.length < slot * 8 + 8) {
    return (u: v[kVUv], v: v[kVUv + 1], footprint: plain);
  }
  final o = slot * 8;
  final (m00, m01, m02) = (rows[o], rows[o + 1], rows[o + 2]);
  final (m10, m11, m12) = (rows[o + 4], rows[o + 5], rows[o + 6]);
  final dudx = m00 * plain.dudx + m01 * plain.dvdx;
  final dvdx = m10 * plain.dudx + m11 * plain.dvdx;
  final dudy = m00 * plain.dudy + m01 * plain.dvdy;
  final dvdy = m10 * plain.dudy + m11 * plain.dvdy;
  return (
    u: m00 * v[kVUv] + m01 * v[kVUv + 1] + m02,
    v: m10 * v[kVUv] + m11 * v[kVUv + 1] + m12,
    footprint: (
      du: math.max(dudx.abs(), dudy.abs()),
      dv: math.max(dvdx.abs(), dvdy.abs()),
      dudx: dudx,
      dvdx: dvdx,
      dudy: dudy,
      dvdy: dvdy,
    ),
  );
}