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

Method hit

examples/cuda/gpu/path_tracer_gpu/src/sphere.rs:29–57  ·  view source on GitHub ↗
(&self, ray: Ray, t_min: f32, t_max: f32)

Source from the content-addressed store, hash-verified

27 }
28
29 fn hit(&self, ray: Ray, t_min: f32, t_max: f32) -> Option<HitRecord> {
30 let oc = ray.origin - self.center;
31 let a = ray.dir.dot(ray.dir);
32 let b = oc.dot(ray.dir);
33 let c = oc.dot(oc) - self.radius * self.radius;
34 let discriminant = b * b - a * c;
35
36 if discriminant > 0.0 {
37 let temp = (-b - discriminant.sqrt()) / a;
38 if temp < t_max && temp > t_min {
39 return Some(HitRecord {
40 t: temp,
41 point: ray.at(temp),
42 normal: (ray.at(temp) - self.center) / self.radius,
43 material_handle: self.mat,
44 });
45 }
46 let temp = (-b + discriminant.sqrt()) / a;
47 if temp < t_max && temp > t_min {
48 return Some(HitRecord {
49 t: temp,
50 point: ray.at(temp),
51 normal: (ray.at(temp) - self.center) / self.radius,
52 material_handle: self.mat,
53 });
54 }
55 }
56 None
57 }
58}

Callers

nothing calls this directly

Calls 3

sqrtMethod · 0.80
atMethod · 0.80
dotMethod · 0.45

Tested by

no test coverage detected