paraboloid_mip.wgsl 1.5 KB

12345678910111213141516171819202122232425262728
  1. // Compute Mip-Chain Generator for Dual Paraboloid Rgba16Float hemispheres.
  2. // Downsamples mip N -> mip N+1 with a 9-tap tent filter so rough surfaces sample soft reflections.
  3. @group(0) @binding(0) var src_tex: texture_2d<f32>;
  4. @group(0) @binding(1) var src_samp: sampler;
  5. @group(0) @binding(2) var dst_tex: texture_storage_2d<rgba16float, write>;
  6. @compute @workgroup_size(8, 8, 1)
  7. fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
  8. let dst_dims = textureDimensions(dst_tex);
  9. if (gid.x >= dst_dims.x || gid.y >= dst_dims.y) {
  10. return;
  11. }
  12. let uv = (vec2<f32>(gid.xy) + 0.5) / vec2<f32>(dst_dims);
  13. let step = 1.25 / vec2<f32>(dst_dims);
  14. var acc = textureSampleLevel(src_tex, src_samp, uv, 0.0) * 4.0;
  15. acc += textureSampleLevel(src_tex, src_samp, uv + vec2<f32>(-step.x, 0.0), 0.0) * 2.0;
  16. acc += textureSampleLevel(src_tex, src_samp, uv + vec2<f32>( step.x, 0.0), 0.0) * 2.0;
  17. acc += textureSampleLevel(src_tex, src_samp, uv + vec2<f32>(0.0, -step.y), 0.0) * 2.0;
  18. acc += textureSampleLevel(src_tex, src_samp, uv + vec2<f32>(0.0, step.y), 0.0) * 2.0;
  19. acc += textureSampleLevel(src_tex, src_samp, uv + vec2<f32>(-step.x, -step.y), 0.0);
  20. acc += textureSampleLevel(src_tex, src_samp, uv + vec2<f32>( step.x, -step.y), 0.0);
  21. acc += textureSampleLevel(src_tex, src_samp, uv + vec2<f32>(-step.x, step.y), 0.0);
  22. acc += textureSampleLevel(src_tex, src_samp, uv + vec2<f32>( step.x, step.y), 0.0);
  23. textureStore(dst_tex, vec2<i32>(gid.xy), acc / 16.0);
  24. }