#ifndef REFLECTIVEEYELIGHTSHADER_H #define REFLECTIVEEYELIGHTSHADER_H #include "Shader.hxx" class ReflectiveEyeLightShader : public Shader { public: Vec3f color; float reflectivity; ReflectiveEyeLightShader( Scene *scene, Vec3f color = Vec3f( 0.5, 0.5, 0.5 ), float reflectivity = 0.4 ) : Shader( scene ), color( color ), reflectivity( reflectivity ) { }; Vec3f Shade( Ray &ray) { /* diffuse term */ Vec3f normal = ray.hit->GetNormal(ray); Vec3f result = color * fabs(Dot(ray.dir, normal)); /* reflectice term */ if ( reflectivity > 0 ) { /* reflection ray */ Ray reflect; reflect.org = ray.org + ray.t * ray.dir; reflect.dir = ray.dir - 2 * Dot( normal, ray.dir ) * normal; reflect.hit = NULL; reflect.t = Infinity; result = result + reflectivity * scene->RayTrace( reflect ); } // get texture coordinates for(unsigned int i=0; i < getTextureCount(); i++) { // get texture color const Vec4f& tex = getTexture(i)->GetTexel(ray.hit->GetUV(ray)); // combine texture color with the computed result result = result * tex.xyz(); } return result; }; }; #endif