From: Roland Hieber Date: Wed, 20 Jan 2010 11:30:51 +0000 (+0100) Subject: still broken reflective eyelight shader, solution for assignment 2.2b X-Git-Url: https://git.rohieb.name/MicroTrace.git/commitdiff_plain/c8f239369af4af00ca31c2a3f1901f0537f4d2de?ds=sidebyside still broken reflective eyelight shader, solution for assignment 2.2b --- diff --git a/Ray.cxx b/Ray.cxx index 86b1294..a3c76cb 100644 --- a/Ray.cxx +++ b/Ray.cxx @@ -5,7 +5,8 @@ Ray::Ray() : m_org(Vec3f()), m_dir(Vec3f()), - m_hit(0) + m_hit(0), + m_level(10) { m_t = std::numeric_limits::max(); } @@ -14,7 +15,8 @@ Ray::Ray(const Vec3f& org, const Vec3f& dir) : m_org(org), m_dir(dir), - m_hit(0) + m_hit(0), + m_level(10) { m_t = std::numeric_limits::max(); } @@ -29,6 +31,7 @@ Ray::Ray(const Ray& r) m_dir = r.m_dir; m_t = r.m_t; m_hit = r.m_hit; + m_level = r.m_level; } Ray& diff --git a/ReflectiveEyeLightShader.cxx b/ReflectiveEyeLightShader.cxx index 2bd0db3..e7fa2ac 100644 --- a/ReflectiveEyeLightShader.cxx +++ b/ReflectiveEyeLightShader.cxx @@ -1,4 +1,6 @@ #include "ReflectiveEyeLightShader.hxx" +#include "Primitive.hxx" +#include "Scene.hxx" ReflectiveEyeLightShader::ReflectiveEyeLightShader(Scene* scene, float reflectivity, @@ -21,5 +23,16 @@ ReflectiveEyeLightShader::ReflectiveEyeLightShader() Vec3f ReflectiveEyeLightShader::Shade(Ray& ray) { - return Vec3f(); + Vec3f eyeColor = EyeLightShader::Shade(ray); + Vec3f reflColor; + + // shoot secondary rays from intersection + Vec3f n = ray.hit()->GetNormal(ray); + Ray sec(ray.origin() + ray.direction() * ray.t(), ray.direction() + n * 2); + sec.setRecursionDepth(ray.recursionDepth() - 1); + + if(ray.recursionDepth() > 0 && m_scene->Intersect(sec)) { + reflColor = Shade(sec); + } + return eyeColor + reflColor; }