Visualisierung 2
Comparison of Hue Preserving Rendering to Alpha Composing
alpha.frag
Go to the documentation of this file.
1 
10 #version 400
11 
12 out vec4 color;
13 
14 in vec3 position;
15 
16 uniform sampler3D volume;
17 uniform float regionSeperator;
18 uniform int depth;
19 uniform int width;
20 uniform int height;
21 uniform vec4 regionColor1;
22 uniform vec4 regionColor2;
23 uniform int orientation;
24 
25 void main() {
26 
27  // transform normalized device coordinates [-1,-1] to volume coordinate system [0,1]
28  vec3 volPosition = (position+1)/2;
29 
30  float alphaB; // back voxel
31  vec4 colorB;
32 
33  float x;
34  float y;
35  float z;
36 
37  // Front-to-Back compositing
38  for(float i=0;i<depth;i++)
39  {
40  switch (orientation) {
41  default:
42  case 0: // top
43  x = volPosition.x;
44  y = volPosition.y;
45  z = i/depth;
46  break;
47  case 1: // bottom
48  x = 1.0f - volPosition.x;
49  y = 1.0f - volPosition.y;
50  z = (depth - i - 1)/depth;
51  break;
52  case 2: // left
53  x = i/depth;
54  y = volPosition.x;
55  z = 1.0f - volPosition.y;
56  break;
57  case 3: // right
58  x = (depth - i - 1) / depth;
59  y = 1 - volPosition.x;
60  z = 1.0f - volPosition.y;
61  break;
62  case 4: // front
63  x = volPosition.x;
64  y = i/depth;
65  z = 1.0f - volPosition.y;
66  break;
67  case 5: // back
68  x = 1 - volPosition.x;
69  y = (depth - i - 1) / depth;
70  z = 1.0f - volPosition.y;
71  break;
72  }
73  colorB.a = texture(volume,vec3(x,y,z)).r;
74  colorB.rgb = (colorB.a<regionSeperator)?regionColor1.rgb:regionColor2.rgb;
75  color.rgb = color.rgb + (1-color.a)*colorB.rgb*colorB.a;
76  color.a = min(1,color.a + (1-color.a)*colorB.a*colorB.a);
77 
78  if(color.a==1){break;} // early ray termination
79  }
80 
81  }
82 
83 
out vec4 color
Definition: alpha.frag:12
void main()
Definition: alpha.frag:25
uniform int height
Definition: alpha.frag:20
uniform int depth
Definition: alpha.frag:18
uniform int orientation
Definition: alpha.frag:23
uniform vec4 regionColor1
Definition: alpha.frag:21
uniform int width
Definition: alpha.frag:19
uniform sampler3D volume
Definition: alpha.frag:16
uniform vec4 regionColor2
Definition: alpha.frag:22
in vec3 position
Definition: alpha.frag:14
uniform float regionSeperator
Definition: alpha.frag:17