Skip to content

Commit

Permalink
Fix ssao only sampling mip 0 (#11292)
Browse files Browse the repository at this point in the history
# 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]>
  • Loading branch information
Elabajaba and alice-i-cecile authored Jan 12, 2024
1 parent ce5bae5 commit 64a15f1
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crates/bevy_pbr/src/ssao/gtao.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ fn gtao(@builtin(global_invocation_id) global_id: vec3<u32>) {
s *= s; // https://github.com/GameTechDev/XeGTAO#sample-distribution
let sample = s * sample_mul;

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

Expand Down

0 comments on commit 64a15f1

Please sign in to comment.