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
#extension GL_EXT_geometry_shader4 : enable
29
#include "WGETransformationTools.glsl"
31
/////////////////////////////////////////////////////////////////////////////
33
/////////////////////////////////////////////////////////////////////////////
36
* A point on the plane.
38
uniform vec3 u_planePoint;
41
* The normal vector of the plane
43
uniform vec3 u_planeVector;
46
* The max distance allowed
48
uniform float u_distance = 1.0;
51
* The size of the tube
53
uniform float u_tubeSize;
55
/////////////////////////////////////////////////////////////////////////////
57
/////////////////////////////////////////////////////////////////////////////
59
/////////////////////////////////////////////////////////////////////////////
61
/////////////////////////////////////////////////////////////////////////////
64
* The normal/tangent in scene-space
66
varying in vec3 v_normal[];
69
* The output normal for the fragment shader in world-space
71
varying out vec3 v_normalWorld;
74
* The vertex coordinates in world-space
76
varying out vec4 v_vertex;
79
* The scaling component of the modelview matrix.
81
varying out float v_worldScale;
83
/////////////////////////////////////////////////////////////////////////////
85
/////////////////////////////////////////////////////////////////////////////
87
/////////////////////////////////////////////////////////////////////////////
89
/////////////////////////////////////////////////////////////////////////////
92
* Main entry point of the geometry shader.
96
#ifdef CLIPPLANE_ENABLED
98
vec3 n = normalize( u_planeVector );
99
float d = dot( u_planePoint, n );
100
float dist = dot( gl_PositionIn[0].xyz, n ) - d;
102
if( abs( dist ) >= u_distance )
106
#endif // CLIPPLANE_ENABLED
108
#if !( defined( ENDCAPS_ENABLED ) )
110
// do not emit any vertex
112
#endif // ENDCAPS_ENABLED
114
// discard the caps if in ribbon mode or non-zoomable mode. it not yet works.
115
#if !( defined( RIBBON_ENABLED ) || !defined( ZOOMABLE_ENABLED ) )
117
// grab the info we got from the vertex array:
118
vec3 tangent = normalize( v_normal[0] );
119
vec4 vertex = gl_PositionIn[0];
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 ) ) );
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 );
129
gl_FrontColor = gl_FrontColorIn[0];
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 ) ) );
136
v_worldScale = 0.1 * getModelViewScale();
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;
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;
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;
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;