當前位置:首頁 » 操作系統 » 去光照演算法

去光照演算法

發布時間: 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 ) );
}
}

熱點內容
為什麼安卓介面充電線松 發布:2025-05-12 03:41:20 瀏覽:669
安卓手機打擊墊怎麼玩 發布:2025-05-12 03:23:14 瀏覽:241
phpexplode 發布:2025-05-12 03:15:33 瀏覽:73
雙色球怎麼演算法 發布:2025-05-12 03:15:31 瀏覽:559
伺服器如何整體遷移 發布:2025-05-12 03:15:27 瀏覽:166
顯示linux分區 發布:2025-05-12 03:15:25 瀏覽:572
c語言數組長度函數是 發布:2025-05-12 03:11:09 瀏覽:173
php簡單框架 發布:2025-05-12 03:00:51 瀏覽:242
雁優化演算法 發布:2025-05-12 03:00:14 瀏覽:937
麻將規則演算法 發布:2025-05-12 03:00:11 瀏覽:388