This introduces the method of Volume Rendering using obsolete API of OpenGL. But now, I want to complete the Volume Rendering using GLSL and I have finished some parts of it. My question is how to do the blending. In the above link, blending is completed by the following codes:
glEnable(GL_BLEND);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
But how can I finish the blending using GLSL?
I tried to using the following equation:
C = Cs*As + Cd(1 - As)
Cs is the color of source object. Cd is the color of the destination object. As is the alpha of the source object. And my code in fragment shader is as following:
......
vec3 dir = backPoint - frontPoint;
float len = length(dir);
float stepSize = 0.01;
vec3 deltaDir = normalize(dir)*stepSize;
float deltaLen = length(deltaDir);
float accLen = 0;
float accAlpha = 0;
float sampleAlpha = 0;
vec4 accColor = vec4(0.0);
vec3 samplePoint = frontPoint;
vec4 sampleColor;
while(accLen < len && accColor.a <= 1.0){
sampleColor = texture(texture3D, samplePoint);
accColor = sampleColor*sampleColor.a + accColor*(1-sampleColor.a);
accLen += deltaLen;
samplePoint += deltaDir;
}
color = accColor;
......
In my project, I let the value of r, g, b, a of the 3D Texture to be the same. But I cannot obtain the result of the one of the above link. Can you help me to solve the blending problem using GLSL?