webgpu-pt

monte carlo path tracer
Contents

utils.wgsl

890 B
 1fn is_nan(x: f32) -> bool {
 2    return x != x;
 3}
 4
 5fn is_inf(x: f32) -> bool {
 6    return abs(x) > 1e20;
 7}
 8
 9fn is_nan3(v: vec3<f32>) -> bool {
10    return is_nan(v.x) || is_nan(v.y) || is_nan(v.z);
11}
12
13fn is_inf3(v: vec3<f32>) -> bool {
14    return abs(v.x) > 1e20 || abs(v.y) > 1e20 || abs(v.z) > 1e20;
15}
16
17fn luminance(color: vec3<f32>) -> f32 {
18    return dot(color, vec3<f32>(0.2126, 0.7152, 0.0722));
19}
20
21fn float_to_int(f: f32) -> i32 {
22    return bitcast<i32>(f);
23}
24
25fn int_to_float(i: i32) -> f32 {
26    return bitcast<f32>(i);
27}
28
29fn srgb_to_linear(rgb: vec3<f32>) -> vec3<f32> {
30    return select(pow((rgb + 0.055) * (1.0 / 1.055), vec3<f32>(2.4)), rgb * (1.0 / 12.92), rgb <= vec3<f32>(0.04045));
31}
32
33fn clamp_hdr(color: vec3<f32>, max_luminance: f32) -> vec3<f32> {
34    let lum = dot(color, vec3f(0.2126, 0.7152, 0.0722));
35    return color * min(1.0, max_luminance / max(lum, 1e-6));
36}
37