Skip to content

Commit 64a15f1

Browse files
Fix ssao only sampling mip 0 (#11292)
# Objective Fixes #11222 ## Solution SSAO's sample_mip_level was always giving negative values because it was in UV space (0..1) when it needed to be in pixel units (0..resolution). Fixing it so it properly samples lower mip levels when appropriate is a pretty large speedup (~3.2ms -> ~1ms at 4k, ~507us-> 256us at 1080p on a 6800xt), and I didn't notice any obvious visual quality differences. --------- Co-authored-by: Alice Cecile <[email protected]>
1 parent ce5bae5 commit 64a15f1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

crates/bevy_pbr/src/ssao/gtao.wgsl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ fn gtao(@builtin(global_invocation_id) global_id: vec3<u32>) {
139139
s *= s; // https://github.com/GameTechDev/XeGTAO#sample-distribution
140140
let sample = s * sample_mul;
141141

142-
let sample_mip_level = clamp(log2(length(sample)) - 3.3, 0.0, 5.0); // https://github.com/GameTechDev/XeGTAO#memory-bandwidth-bottleneck
142+
// * view.viewport.zw gets us from [0, 1] to [0, viewport_size], which is needed for this to get the correct mip levels
143+
let sample_mip_level = clamp(log2(length(sample * view.viewport.zw)) - 3.3, 0.0, 5.0); // https://github.com/GameTechDev/XeGTAO#memory-bandwidth-bottleneck
143144
let sample_position_1 = load_and_reconstruct_view_space_position(uv + sample, sample_mip_level);
144145
let sample_position_2 = load_and_reconstruct_view_space_position(uv - sample, sample_mip_level);
145146

0 commit comments

Comments
 (0)