1 #include "ReflectiveEyeLightShader.hxx"
2 #include "Primitive.hxx"
5 ReflectiveEyeLightShader::ReflectiveEyeLightShader(Scene
* scene
,
8 : EyeLightShader(scene
,color
),
9 m_reflectivity(reflectivity
)
13 ReflectiveEyeLightShader::~ReflectiveEyeLightShader()
17 ReflectiveEyeLightShader::ReflectiveEyeLightShader()
24 ReflectiveEyeLightShader::Shade(Ray
& ray
)
26 Vec3f N
= ray
.hit()->GetNormal(ray
);
27 // turn normal to front
28 if(N
.dot(ray
.direction()) > 0)
31 float cos_phi
= fabs(ray
.direction().dot(N
));
33 Vec3f color
= m_color
* cos_phi
;
35 if(ray
.recursionDepth() < RecursionDepth
)
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());
44 Ray
reflection_ray(origin
, dir
, ray
.recursionDepth()+1);
45 reflection_ray
.setT(Infinity
);
47 // trace reflection ray
48 Vec3f reflected_color
= m_scene
->RayTrace(reflection_ray
);
49 color
+= reflected_color
* m_reflectivity
;
This page took 0.046979 seconds and 5 git commands to generate.