blueNoise function

double blueNoise(
  1. ShaderBindings b,
  2. double x,
  3. double y
)

BlueNoise from lib/blue_noise.glsl — R3: this frame's slice of the engine's blue noise at the pixel (x, y), in [0, 1).

Implementation

double blueNoise(ShaderBindings b, double x, double y) {
  final table = b.textures['blue_noise_texture'];
  if (table == null) return bayerCell(x, y);
  final slice = b.vec4('NoiseInfo', 'noise', Vector4.zero()).y;
  final cellX = x.floorToDouble() % 64.0;
  final cellY = y.floorToDouble() % 64.0;
  final cornerX = (slice % 8.0).floorToDouble() * 64.0;
  final cornerY = (slice / 8.0).floorToDouble() * 64.0;
  final texel = table.sample(
    (cornerX + cellX + 0.5) / 512.0,
    (cornerY + cellY + 0.5) / 256.0,
  );
  return texel.x * (255.0 / 256.0);
}