split light calculations and camera rays

This commit is contained in:
numzero 2025-11-24 18:21:31 +03:00
parent 295037edc6
commit 722e5d4b6e

View File

@ -346,16 +346,13 @@ impl Core {
hits1 = hits2; hits1 = hits2;
} }
} }
let mut camera_ray_display: Vec<Vertex> = Vec::with_capacity(camera_rays.len()); let light_at = {
if args.show_light {
let sigma2 = args.accum_sigma.powi(2); let sigma2 = args.accum_sigma.powi(2);
let accum_normalizator = (2. * PI * sigma2).sqrt().recip(); let accum_normalizator = (2. * PI * sigma2).sqrt().recip();
for ray in camera_rays { let hits = &hits;
let Some(hit) = scene.trace_ray(ray) else { move |hit: Hit| -> f32 {
continue;
};
let mut total_cd = 0.0f32; let mut total_cd = 0.0f32;
for light_hit in &hits { for light_hit in hits {
let d2 = hit.incident.base.distance_squared(light_hit.incident.base); let d2 = hit.incident.base.distance_squared(light_hit.incident.base);
if d2 > 9. * sigma2 { if d2 > 9. * sigma2 {
continue; continue;
@ -368,11 +365,22 @@ impl Core {
assert!(hit.incident.dir.is_normalized()); assert!(hit.incident.dir.is_normalized());
let reflector = Lambertian; let reflector = Lambertian;
let in_lm = 1.0; let in_lm = 1.0;
let out_cd = in_lm * reflector.brdf(normal, light_hit.incident.dir, -ray.dir); let out_cd =
in_lm * reflector.brdf(normal, light_hit.incident.dir, -hit.incident.dir);
let weight = accum_normalizator * (-0.5 * d2 / sigma2).exp(); let weight = accum_normalizator * (-0.5 * d2 / sigma2).exp();
total_cd += weight * out_cd; total_cd += weight * out_cd;
} }
let brightness = 3. * (1. - (1. + total_cd * args.accum_scale).recip()); total_cd * args.accum_scale
}
};
let mut camera_ray_display: Vec<Vertex> = Vec::with_capacity(camera_rays.len());
if args.show_light {
for ray in camera_rays {
let Some(hit) = scene.trace_ray(ray) else {
continue;
};
let light = light_at(hit);
let brightness = 3. * (1. - (1. + light).recip());
let r = args.accum_sigma; let r = args.accum_sigma;
let color = vec3(brightness, brightness - 1., brightness - 2.) let color = vec3(brightness, brightness - 1., brightness - 2.)
.clamp(Vec3::splat(0.), Vec3::splat(1.)); .clamp(Vec3::splat(0.), Vec3::splat(1.));