X-Git-Url: https://git.rohieb.name/MicroTrace.git/blobdiff_plain/9fa235f6c621a9737be66359dc6bed473f1823d9..3396a44710415bde9509afeb02f3ec10a22c6661:/PhongShader.cxx diff --git a/PhongShader.cxx b/PhongShader.cxx index 67363a6..c44966e 100644 --- a/PhongShader.cxx +++ b/PhongShader.cxx @@ -34,16 +34,16 @@ PhongShader::Shade(Ray& ray) { // surface normal at hit point of object Vec3f normal = ray.hit()->GetNormal(ray); - // turn to fron if angle < 90° + // turn to front if angle > 90° if(normal.dot(ray.direction()) < 0) { normal = normal * -1; } // direction of reflection - Vec3f refl_dir = ray.direction() - normal * 2 * (normal % ray.direction()); + Vec3f refl_dir = ray.direction() - normal * 2 * normal.dot(ray.direction()); refl_dir.normalize(); - // ambient color term - radiance is 1 since we have point light - Vec3f amb_color = m_ambient_color * m_ka * 1.0f; + // ambient color term + Vec3f amb_color = m_ambient_color * m_ka; Vec3f intensity, light_dir; @@ -55,10 +55,11 @@ PhongShader::Shade(Ray& ray) Ray light_ray; (*it)->Illuminate(light_ray, intensity); diff_sum += intensity * light_ray.direction().dot(normal); - spec_sum += intensity * light_ray.direction().dot(refl_dir); + Vec3f view_dir = ray.direction()*-1; // direction from hitpoint to viewer + spec_sum += intensity * pow(fmax(view_dir.dot(refl_dir),0), m_ke); } Vec3f diff_color = m_diffuse_color * m_kd * diff_sum; Vec3f spec_color = m_specular_color * m_ks * spec_sum; - return amb_color + diff_color + spec_sum; + return amb_color + diff_color + spec_color; }