solution for 3.1a)
[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 N = ray.hit()->GetNormal(ray);
27
28 // diffuse color
29 Vec3f color = EyeLightShader::Shade(ray);
30
31 // add reflection
32 if(ray.recursionDepth() < RecursionDepth)
33 {
34 // generate reflected ray
35 // ray origin = hitpoint
36 Vec3f origin = ray.origin() + ray.direction()*ray.t();
37 Vec3f dir = ray.direction()-N*2*N.dot(ray.direction());
38 dir.normalize();
39
40 // spawn new ray
41 Ray reflection_ray(origin, dir, ray.recursionDepth()+1);
42 reflection_ray.setT(Infinity);
43
44 // trace reflection ray
45 Vec3f reflected_color = m_scene->RayTrace(reflection_ray);
46 color += reflected_color * m_reflectivity;
47 }
48
49 color.clamp();
50
51 return color;
52 }
This page took 0.044541 seconds and 5 git commands to generate.