1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
27
#include "WGEColormapping-fragment.glsl"
29
#include "WGEShadingTools.glsl"
30
#include "WGETextureTools.glsl"
31
#include "WGEPostprocessing.glsl"
33
#include "WMFiberDisplaySimple-varyings.glsl"
35
/////////////////////////////////////////////////////////////////////////////
37
/////////////////////////////////////////////////////////////////////////////
40
* The max distance allowed
42
uniform float u_distance = 1.0;
45
* Ratio between colormap and fiber color.
47
uniform float u_colormapRatio = 1.0;
49
/////////////////////////////////////////////////////////////////////////////
51
/////////////////////////////////////////////////////////////////////////////
53
/////////////////////////////////////////////////////////////////////////////
55
/////////////////////////////////////////////////////////////////////////////
57
/////////////////////////////////////////////////////////////////////////////
59
/////////////////////////////////////////////////////////////////////////////
62
* Main entry point of the fragment shader.
66
#ifdef CLIPPLANE_ENABLED
67
// discard fragment if too far from plane
68
if( abs( dist ) >= u_distance )
74
// the depth of the fragment. For lines and flattubes this is the fragments z value. Tubes need to recalculate this
75
float depth = gl_FragCoord.z;
77
// this allows modification of surface brightness corresponding to current surface parameter
78
float colorScaler = 1.0;
80
// the normal acutally used for lighting
81
vec3 normal = normalize( v_normal );
83
// We need to differentiate several cases here: Lines, FlatTubes and Tubes
86
// colorScaler = 1.0; // surface parameter should have no influence
87
// normal = v_normal // apply lighting equally on the surface
88
// depth = gl_FragCoord.z; // as it is a flat ribbon
90
#ifndef ILLUMINATION_ENABLED
91
// For tubes, we need to create some "tube-effect" with the surface parameter if lighting is disabled.
92
// If light is enabled, the corrected normal ensures proper tube-effect.
93
colorScaler = 1.0 - abs( v_surfaceParam );
95
// The normal needs to be adopted too. Use the surface parameter to interpolate along the ortogonal tangent direction using the biNormal.
96
normal = normalize( mix( normal, normalize( v_biNormal ), abs( v_surfaceParam ) ) );
98
// Correct fragment depth
99
// We use the known world-space diameter and move the vertex along the corrected normal using the surface parameter
100
vec3 v = v_vertex.xyz + normal * v_diameter * ( 1.0 - abs( v_surfaceParam ) );
102
// apply standard projection:
103
vec4 vProj = gl_ProjectionMatrix * vec4( v.xyz, 1.0 );
104
depth = ( 0.5 * vProj.z / vProj.w ) + 0.5;
106
#endif // RIBBON_ENABLED
107
#else // !TUBE_ENABLED
108
// colorScaler = 1.0; // surface parameter should have no influence as lines are 1px thick
109
// normal = v_normal; // for lines, the normal does not need to be modified
110
// depth = gl_FragCoord.z; // the vertex is at the correct depth -> fragment too.
111
#endif // TUBE_ENABLED
113
// Calculate light finally
114
#ifdef ILLUMINATION_ENABLED
115
float light = blinnPhongIlluminationIntensity( wge_DefaultLightIntensity, normal );
120
// apply colormapping to the input color
121
vec4 finalColor = gl_Color;
122
#ifdef COLORMAPPING_ENABLED
123
finalColor = mix( finalColor, colormapping(), u_colormapRatio );
126
// finally set the color and depth
127
wge_FragColor = vec4( vec3( light * finalColor.xyz * colorScaler ), finalColor.a );
128
wge_FragNormal = textureNormalize( normal );
129
gl_FragDepth = depth;