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

去光照演算法

發布時間: 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-07-03 16:28:46 瀏覽:72
電信無線路由器官方密碼是什麼 發布:2025-07-03 16:25:00 瀏覽:773
空間只能申請訪問 發布:2025-07-03 16:23:27 瀏覽:735
華碩天選2air配置如何選擇 發布:2025-07-03 16:10:09 瀏覽:571
asp搜索源碼 發布:2025-07-03 15:49:55 瀏覽:235
醫美大資料庫 發布:2025-07-03 15:47:07 瀏覽:357
c語言將二進制轉化為十進制 發布:2025-07-03 15:32:47 瀏覽:988
c語言幫助文檔 發布:2025-07-03 15:22:43 瀏覽:320
雙埠存儲器在情況下會發生讀寫沖突 發布:2025-07-03 15:12:54 瀏覽:271
快站資料庫 發布:2025-07-03 14:45:44 瀏覽:40