aboutsummaryrefslogtreecommitdiff
path: root/src/trace/mod.rs
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2021-02-03 17:54:03 +0100
committerJulian T <julian@jtle.dk>2021-02-03 17:54:03 +0100
commit9235e74dfbc41895a5f8807e1ab93508268a39ea (patch)
treeb8e85390b9e131736016dd2589d5e6ea14013552 /src/trace/mod.rs
parent977b0e4152433b2a68e2b97fe5fe2c0ff6fb20d8 (diff)
Base render of surface normal, and abstract shading and tracing to the
trace module
Diffstat (limited to 'src/trace/mod.rs')
-rw-r--r--src/trace/mod.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/trace/mod.rs b/src/trace/mod.rs
new file mode 100644
index 0000000..90f12da
--- /dev/null
+++ b/src/trace/mod.rs
@@ -0,0 +1,30 @@
+use crate::scene::Scene;
+use crate::core::{Spectrum, Ray, Vector3f};
+
+/// Simple surface normal tracer
+///
+/// This ray tracer bases color values on the hit surface normals
+pub struct NormTracer {}
+
+/// Alias for chosen trace implementation.
+///
+/// This is swiched at compile time to save alot of time.
+pub type Tracer = NormTracer;
+
+impl NormTracer {
+ pub fn new() -> NormTracer {
+ NormTracer {}
+ }
+
+ pub fn trace(&self, scn: &Scene, ray: &Ray) -> Spectrum {
+ // Trace ray
+ if let Some(i) = scn.intersect(ray) {
+ let p = ray.at(i.t);
+ let norm = i.shp.norm_at(&p) * 0.5 + Vector3f::new(0.5);
+
+ return Spectrum::new_rgb(norm.x, norm.y, norm.z);
+ }
+
+ Spectrum::new_rgb(0.0, 0.0, 0.0)
+ }
+}