【Ray Tracing from Ground Up】光源(Lights)

来源:互联网 发布:淘宝买家号权重是什么 编辑:程序博客网 时间:2024/05/20 18:54

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_directionVector3DEnvironmentLight::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);}// --------------------------------------------------------------- LRGBColorEnvironmentLight::L(ShadeRec& sr) {return (material_ptr->get_Le(sr));}// ---------------------------------------------------------------- pdf// The following function is not in the book.// It uses Equation 18.6floatEnvironmentLight::pdf(const ShadeRec& sr) const {return (sr.normal * wi * invPI);}


2. 平行光

// ---------------------------------------------------------------------- get_direction// as this function is virtual, it shouldn't be inlined Vector3DDirectional::get_direction(ShadeRec& sr) {return (dir);}// ------------------------------------------------------------------------------  LRGBColorDirectional::L(ShadeRec& s) {return (ls * color);}


3.点光源

// ---------------------------------------------------------------------- get_directionVector3DPointLight::get_direction(ShadeRec& sr) {return ((location - sr.hit_point).hat());}// ---------------------------------------------------------------------- LRGBColorPointLight::L(ShadeRec& sr) {return (ls * color);}



0 0