MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / refract

Function refract

examples/cuda/gpu/path_tracer_gpu/src/math.rs:38–47  ·  view source on GitHub ↗
(v: Vec3, n: Vec3, ni_over_nt: f32)

Source from the content-addressed store, hash-verified

36}
37
38pub fn refract(v: Vec3, n: Vec3, ni_over_nt: f32) -> Option<Vec3> {
39 let uv = v.normalized();
40 let dt = uv.dot(n);
41 let discriminant = 1.0 - ni_over_nt * ni_over_nt * (1.0 - dt * dt);
42 if discriminant > 0.0 {
43 Some(ni_over_nt * (uv - n * dt) - discriminant.sqrt() * n)
44 } else {
45 None
46 }
47}
48
49pub fn schlick(cos: f32, ref_idx: f32) -> f32 {
50 let r0 = (1.0 - ref_idx) / (1.0 + ref_idx);

Callers 1

scatterMethod · 0.85

Calls 2

sqrtMethod · 0.80
dotMethod · 0.45

Tested by

no test coverage detected