Blame view

fragRayCast.glsl 1.02 KB
ee96a02c   David Mayerich   first commit from...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  #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;
  }