1. 环境光照
"Images rendered with only ambient illumiation show all surfaces with constant colors" 入射光线,环境光(Ambient Light)给那些有漫反射(diffuse-reflction)材质提供亮度(part of the reflected radiance). 环境光照射的所有面可以有不同的 反射颜色(c)和反射率(l)。反射光线方程如下
2.平行光
没有光源位置,同一方向的平行光线。p受光点的亮度可以表示如下:wi 是p点的立体角
3. 点光源
点光源是虚拟的没有表面积,所有的实际光源都是有表面积的。但是因为简洁的辉度表示,在实际中还是常使用。
implementation
1. 环境光
EnvironmentLight::EnvironmentLight(void)
: Light(),
sampler_ptr(NULL),
material_ptr(NULL),
u(), v(), w(),
wi()
{}
// --------------------------------------------------------------- get_direction
Vector3D
EnvironmentLight::get_direction(ShadeRec& sr) {
w = sr.normal;
v = Vector3D(0.0034, 1, 0.0071) ^ w;
v.normalize();
u = v ^ w;
Point3D sp = sampler_ptr->sample_hemisphere();
wi = sp.x * u + sp.y * v + sp.z * w;
return (wi);
}
// --------------------------------------------------------------- L
RGBColor
EnvironmentLight::L(ShadeRec& sr) {
return (material_ptr->get_Le(sr));
}
// ---------------------------------------------------------------- pdf
// The following function is not in the book.
// It uses Equation 18.6
float
EnvironmentLight::pdf(const ShadeRec& sr) const {
return (sr.normal * wi * invPI);
}
2. 平行光
// ---------------------------------------------------------------------- get_direction
// as this function is virtual, it shouldn't be inlined
Vector3D
Directional::get_direction(ShadeRec& sr) {
return (dir);
}
// ------------------------------------------------------------------------------ L
RGBColor
Directional::L(ShadeRec& s) {
return (ls * color);
}
3.点光源
// ---------------------------------------------------------------------- get_direction
Vector3D
PointLight::get_direction(ShadeRec& sr) {
return ((location - sr.hit_point).hat());
}
// ---------------------------------------------------------------------- L
RGBColor
PointLight::L(ShadeRec& sr) {
return (ls * color);
}