Geogram Version 1.9.6-rc
A programming library of geometric algorithms
Loading...
Searching...
No Matches
vertex_shader.h
1//import <GLUP/current_profile/vertex_shader_preamble.h>
2//import <GLUPGLSL/state.h>
3//import <GLUP/stdglup.h>
4//import <GLUP/current_profile/toggles.h>
5//import <GLUP/current_profile/primitive.h>
6
7in vec4 vertex_in;
8in vec4 color_in;
9in vec4 tex_coord_in;
10
11#if GLUP_PRIMITIVE_DIMENSION==2
12in vec4 normal_in;
13#endif
14
15out VertexData {
16#ifdef GLUP_NO_GEOMETRY_SHADER
17 vec4 vertex_clip_space;
18#endif
19 vec4 color;
20 vec4 tex_coord;
21#if GLUP_PRIMITIVE_DIMENSION==2
22 vec3 normal;
23# ifdef GLUP_NO_GEOMETRY_SHADER
24 vec4 mesh_tex_coord;
25# endif
26#endif
27} VertexOut;
28
29
30void main(void) {
31 if(glupIsEnabled(GLUP_VERTEX_COLORS)) {
32 VertexOut.color = color_in;
33 }
34 if(glupIsEnabled(GLUP_TEXTURING)) {
35 if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) {
36 VertexOut.tex_coord = tex_coord_in;
37 } else {
38 VertexOut.tex_coord =
39 GLUP.texture_matrix * tex_coord_in;
40 }
41 }
42
43#ifndef GLUP_NO_GL_CLIPPING
44 if(glupIsEnabled(GLUP_CLIPPING)) {
45 gl_ClipDistance[0] = dot(
46 vertex_in, GLUP.world_clip_plane
47 );
48 } else {
49 gl_ClipDistance[0] = 0.0;
50 }
51#endif
52
53#if GLUP_PRIMITIVE_DIMENSION==2
54 if(
55 glupIsEnabled(GLUP_LIGHTING) &&
56 glupIsEnabled(GLUP_VERTEX_NORMALS)
57 ) {
58 VertexOut.normal = GLUP.normal_matrix * normal_in.xyz;
59 }
60
61#endif
62 gl_Position = GLUP.modelviewprojection_matrix * vertex_in;
63
64#if GLUP_PRIMITIVE_DIMENSION==2
65# ifdef GLUP_NO_GEOMETRY_SHADER
66 VertexOut.vertex_clip_space = gl_Position;
67 if(glupIsEnabled(GLUP_DRAW_MESH)) {
68 // Note: does not work with glDrawElements because gl_VertexID is
69 // the element index !
70 int lv = gl_VertexID % glup_primitive_nb_vertices;
71 VertexOut.mesh_tex_coord = vec4(
72 float(lv == 0),
73 float(lv == 1),
74 float(lv == 2),
75 float(lv == 3)
76 );
77 }
78# endif
79#endif
80}
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors. vecng
Definition vecg.h:916
vecng< 3, Numeric::float64 > vec3
Represents points and vectors in 3d.
Definition geometry.h:65
vecng< 4, Numeric::float64 > vec4
Represents points and vectors in 4d.
Definition geometry.h:71