新的一年,前来打卡
Preface
回顾上一篇,我们讲述了漫反射材质,也就是平时的磨砂表面。
它一种将入射光经表面随机散射形成的材质,是一种非常普遍的表面形式。
这一篇,我们将来学习镜面反射,或者说是金属材质
镜面在生活中见得也很多,它是一种将入射光经表面按照物理反射规律形成的材质。
先看效果

Ready
之前我们就写好的
ray.h
intersect.h
intersection.h
sphere.h
camera.h
Chapter8: Metal
之前我们已经写过一个漫反射的材质,可以发现,材质其实就解决两个问题:
1.如何创造反射光或者散射光(吸收转化入射光)
2.如何确定光线强度的衰减量
我们采用类比法:
上一篇中
diffuse表面:1.视线与物体表面产生撞击点p,在p处相切单位圆内随机找一点s,散射光方向即p->s
2.我们上一篇采用的光线强度衰减机制是取半。
这一篇中我们将
metal表面: 1.根据物理反射定律确定入射光对应的反射光的方向
2.强度衰减改为三元组,分别对应rgb三分量的衰减度,且用参数自由确定
那么首先,它们有共同点,我们有必要将其抽象一下
/// material.h// ----------------------------------------------------- // [author] lv // [begin ] 2018.1.1 // [brief ] the material-class for the ray-tracing project // from the 《ray tracing in one week》 // ----------------------------------------------------- #ifndef MATERIAL_H #define MATERIAL_Hnamespace rt { //abstract basic classclass material { public: /* @brief: produce a scattered ray @param: InRay -> Incident light info -> the information of intersect-point(hit-point) attenuation -> when scattered, how much the ray should be attenuated by tis reflectance R scattered -> as we talk, it is a new sight; or it is the scattered ray with the intersect-point @retur: the function calculate a scattered ray or not */ virtual bool scatter(const ray& InRay, const hitInfo& info, rtvec& attenuation, ray& scattered)const = 0; protected: /* @brief: find a random point in unit_sphere */ const rtvec random_unit_sphere()const { rtvec p; do { p = 2.0*rtvec(rtrand01(), rtrand01(), rtrand01()) - rtvec(1, 1, 1); } while (dot(p, p) >= 1.0); return p; } }; } #endif
书上是这样的:

但是取单位圆随机点在两
50000+
5万行代码练就真实本领
17年
创办于2008年老牌培训机构
1000+
合作企业
98%
就业率

