X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/0e3446ceb6fd6db0cb292671f37b46daaa2aed5b..556bb9d82b766ce68c56844492536525dc2d19d7:/ReflectiveEyeLightShader.cxx diff --git a/ReflectiveEyeLightShader.cxx b/ReflectiveEyeLightShader.cxx index 2bd0db3..59f9444 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,33 @@ ReflectiveEyeLightShader::ReflectiveEyeLightShader() Vec3f ReflectiveEyeLightShader::Shade(Ray& ray) { - return Vec3f(); + Vec3f N = ray.hit()->GetNormal(ray); + // turn normal to front + if(N.dot(ray.direction()) > 0) + N *= -1; + + float cos_phi = fabs(ray.direction().dot(N)); + + Vec3f color = m_color * cos_phi; + + if(ray.recursionDepth() < RecursionDepth) + { + // generate reflected ray + // ray origin = hitpoint + Vec3f origin = ray.origin() + ray.direction()*ray.t(); + Vec3f dir = ray.direction()-N*2*N.dot(ray.direction()); + dir.normalize(); + + // spawn new ray + Ray reflection_ray(origin, dir, ray.recursionDepth()+1); + reflection_ray.setT(Infinity); + + // trace reflection ray + Vec3f reflected_color = m_scene->RayTrace(reflection_ray); + color += reflected_color * m_reflectivity; + } + + color.clamp(); + + return color; }