still broken ReflectiveEyeLightShader, saving it for later
[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 // get normal and turn towards ray if angle > 90°
30 Vec3f n = ray.hit()->GetNormal(ray);
31 float cos_theta = n.dot(ray.direction());
32 // we just need the sign, no value
33 if( cos_theta > 0 ) {
34 std::cout << "cos_theta="<<cos_theta <<", flipping normal" <<std::endl;
35 n = n * -1;
36 }
37
38 // shoot secondary rays from intersection
39 Ray sec(ray.origin() + ray.direction() * (ray.t() - Epsilon),
40 ray.direction() + n * 2);
41 sec.setRecursionDepth(ray.recursionDepth() - 1);
42
43 if(sec.recursionDepth() + 1 > 0) {
44 reflColor = m_scene->RayTrace(sec);
45 //reflColor = Shade(sec);
46 }
47 return eyeColor + (reflColor * m_reflectivity);
48 }
This page took 0.051807 seconds and 5 git commands to generate.