mapUv function

MappedUv 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

MappedUv 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 MappedUv(u: v[kVUv], v: v[kVUv + 1], footprint: plain);
  }
  final o = slot * 8;
  final m00 = rows[o], m01 = rows[o + 1], m02 = rows[o + 2];
  final m10 = rows[o + 4], m11 = rows[o + 5], m12 = 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 MappedUv(
    u: m00 * v[kVUv] + m01 * v[kVUv + 1] + m02,
    v: m10 * v[kVUv] + m11 * v[kVUv + 1] + m12,
    footprint: UvFootprint(
      du: math.max(dudx.abs(), dudy.abs()),
      dv: math.max(dvdx.abs(), dvdy.abs()),
      dudx: dudx,
      dvdx: dvdx,
      dudy: dudy,
      dvdy: dvdy,
    ),
  );
}