b681e47458f04452d011b774219d978943a76da9
[MicroTrace.git] / ReflectiveEyeLightShader.cxx
1 #include "ReflectiveEyeLightShader.hxx"
2 #include "Primitive.hxx"
3 #include "Scene.hxx"
4
5 ReflectiveEyeLightShader::ReflectiveEyeLightShader(Scene* scene,
6 float reflectivity,
7 const Vec3f& color)
8 : EyeLightShader(scene,color),
9 m_reflectivity(reflectivity)
10 {
11 }
12
13 ReflectiveEyeLightShader::~ReflectiveEyeLightShader()
14 {
15 }
16
17 ReflectiveEyeLightShader::ReflectiveEyeLightShader()
18 : EyeLightShader(0),
19 m_reflectivity(0)
20 {
21 }
22
23 Vec3f
24 ReflectiveEyeLightShader::Shade(Ray& ray)
25 {
26 Vec3f eyeColor = EyeLightShader::Shade(ray);
27 Vec3f reflColor;
28
29 if(ray.recursionDepth() > 0) {
30 m_scene->Intersect(ray);
31 // intersection, - Epsilon to avoid numerical problems and getting the
32 // reflection on the object's inside ;-)
33 Vec3f i = ray.origin() + ray.direction() * (ray.t() - Epsilon);
34 Vec3f r = ray.direction();
35 Vec3f n = (ray.hit()->GetNormal(ray));
36
37 Ray sec(i, r + n * (2 * r.dot(n * -1)));
38 sec.setRecursionDepth(ray.recursionDepth() - 1);
39 reflColor = m_scene->RayTrace(sec);
40 }
41 return eyeColor + reflColor * m_reflectivity;
42 }
This page took 0.048365 seconds and 3 git commands to generate.