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