Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/bevy_solari/src/realtime/gbuffer_utils.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn gpixel_resolve(gpixel: vec4<u32>, depth: f32, pixel_id: vec2<u32>, view_size:
let roughness = clamp(perceptual_roughness * perceptual_roughness, 0.001, 1.0);
let props = unpack4x8unorm(gpixel.b);
let reflectance = vec3(props.r);
let metallic = props.g;
let metallic = saturate(props.g); // TODO: Not sure why saturate is needed here to prevent NaNs
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be something wrong with our gbuffer encoding? @DGriffin91

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like any bit pattern of gpixel.b should be valid in respect to metallic. It seems sus if unpack4x8unorm is returning something that's not 0.0..=1.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah idk

let emissive = rgb9e5_to_vec3_(gpixel.g);
let material = ResolvedMaterial(base_color, emissive, reflectance, perceptual_roughness, roughness, metallic);

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_solari/src/realtime/restir_gi.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ fn merge_reservoirs(
);

// Don't merge samples with huge jacobians, as it explodes the variance
if canonical_target_function_other_sample_jacobian > 2.0 {
if canonical_target_function_other_sample_jacobian > 1.2 {
return ReservoirMergeResult(canonical_reservoir, canonical_sample_radiance);
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_solari/src/realtime/specular_gi.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn specular_gi(@builtin(global_invocation_id) global_id: vec3<u32>) {
}

let brdf = evaluate_specular_brdf(surface.world_normal, wo, wi, surface.material.base_color, surface.material.metallic,
surface.material.reflectance, surface.material.perceptual_roughness, surface.material.roughness);
surface.material.reflectance, surface.material.perceptual_roughness);
let cos_theta = saturate(dot(wi, surface.world_normal));
radiance *= brdf * cos_theta * view.exposure;

Expand Down
8 changes: 5 additions & 3 deletions crates/bevy_solari/src/scene/brdf.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ fn evaluate_brdf(
material.metallic,
material.reflectance,
material.perceptual_roughness,
material.roughness,
);
return diffuse_brdf + specular_brdf;
}
Expand All @@ -38,16 +37,19 @@ fn evaluate_specular_brdf(
metallic: f32,
reflectance: vec3<f32>,
perceptual_roughness: f32,
roughness: f32,
) -> vec3<f32> {
// Clamp roughness to prevent NaNs
let perceptual_roughness_clamped = clamp(perceptual_roughness, 0.0316227766, 1.0);
let roughness = perceptual_roughness_clamped * perceptual_roughness_clamped;

let H = normalize(L + V);
let NdotL = saturate(dot(N, L));
let NdotH = saturate(dot(N, H));
let LdotH = saturate(dot(L, H));
let NdotV = max(dot(N, V), 0.0001);

let F0 = calculate_F0(base_color, metallic, reflectance);
let F_ab = F_AB(perceptual_roughness, NdotV);
let F_ab = F_AB(perceptual_roughness_clamped, NdotV);

let D = D_GGX(roughness, NdotH);
let Vs = V_SmithGGXCorrelated(roughness, NdotV, NdotL);
Expand Down