体积渲染的正确颜色累积公式是什么?

What’s the correct color accumulation formula for volume rendering?

提问人:Soonts 提问时间:4/21/2023 更新时间:4/21/2023 访问量:49

问:

我正在编写一个像素着色器(在 HLSL 中,用于 Direct3D 11)来可视化体积数据。源数据是具有预乘 RGBA 值的 3D 纹理。我需要在输出上使用单一的 RGBA 颜色,同样是预乘的 alpha。我不需要任何照明来调节音量。

沿光线累积半透明体素颜色的正确公式是什么?

Z 顺序不是问题。源数据很密集,我可以从后到前或从前到后进行迭代。

当输出也是透明的时,常用的 alpha 混合公式似乎无法处理这种情况。具体来说,当至少 1 个采样体素的 alpha = 1.0 时,我希望输出 alpha 也为 1.0,而不管该不透明体素前面有多少个半透明体素。

下面是像素着色器的主循环:

// Figure out count of layers to sample
const float inv = 1.0 / layersCount;
float s = round( layersCount );
// Initialize the accumulator
float4 acc = 0;
// Iterate over the ray, using back to front direction
for( s -= 0.5; s > 0; s -= 1.0 )
{
    // Compute UV value for the sampler
    float3 tc = mad( dir, s * inv, volumeNear );
    // Sample from the volume texture
    float4 voxel = sampleVolumeColor( tc );

    // `voxel` usually has transparency, but it can also be completely opaque, or fully transparent.
    // The values have pre-multiuplied alpha, voxel.rgb <= voxel.a

    // TODO: correct formula to update accumulator with voxel color?
}
return acc; // SV_Target
透明度 HLSL Direct3D Direct3D11 半透明性

评论

0赞 BubLblckZ 5/19/2023
如果我正确理解了你的问题:跟随光线并跟踪剩余的光量,在最初设置为 1.0 的浮点数中,我将其称为 x。然后,对于每个体素,将 voxel.rgb 乘以 x 添加到 acc.rgb,然后将 x 乘以 voxel.a。一旦所有体素都被迭代,x 将保持不击中任何东西的光量,因此将 acc.a 设置为 1.0 - x。

答: 暂无答案