Vec3f PhongMaterial::Shade(const Ray& ray, const Hit& hit, const Vec3f& dirToLight, const Vec3f& lightColor) const { Vec3f v = ray.getDirection() * -1.0f; Vec3f n = hit.getNormal(); // Vec3f h = dirToLight + ray.getDirection() * -1.0f; // h.Normalize(); float diffuse = dirToLight.Dot3(n); Vec3f r = n * 2.0 * n.Dot3(dirToLight) - dirToLight; float specular = v.Dot3(r); if (diffuse < 0.0f) diffuse = 0.0f; if (specular < 0.0f) specular = 0.0f; Vec3f color = this->getDiffuseColor(); color = color * diffuse + m_specularColor * pow(specular, m_exponent); color.Scale(lightColor); return color; }
Ray OrthographicCamera::generateRay(const Vec2f & point) { assert (point[0] >= 0.0f && point[0] <= 1.0f); assert (point[1] >= 0.0f && point[1] <= 1.0f); float hScale = size * (point.x() - 0.5f), uScale = size * (point.y() - 0.5); Vec3f h = horizontal, u = up; h.Normalize(); u.Normalize(); h.Scale(uScale, uScale, uScale); u.Scale(hScale, hScale, hScale); Vec3f origin = center + h + u; Ray r(direction, origin); return r; }