CalcBounds for other Primitives... ;-)
[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 // turn normal to front
28 if(N.dot(ray.direction()) > 0)
29 N *= -1;
30
31 float cos_phi = fabs(ray.direction().dot(N));
32
33 Vec3f color = m_color * cos_phi;
34
35 if(ray.recursionDepth() < RecursionDepth)
36 {
37 // generate reflected ray
38 // ray origin = hitpoint
39 Vec3f origin = ray.origin() + ray.direction()*ray.t();
40 Vec3f dir = ray.direction()-N*2*N.dot(ray.direction());
41 dir.normalize();
42
43 // spawn new ray
44 Ray reflection_ray(origin, dir, ray.recursionDepth()+1);
45 reflection_ray.setT(Infinity);
46
47 // trace reflection ray
48 Vec3f reflected_color = m_scene->RayTrace(reflection_ray);
49 color += reflected_color * m_reflectivity;
50 }
51
52 color.clamp();
53
54 return color;
55 }
This page took 0.048282 seconds and 5 git commands to generate.