This listing is a function that will, given a pair input colors (with the
alpha components set to the attenuation parameter
), a ray
segment length, and a
table (which is ubiquitous), compute
the volume rendering integral with linear interpolation for the luminance
and attenuation. Section 1.2
introduces the partial pre-integration technique.
The function assumes that the
table, which is stored in the
PsiTable variable, is 1024 by 1024. The size can be changed by
changing the definition of PSI_TABLE_SIZE.
Appendix 1 gives a Mathematica script that
builds
tables.
#define PSI_TABLE_SIZE float2(1024,1024)
float4 integrateRay(in float4 colorBack, in float4 colorFront,
in float distance, in sampler2D PsiTable)
{
float2 taudbackfront;
taudbackfront.x = distance*colorBack.a;
taudbackfront.y = distance*colorFront.a;
float zeta = exp(-dot(taudbackfront, float2(0.5,0.5)));
float2 gammabackfront = taudbackfront/(1+taudbackfront);
float Psi = tex2D(PsiTable,
gammabackfront + float2(0.5,0.5)/PSI_TABLE_SIZE).w;
float4 outColor;
outColor.rgb = colorFront.rgb*(1-Psi) + colorBack.rgb*(Psi-zeta);
outColor.a = 1 - zeta;
return outColor;
}