光线投影算法
体绘制(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.
- 对最终图像的每个像素,都有一条光线穿过体素。在这一阶段,考虑体素被接触并且在一个原始边界内封闭是很有用的,一个简单的几何对象——通常是一个长方体——被表示光线和体的相交。
- 沿着光线的射线部分位于体的内部,等距离的点采样被选择。通常体和表示光线的射线对齐,样本点通常被放于体素中间。因为如此,有必要对从他周围的体素的样本点的值进行插值。
- 对每个样本点,梯度被计算出来。这些代表在体内部的本地表面的方向。这些样本然后根据他们的表面方向和实际的光源被加阴影,着色加光照。
- 在所有的样本点背加阴影后,他们被沿着光线复合,得到最终的每个被处理过的像素的颜色值。组成是直接派生于渲染方程并且是像在一个投影机上混合图层。这个过程被不断重复。计算开始于视图中最远的样本点,并且结束于最近的一个。这个工作流水线确认被遮挡的体部分不影响得到的像素。
光线投射方 法是基于图像序列的直接体绘制算法。从图像的每一个像素,沿固定方向(通常是视线方向)发射一条光线,光线穿越整个图像序列,并在这个过程中,对图像序列进行采样获取颜色信息,同时依据光线吸收模型将颜色值进行累加,直至光线穿越整个图像序列,最后得到的颜色值就是渲染图像的颜色。
尤其要注意:光线投射算法是从视点到 “ 图像序列最 表面的外层像素 ” 引射线穿越 体数据,而不少教程中都是糊里糊涂的写到 “ 从屏幕像素 出发 ” ,这种说法 太过简单,而且很容易让人误解技术的实现途径,可以说这是一种以讹传讹的说法!从屏幕像素出发引出射线,是光线跟踪算法,不是光线投射算法。