Carna  Version 3.0.1
drr-accumulation.frag
1 #version 330
2 
3 /*
4  * Copyright (C) 2010 - 2015 Leonid Kostrykin
5  *
6  * Chair of Medical Engineering (mediTEC)
7  * RWTH Aachen University
8  * Pauwelsstr. 20
9  * 52074 Aachen
10  * Germany
11  *
12  */
13 
14 uniform sampler3D huVolume;
15 uniform mat4 modelTexture;
16 uniform float stepLength;
17 uniform float waterAttenuation;
18 uniform float lowerThreshold;
19 uniform float upperThreshold;
20 uniform float upperMultiplier;
21 
22 in vec4 modelSpaceCoordinates;
23 
24 out vec4 gl_FragColor;
25 
26 
27 // ----------------------------------------------------------------------------------
28 // Basic Sampling
29 // ----------------------------------------------------------------------------------
30 
31 float intensityAt( vec3 p )
32 {
33  return texture( huVolume, p ).r;
34 }
35 
36 
37 // ----------------------------------------------------------------------------------
38 // Fragment Procedure
39 // ----------------------------------------------------------------------------------
40 
41 void main()
42 {
43  if( abs( modelSpaceCoordinates.x ) > 0.5 || abs( modelSpaceCoordinates.y ) > 0.5 || abs( modelSpaceCoordinates.z ) > 0.5 )
44  {
45  discard;
46  }
47 
48  vec4 textureCoordinates = modelTexture * modelSpaceCoordinates;
49  float intensity = intensityAt( textureCoordinates.xyz );
50  intensity = intensity + step( upperThreshold, intensity ) * ( upperMultiplier - 1 ) * intensity;
51  float huv = intensity * 4096 - 1024;
52  float mu = waterAttenuation * ( 1 + huv / 1000 );
53  float summand = step( lowerThreshold, intensity ) * mu * stepLength;
54 
55  gl_FragColor = vec4( summand, 0, 0, 1 );
56 }