4 * Copyright (C) 2010 - 2015 Leonid Kostrykin
6 * Chair of Medical Engineering (mediTEC)
7 * RWTH Aachen University
14 uniform sampler3D huVolume;
15 uniform sampler3D normalMap;
16 uniform sampler1D colorMap;
17 uniform mat4 modelTexture;
18 uniform mat3 normalsView;
19 uniform float stepLength;
20 uniform float translucence;
21 uniform float diffuseLight;
22 uniform int lightingEnabled;
24 in vec4 modelSpaceCoordinates;
26 out vec4 gl_FragColor;
29 // ----------------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------------
33 vec4 sampleAt( vec3 p )
35 float intensity = texture( huVolume, p ).r;
36 vec4 color = texture( colorMap, intensity );
38 if( lightingEnabled == 1 )
40 vec3 normalDirection = texture( normalMap, p ).rgb;
42 if( dot( normalDirection, normalDirection ) < 1e-4 )
44 diffuseColor = vec3( 0, 0, 0 );
48 vec3 normal = normalize( normalsView * normalDirection );
49 vec3 lightDirection = vec3( 0, 0, -1 );
50 float diffuseLightAmount = max( 0, -dot( normal, lightDirection ) );
51 diffuseColor = color.rgb * diffuseLightAmount;
53 return vec4( mix( color.rgb, diffuseColor, diffuseLight ), color.a );
62 // ----------------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------------
68 if( abs( modelSpaceCoordinates.x ) > 0.5 || abs( modelSpaceCoordinates.y ) > 0.5 || abs( modelSpaceCoordinates.z ) > 0.5 )
73 vec4 textureCoordinates = modelTexture * modelSpaceCoordinates;
74 vec4 color = sampleAt( textureCoordinates.xyz );
76 float alpha = color.a * stepLength / ( 1 + translucence );
77 gl_FragColor = vec4( color.rgb * alpha, alpha );