~ubuntu-branches/ubuntu/precise/openwalnut/precise

« back to all changes in this revision

Viewing changes to src/modules/fiberDisplaySimple/shaders/WMFiberDisplaySimple-fragment.glsl

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Eichelbaum
  • Date: 2011-06-21 10:26:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110621102654-rq0zf436q949biih
Tags: upstream-1.2.5
ImportĀ upstreamĀ versionĀ 1.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
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.
 
14
//
 
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.
 
19
//
 
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/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#version 120
 
26
 
 
27
#include "WGEColormapping-fragment.glsl"
 
28
 
 
29
#include "WGEShadingTools.glsl"
 
30
#include "WGETextureTools.glsl"
 
31
#include "WGEPostprocessing.glsl"
 
32
 
 
33
#include "WMFiberDisplaySimple-varyings.glsl"
 
34
 
 
35
/////////////////////////////////////////////////////////////////////////////
 
36
// Uniforms
 
37
/////////////////////////////////////////////////////////////////////////////
 
38
 
 
39
/**
 
40
 * The max distance allowed
 
41
 */
 
42
uniform float u_distance = 1.0;
 
43
 
 
44
/**
 
45
 * Ratio between colormap and fiber color.
 
46
 */
 
47
uniform float u_colormapRatio = 1.0;
 
48
 
 
49
/////////////////////////////////////////////////////////////////////////////
 
50
// Attributes
 
51
/////////////////////////////////////////////////////////////////////////////
 
52
 
 
53
/////////////////////////////////////////////////////////////////////////////
 
54
// Variables
 
55
/////////////////////////////////////////////////////////////////////////////
 
56
 
 
57
/////////////////////////////////////////////////////////////////////////////
 
58
// Functions
 
59
/////////////////////////////////////////////////////////////////////////////
 
60
 
 
61
/**
 
62
 * Main entry point of the fragment shader.
 
63
 */
 
64
void main()
 
65
{
 
66
#ifdef CLIPPLANE_ENABLED
 
67
    // discard fragment if too far from plane
 
68
    if( abs( dist ) >= u_distance )
 
69
    {
 
70
        discard;
 
71
    }
 
72
#endif
 
73
 
 
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;
 
76
 
 
77
    // this allows modification of surface brightness corresponding to current surface parameter
 
78
    float colorScaler = 1.0;
 
79
 
 
80
    // the normal acutally used for lighting
 
81
    vec3 normal = normalize( v_normal );
 
82
 
 
83
    // We need to differentiate several cases here: Lines, FlatTubes and Tubes
 
84
#ifdef TUBE_ENABLED
 
85
#ifdef RIBBON_ENABLED
 
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
 
89
#else
 
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 );
 
94
#endif
 
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 ) ) );
 
97
 
 
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 ) );
 
101
 
 
102
    // apply standard projection:
 
103
    vec4 vProj = gl_ProjectionMatrix * vec4( v.xyz, 1.0 );
 
104
    depth = ( 0.5 * vProj.z / vProj.w ) + 0.5;
 
105
 
 
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
 
112
 
 
113
    // Calculate light finally
 
114
#ifdef ILLUMINATION_ENABLED
 
115
    float light = blinnPhongIlluminationIntensity( wge_DefaultLightIntensity, normal );
 
116
#else
 
117
    float light = 1.0;
 
118
#endif
 
119
 
 
120
    // apply colormapping to the input color
 
121
    vec4 finalColor = gl_Color;
 
122
#ifdef COLORMAPPING_ENABLED
 
123
    finalColor = mix( finalColor, colormapping(), u_colormapRatio );
 
124
#endif
 
125
 
 
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;
 
130
}
 
131