天天看點

光線投影算法

體繪制(VolumeRendering)之光線投射算法(RayCasting)

The four basic steps of volume ray casting: (1) Ray Casting (2) Sampling (3)Shading (4) Compositing.

Inits basic form, the volume ray casting algorithm comprises four steps:

Ray casting. For each pixel of the final image, a ray of sight is shot ("cast") through the volume. At this stage it is useful to consider the volume being touched and enclosed within a bounding primitive, a simple geometric object — usually a cuboid — that is used to intersect the ray of sight and the volume.

Sampling. Along the part of the ray of sight that lies within the volume, equidistant sampling pointssamples are selected. As in general the volume is not aligned with the ray of sight, sampling points usually will be located in between voxels. Because of that, it is necessary to trilinearly interpolate the values of the samples from its surrounding voxels. or

Shading. For each sampling point, the gradient is computed. These represent the orientation of local surfaces within the volume. The samples are then shaded, i. e. coloured and lighted, according to their surface orientation and the source of light in the scene.

Compositing. After all sampling points have been shaded, they are composited along the ray of sight, resulting in the final colour value for the pixel that is currently being processed. The composition is derived directly from the rendering equation and is similar to blending acetate sheets on an overhead projector. It works back-to-front, i. e. computation starts with the sample farthest from the viewer and ends with the one nearest to him. This work flow direction ensures that masked parts of the volume do not affect the resulting pixel.

對最終圖像的每個像素,都有一條光線穿過體素。在這一階段,考慮體素被接觸并且在一個原始邊界内封閉是很有用的,一個簡單的幾何對象——通常是一個長方體——被表示光線和體的相交。

沿着光線的射線部分位于體的内部,等距離的點采樣被選擇。通常體和表示光線的射線對齊,樣本點通常被放于體素中間。因為如此,有必要對從他周圍的體素的樣本點的值進行插值。

對每個樣本點,梯度被計算出來。這些代表在體内部的本地表面的方向。這些樣本然後根據他們的表面方向和實際的光源被加陰影,着色加光照。

在所有的樣本點背加陰影後,他們被沿着光線複合,得到最終的每個被處理過的像素的顔色值。組成是直接派生于渲染方程并且是像在一個投影機上混合圖層。這個過程被不斷重複。計算開始于視圖中最遠的樣本點,并且結束于最近的一個。這個工作流水線确認被遮擋的體部分不影響得到的像素。

光線投射方 法是基于圖像序列的直接體繪制算法。從圖像的每一個像素,沿固定方向(通常是視線方向)發射一條光線,光線穿越整個圖像序列,并在這個過程中,對圖像序列進行采樣擷取顔色資訊,同時依據光線吸收模型将顔色值進行累加,直至光線穿越整個圖像序列,最後得到的顔色值就是渲染圖像的顔色。

尤其要注意:光線投射算法是從視點到 “ 圖像序列最 表面的外層像素 ” 引射線穿越 體資料,而不少教程中都是糊裡糊塗的寫到 “ 從螢幕像素 出發 ” ,這種說法 太過簡單,而且很容易讓人誤解技術的實作途徑,可以說這是一種以訛傳訛的說法!從螢幕像素出發引出射線,是光線跟蹤算法,不是光線投射算法。

繼續閱讀