Carna  Version 3.0.1
mip.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 minIntensity;
17 uniform float maxIntensity;
18 uniform vec4 color;
19 
20 in vec4 modelSpaceCoordinates;
21 
22 out vec4 gl_FragColor;
23 
24 
25 // ----------------------------------------------------------------------------------
26 // Basic Sampling
27 // ----------------------------------------------------------------------------------
28 
29 float intensityAt( vec3 p )
30 {
31  return texture( huVolume, p ).r;
32 }
33 
34 
35 // ----------------------------------------------------------------------------------
36 // Fragment Procedure
37 // ----------------------------------------------------------------------------------
38 
39 void main()
40 {
41  if( abs( modelSpaceCoordinates.x ) > 0.5 || abs( modelSpaceCoordinates.y ) > 0.5 || abs( modelSpaceCoordinates.z ) > 0.5 )
42  {
43  discard;
44  }
45 
46  vec4 textureCoordinates = modelTexture * modelSpaceCoordinates;
47  float intensity = intensityAt( textureCoordinates.xyz );
48  float f = step( minIntensity, intensity ) * ( 1 - step( maxIntensity, intensity ) ) * ( intensity - minIntensity ) / ( maxIntensity - minIntensity );
49 
50  gl_FragColor = vec4( color.rgb, color.a * f );
51 }