#version 330 uniform vec3 camera; uniform float stepsize; uniform vec3 d; uniform vec3 ray_min; uniform vec3 ray_max; vec4 computeColor(vec3 p); in vec4 gl_TexCoord[1]; out vec4 MyFragColor; void main(void) { //vec3 camera = vec3(0.5, 0.5, 1); //float stepsize = 0.001; vec4 value; float scalar; //initialize the destinatino color and opacity vec4 dst = vec4(0.0, 0.0, 0.0, 0.0); //determine the entry position of the volume vec3 p = gl_TexCoord[0].xyz; //compute the ray direction vec3 direction = p - camera; direction = normalize(direction); vec3 step = length(direction*(1.0/d))*direction*stepsize; //loop for ray traversal //for(int i=0; i<400; i++) do { value = computeColor(p); vec4 src = value; src.rgb = src.rgb*src.a; //ray integration dst = (1.0 - dst.a)*src + dst; //advance the ray position along the ray direction p = p + step; }while(p.x > ray_min.x && p.y > ray_min.y && p.z > ray_min.z && p.x < ray_max.x && p.y < ray_max.y && p.z < ray_max.z && dst.a < 0.99); MyFragColor = dst; }