4 * Copyright (C) 2010 - 2016 Leonid Kostrykin
6 * Chair of Medical Engineering (mediTEC)
7 * RWTH Aachen University
13 * Copyright (C) 2021 - 2025 Leonid Kostrykin
17uniform sampler3D intensities;
18uniform sampler3D normalMap;
19uniform sampler1D colorMap;
20uniform float minIntensity;
21uniform float maxIntensity;
22uniform mat4 modelTexture;
23uniform mat3 normalsView;
24uniform float stepLength;
25uniform float translucency;
26uniform float diffuseLight;
27uniform int lightingEnabled;
29in vec4 modelSpaceCoordinates;
31layout( location = 0 ) out vec4 _gl_FragColor;
36// ----------------------------------------------------------------------------------
38// ----------------------------------------------------------------------------------
40vec4 sampleAt( vec3 p )
42 float intensity = texture( intensities, p ).r;
44 /* Apply intensity clipping.
47 ( intensity - minIntensity + EPS ) / ( maxIntensity - minIntensity + EPS )
50 /* Query color in `colorMap`.
52 vec4 color = texture( colorMap, intensity );
56 if( lightingEnabled == 1 )
58 vec3 normalDirection = texture( normalMap, p ).rgb;
60 if( dot( normalDirection, normalDirection ) < 1e-4 )
62 diffuseColor = vec3( 0, 0, 0 );
66 vec3 normal = normalize( normalsView * normalDirection );
67 vec3 lightDirection = vec3( 0, 0, -1 );
68 float diffuseLightAmount = max( 0, -dot( normal, lightDirection ) );
69 diffuseColor = color.rgb * diffuseLightAmount;
71 return vec4( mix( color.rgb, diffuseColor, diffuseLight ), color.a );
80// ----------------------------------------------------------------------------------
82// ----------------------------------------------------------------------------------
86 if( abs( modelSpaceCoordinates.x ) > 0.5 || abs( modelSpaceCoordinates.y ) > 0.5 || abs( modelSpaceCoordinates.z ) > 0.5 )
91 vec4 textureCoordinates = modelTexture * modelSpaceCoordinates;
92 vec4 color = sampleAt( textureCoordinates.xyz );
94 float alpha = color.a * stepLength / ( 1 + translucency );
95 _gl_FragColor = vec4( color.rgb * alpha, alpha );