diff --git a/crates/bevy_solari/src/pathtracer/pathtracer.wgsl b/crates/bevy_solari/src/pathtracer/pathtracer.wgsl index 68cb45e207ffb..77fc834b2f5a5 100644 --- a/crates/bevy_solari/src/pathtracer/pathtracer.wgsl +++ b/crates/bevy_solari/src/pathtracer/pathtracer.wgsl @@ -104,7 +104,7 @@ fn importance_sample_next_bounce(wo: vec3, 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); @@ -133,7 +133,7 @@ fn importance_sample_next_bounce(wo: vec3, ray_hit: ResolvedRayHitFull, rng } fn brdf_pdf(wo: vec3, wi: vec3, 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); diff --git a/crates/bevy_solari/src/realtime/gbuffer_utils.wgsl b/crates/bevy_solari/src/realtime/gbuffer_utils.wgsl index a9d513f77e8e1..baf1556806b6e 100644 --- a/crates/bevy_solari/src/realtime/gbuffer_utils.wgsl +++ b/crates/bevy_solari/src/realtime/gbuffer_utils.wgsl @@ -18,11 +18,12 @@ fn gpixel_resolve(gpixel: vec4, depth: f32, pixel_id: vec2, 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); // Clamp roughness to 0.001 + 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 let emissive = rgb9e5_to_vec3_(gpixel.g); let material = ResolvedMaterial(base_color, emissive, reflectance, perceptual_roughness, roughness, metallic); diff --git a/crates/bevy_solari/src/realtime/restir_gi.wgsl b/crates/bevy_solari/src/realtime/restir_gi.wgsl index 4fcf537a496b4..7d3a60ac9e6d3 100644 --- a/crates/bevy_solari/src/realtime/restir_gi.wgsl +++ b/crates/bevy_solari/src/realtime/restir_gi.wgsl @@ -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); } diff --git a/crates/bevy_solari/src/scene/raytracing_scene_bindings.wgsl b/crates/bevy_solari/src/scene/raytracing_scene_bindings.wgsl index 9e346bbf2d783..8b1e875fc5423 100644 --- a/crates/bevy_solari/src/scene/raytracing_scene_bindings.wgsl +++ b/crates/bevy_solari/src/scene/raytracing_scene_bindings.wgsl @@ -142,7 +142,10 @@ fn resolve_material(material: Material, uv: vec2) -> 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); // Clamp roughness to 0.001 + m.roughness = m.perceptual_roughness * m.perceptual_roughness; return m; }