提问人:Soonts 提问时间:4/21/2023 更新时间:4/21/2023 访问量:49
体积渲染的正确颜色累积公式是什么?
What’s the correct color accumulation formula for volume rendering?
问:
我正在编写一个像素着色器(在 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
答: 暂无答案
评论