From cbe0839cd6166981e3835cde6651e4cb46ba5c10 Mon Sep 17 00:00:00 2001 From: numzero Date: Tue, 18 Nov 2025 19:46:08 +0300 Subject: [PATCH] sort out units --- src/lib.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 09f5e5a..5195e03 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -244,26 +244,27 @@ impl Core { } let mut camera_ray_display: Vec = Vec::with_capacity(camera_rays.len()); let sigma2 = args.accum_sigma.powi(2); - let weight = (2. * PI * sigma2).sqrt().recip() * args.accum_scale; + let accum_normalizator = (2. * PI * sigma2).sqrt().recip(); for ray in camera_rays { let Some(hit) = scene.trace_ray(ray) else { continue; }; - let mut value = 0.0f32; + let mut total_cd = 0.0f32; for light_hit in &hits { let d2 = hit.incident.base.distance_squared(light_hit.incident.base); if d2 > 9. * sigma2 { continue; } assert!(hit.incident.dir.is_normalized()); - let radiance = hit.normal.dot(-hit.incident.dir); - let w = (-0.5 * d2 / sigma2).exp(); - value += w * radiance; + let in_lm = 1.0; + let out_cd = in_lm * hit.normal.dot(-hit.incident.dir) / PI; + let weight = accum_normalizator * (-0.5 * d2 / sigma2).exp(); + total_cd += weight * out_cd; } - value *= weight; - value = 3. * (1. - (1. + value).recip()); + let brightness = 3. * (1. - (1. + total_cd * args.accum_scale).recip()); let r = args.accum_sigma; - let color = vec3(value, value - 1., value - 2.).clamp(Vec3::splat(0.), Vec3::splat(1.)); + let color = vec3(brightness, brightness - 1., brightness - 2.) + .clamp(Vec3::splat(0.), Vec3::splat(1.)); let vertex = |off: Vec3| Vertex { pos: hit.incident.base + r * off, color,