~ubuntu-branches/ubuntu/raring/openwalnut/raring

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Sebastian Eichelbaum
  • Date: 2012-12-12 11:26:32 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20121212112632-xhiuwkxuz5h0idkh
Tags: 1.3.1+hg5849-1
* Minor changes compared to 1.3.0 but included several bug fixes.
* See http://www.openwalnut.org/versions/4

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
#extension GL_EXT_geometry_shader4 : enable
 
28
 
 
29
#include "WGETransformationTools.glsl"
 
30
 
 
31
/////////////////////////////////////////////////////////////////////////////
 
32
// Uniforms
 
33
/////////////////////////////////////////////////////////////////////////////
 
34
 
 
35
/**
 
36
 * A point on the plane.
 
37
 */
 
38
uniform vec3 u_planePoint;
 
39
 
 
40
/**
 
41
 * The normal vector of the plane
 
42
 */
 
43
uniform vec3 u_planeVector;
 
44
 
 
45
/**
 
46
 * The max distance allowed
 
47
 */
 
48
uniform float u_distance = 1.0;
 
49
 
 
50
/**
 
51
 * The size of the tube
 
52
 */
 
53
uniform float u_tubeSize;
 
54
 
 
55
/////////////////////////////////////////////////////////////////////////////
 
56
// Attributes
 
57
/////////////////////////////////////////////////////////////////////////////
 
58
 
 
59
/////////////////////////////////////////////////////////////////////////////
 
60
// Varyings
 
61
/////////////////////////////////////////////////////////////////////////////
 
62
 
 
63
/**
 
64
 * The normal/tangent in scene-space
 
65
 */
 
66
varying in vec3 v_normal[];
 
67
 
 
68
/**
 
69
 * The output normal for the fragment shader in world-space
 
70
 */
 
71
varying out vec3 v_normalWorld;
 
72
 
 
73
/**
 
74
 * The vertex coordinates in world-space
 
75
 */
 
76
varying out vec4 v_vertex;
 
77
 
 
78
/**
 
79
 * The scaling component of the modelview matrix.
 
80
 */
 
81
varying out float v_worldScale;
 
82
 
 
83
/////////////////////////////////////////////////////////////////////////////
 
84
// Variables
 
85
/////////////////////////////////////////////////////////////////////////////
 
86
 
 
87
/////////////////////////////////////////////////////////////////////////////
 
88
// Functions
 
89
/////////////////////////////////////////////////////////////////////////////
 
90
 
 
91
/**
 
92
 * Main entry point of the geometry shader.
 
93
 */
 
94
void main()
 
95
{
 
96
#ifdef CLIPPLANE_ENABLED
 
97
    // define the plane
 
98
    vec3 n = normalize( u_planeVector );
 
99
    float d = dot( u_planePoint, n );
 
100
    float dist = dot( gl_PositionIn[0].xyz, n ) - d;
 
101
 
 
102
    if( abs( dist ) >= u_distance )
 
103
    {
 
104
        return;
 
105
    }
 
106
#endif  // CLIPPLANE_ENABLED
 
107
 
 
108
#if !( defined( ENDCAPS_ENABLED ) )
 
109
    // no endcaps?
 
110
    // do not emit any vertex
 
111
    return;
 
112
#endif  // ENDCAPS_ENABLED
 
113
 
 
114
    // discard the caps if in ribbon mode or non-zoomable mode. it not yet works.
 
115
#if !( defined( RIBBON_ENABLED ) || !defined( ZOOMABLE_ENABLED ) )
 
116
 
 
117
    // grab the info we got from the vertex array:
 
118
    vec3 tangent = normalize( v_normal[0] );
 
119
    vec4 vertex = gl_PositionIn[0];
 
120
 
 
121
    // camera view direction
 
122
    vec3 view = normalize( ( gl_ModelViewMatrixInverse * vec4( 0.0, 0.0, -1.0, 0.0 ) ).xyz );
 
123
    float angle = step( 0.0, sign( dot( view, tangent ) ) );
 
124
 
 
125
    // the plane of the sprite is determined by the tangent ond two orthogonal vectors a and b
 
126
    vec4 a = 0.2 * u_tubeSize * vec4( normalize( cross( tangent, view ) ), 0.0 );
 
127
    vec4 b = 0.2 * u_tubeSize * vec4( normalize( cross( tangent, a.xyz ) ), 0.0 );
 
128
 
 
129
    gl_FrontColor = gl_FrontColorIn[0];
 
130
 
 
131
    // create the quad
 
132
    v_normalWorld = ( gl_ModelViewMatrix * vec4( v_normal[0], 0.0 ) ).xyz;
 
133
    // let it point towards the camera
 
134
    v_normalWorld *= sign( dot( normalize( v_normalWorld ), vec3( 0.0, 0.0, 1.0 ) ) );
 
135
 
 
136
    v_worldScale = 0.1 * getModelViewScale();
 
137
 
 
138
    // vertex 1
 
139
    gl_TexCoord[0] = vec4( -1.0, -1.0, 0.0, angle );
 
140
    v_vertex = gl_ModelViewMatrix * ( vertex + ( -0.5 * a ) + ( -0.5 * b ) );
 
141
    gl_Position = gl_ProjectionMatrix * v_vertex;
 
142
    EmitVertex();
 
143
 
 
144
    // vertex 2
 
145
    gl_TexCoord[0] = vec4( -1.0, 1.0, 0.0, angle );
 
146
    v_vertex = gl_ModelViewMatrix * ( vertex + ( -0.5 * a ) + ( 0.5 * b ) );
 
147
    gl_Position = gl_ProjectionMatrix * v_vertex;
 
148
    EmitVertex();
 
149
 
 
150
    // vertex 3
 
151
    gl_TexCoord[0] = vec4( 1.0, -1.0, 0.0, angle );
 
152
    v_vertex = gl_ModelViewMatrix * ( vertex + ( 0.5 * a ) + ( -0.5 * b ) );
 
153
    gl_Position = gl_ProjectionMatrix * v_vertex;
 
154
    EmitVertex();
 
155
 
 
156
    // vertex 4
 
157
    gl_TexCoord[0] = vec4( 1.0, 1.0, 0.0, angle );
 
158
    v_vertex = gl_ModelViewMatrix * ( vertex + ( 0.5 * a ) + ( 0.5 * b ) );
 
159
    gl_Position = gl_ProjectionMatrix * v_vertex;
 
160
    EmitVertex();
 
161
 
 
162
    EndPrimitive();
 
163
#endif
 
164
}
 
165