This listing is a function that provides a rough but usually reasonable approximation to volume rendering with linearly interpolated opacity and luminance. Section 1.3.1 gives details of the approximation. We may use this function in conjunction with the fragment program given in Appendix 1.2.
float4 IntegrateRay(in float4 BackColor, in float4 FrontColor,
in float Length)
{
float dtau = -distance*LengthMultiply
*log(1-0.5*(colorBack.a+colorFront.a));
float zeta = exp(-dtau);
float alpha = 1 - zeta;
float Psi = alpha/dtau;
float4 color;
color.rgb = colorFront.rgb*(1-Psi) + colorBack.rgb*(Psi-zeta);
color.a = alpha;
return color;
}