oxihuman_viewer/
gi_debug_view.rs1#![allow(dead_code)]
4
5pub struct GiDebugView {
6 pub show_irradiance: bool,
7 pub show_radiance: bool,
8 pub show_probes: bool,
9 pub exposure: f32,
10}
11
12pub fn new_gi_debug_view() -> GiDebugView {
13 GiDebugView {
14 show_irradiance: true,
15 show_radiance: false,
16 show_probes: false,
17 exposure: 1.0,
18 }
19}
20
21pub fn gi_irradiance_color(irradiance: [f32; 3], exposure: f32) -> [f32; 3] {
22 [
23 (irradiance[0] * exposure).clamp(0.0, 1.0),
24 (irradiance[1] * exposure).clamp(0.0, 1.0),
25 (irradiance[2] * exposure).clamp(0.0, 1.0),
26 ]
27}
28
29pub fn gi_probe_color(probe_weight: f32) -> [f32; 3] {
30 let w = probe_weight.clamp(0.0, 1.0);
31 [w, w * 0.5, 1.0 - w]
32}
33
34pub fn gi_radiance_to_ldr(radiance: [f32; 3], exposure: f32) -> [f32; 3] {
35 [
37 (radiance[0] * exposure) / (1.0 + radiance[0] * exposure),
38 (radiance[1] * exposure) / (1.0 + radiance[1] * exposure),
39 (radiance[2] * exposure) / (1.0 + radiance[2] * exposure),
40 ]
41}
42
43pub fn gi_is_converged(variance: f32, threshold: f32) -> bool {
44 variance < threshold
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_new_gi_debug_view() {
53 let v = new_gi_debug_view();
55 assert!((v.exposure - 1.0).abs() < 1e-6);
56 }
57
58 #[test]
59 fn test_gi_irradiance_color() {
60 let c = gi_irradiance_color([2.0, 0.5, 0.1], 1.0);
62 assert!((c[0] - 1.0).abs() < 1e-6);
63 }
64
65 #[test]
66 fn test_gi_probe_color() {
67 let c = gi_probe_color(0.0);
69 assert!((c[2] - 1.0).abs() < 1e-6);
70 }
71
72 #[test]
73 fn test_gi_radiance_to_ldr() {
74 let c = gi_radiance_to_ldr([100.0, 0.0, 0.0], 1.0);
76 assert!(c[0] < 1.0 && c[0] > 0.9);
77 }
78
79 #[test]
80 fn test_gi_is_converged() {
81 assert!(gi_is_converged(0.001, 0.01));
82 assert!(!gi_is_converged(0.1, 0.01));
83 }
84}