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

去光照演算法

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

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:568
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:857
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:556
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:737
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:659
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:978
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:231
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:89
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:781
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:684