Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions crates/bevy_solari/src/pathtracer/pathtracer.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn importance_sample_next_bounce(wo: vec3<f32>, ray_hit: ResolvedRayHitFull, rng
if is_perfectly_specular {
return NextBounce(reflect(-wo, ray_hit.world_normal), 1.0, true);
}
let diffuse_weight = mix(mix(0.4f, 0.9f, ray_hit.material.perceptual_roughness), 0.f, ray_hit.material.metallic);
let diffuse_weight = mix(mix(0.4, 0.9, ray_hit.material.perceptual_roughness), 0.0, ray_hit.material.metallic);
let specular_weight = 1.0 - diffuse_weight;

let TBN = calculate_tbn_mikktspace(ray_hit.world_normal, ray_hit.world_tangent);
Expand Down Expand Up @@ -133,7 +133,7 @@ fn importance_sample_next_bounce(wo: vec3<f32>, ray_hit: ResolvedRayHitFull, rng
}

fn brdf_pdf(wo: vec3<f32>, wi: vec3<f32>, ray_hit: ResolvedRayHitFull) -> f32 {
let diffuse_weight = mix(mix(0.4f, 0.9f, ray_hit.material.roughness), 0.f, ray_hit.material.metallic);
let diffuse_weight = mix(mix(0.4, 0.9, ray_hit.material.roughness), 0.0, ray_hit.material.metallic);
let specular_weight = 1.0 - diffuse_weight;

let TBN = calculate_tbn_mikktspace(ray_hit.world_normal, ray_hit.world_tangent);
Expand Down
7 changes: 4 additions & 3 deletions crates/bevy_solari/src/realtime/gbuffer_utils.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ fn gpixel_resolve(gpixel: vec4<u32>, depth: f32, pixel_id: vec2<u32>, view_size:

let base_rough = unpack4x8unorm(gpixel.r);
let base_color = pow(base_rough.rgb, vec3(2.2));
let perceptual_roughness = base_rough.a;
let roughness = clamp(perceptual_roughness * perceptual_roughness, 0.001, 1.0);
// Clamp roughness to prevent NaNs
let perceptual_roughness = clamp(base_rough.a, 0.0316227766, 1.0);
let roughness = perceptual_roughness * perceptual_roughness;
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
5 changes: 4 additions & 1 deletion crates/bevy_solari/src/scene/raytracing_scene_bindings.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ fn resolve_material(material: Material, uv: vec2<f32>) -> ResolvedMaterial {
m.perceptual_roughness *= metallic_roughness.g;
m.metallic *= metallic_roughness.b;
}
m.roughness = clamp(m.perceptual_roughness * m.perceptual_roughness, 0.001, 1.0);

// Clamp roughness to prevent NaNs
m.perceptual_roughness = clamp(m.perceptual_roughness, 0.0316227766, 1.0);
m.roughness = m.perceptual_roughness * m.perceptual_roughness;

return m;
}
Expand Down