当前位置:首页 » 操作系统 » 去光照算法

去光照算法

发布时间: 2023-09-24 04:40:41

① 计算机图形学, 光线跟踪算法的过程是什么

光线跟踪思路:从视点出发,通过图像平面上每个像素中心向场景发出一条光线,光线的起点为视点,方向为像素中心和视点连线单位向量。光线与离视点最近的场景物体表面交点有三种可能:
当前交点所在的物体表面为理想漫射面,跟踪结束。
当前交点所在的物体表面为理想镜面,光线沿其镜面发射方向继续跟踪。
当前交点所在的物体表面为规则透射面,光线沿其规则透射方向继续跟踪。

伪代码:

void TraceRay(const Vec3& start, const Vec3& direction, int depth, Color& color)
{
Vec3 intersectionPoint, reflectedDirection, transmittedDirection;
Color localColor, reflectedColor, transmittedColor;
if (depth >= MAX_DEPTH) {
color = Black; //#000
}
else {
Ray ray(start, direction); //取start起点,方向direction为跟踪射线;
if ( !scene->HasIntersection(ray) )
color = BackgroundColor;
else {
计算理起始点start最近的交点intersectionPoint,
记录相交物体intersectionObject,

// #1
Shade(intersectionObject, intersectionPoint, localColor);

// #2
if ( intersectionPoint所在面为镜面 ) {
计算跟踪光想S在intersectionPoint处的反射光线方向reflectedDirection,
TraceRay(intersectionPoint, reflectedDirection, depth+1, reflectedColor);
}
// #3
if ( intersectionPoint所在的表面为透明面 ) {
计算跟踪光线S在intersectionPoint处的规则透射光线方向transmittedDirection,
TraceRay(intersectionPoint, transmittedDirection, depth+1, transmittedColor);
}
// #summarize
color = localColor + Ks * reflectedColor + Kt * transmittedColor;
}// else
} //else
}
// 局部光照模型计算交点intersectionPoint处的局部光亮度localColor
void Shade(const Object& intersectionObj, const Vec3& intersectionPoint, Color& localColor)
{
确定intersectionObj在intersectionPoint处的单位法向量N,
漫反射系数Kd,
镜面反射系数Ks,
环境反射系数Ka;
localColor = Ka * Ia; //Ia为环境光亮度
for ( 每一个点光源PointLight ) {
计算入射光线单位向量L和虚拟镜面法向单位向量H,
// 由Phong模型计算光源PointLight在intersectionPoint处的漫反射和镜面反射光亮度
localColor += ( Ipointlight * ( Kd * (N.dot(L)) + Ks * (N.dot(H))^n ) );
}
}

热点内容
ftp服务器被动模式配置 发布:2025-07-04 05:17:32 浏览:331
电动车小龟有哪些配置 发布:2025-07-04 05:16:18 浏览:39
mysql同步存储过程 发布:2025-07-04 05:14:32 浏览:662
安卓手机如何控制空调 发布:2025-07-04 05:09:06 浏览:154
新洁尔灭用于物体表面怎么配置 发布:2025-07-04 05:03:28 浏览:829
生活中的云服务器 发布:2025-07-04 05:01:55 浏览:744
三星g6700c原始密码是多少 发布:2025-07-04 04:49:41 浏览:726
网页编程代码 发布:2025-07-04 04:47:25 浏览:805
发消息时用到什么密码 发布:2025-07-04 04:41:47 浏览:980
3个密码箱能装多少钱 发布:2025-07-04 04:39:36 浏览:11