Geogram Version 1.9.9
A programming library of geometric algorithms
Loading...
Searching...
No Matches
thick_lines_vertex_shader.h
1//import <GLUP/current_profile/vertex_shader_preamble.h>
2//import <GLUP/stdglup.h>
3//import <GLUP/current_profile/toggles.h>
4//import <GLUP/current_profile/primitive.h>
5//import <GLUPES/vertex_shader_state.h>
6
7glup_in vec4 vertex_in;
8glup_in vec4 color_in;
9glup_in vec4 tex_coord_in;
10glup_in vec4 normal_in;
11glup_in highp float vertex_id_in;
12glup_out float clip_dist;
13glup_out vec4 color;
14glup_out vec4 tex_coord;
15glup_flat glup_out glup_id primitive_id;
16glup_out float R;
17glup_out vec2 p1_ndc;
18glup_out vec2 p2_ndc;
19
20
21void emit_vertex_2(
22 in vec4 p_world, in vec4 p_clip_space,
23 in vec2 offset, in float z_offset
24) {
25 if(glupIsEnabled(GLUP_CLIPPING)) {
26 clip_dist = dot(
27 p_world, GLUP_VS.world_clip_plane
28 );
29 }
30 gl_Position = p_clip_space / p_clip_space.w ;
31 gl_Position.x += offset.x;
32 gl_Position.y += offset.y;
33 gl_Position.z -= z_offset;
34 if(glupIsEnabled(GLUP_VERTEX_COLORS)) {
35 color = color_in;
36 }
37 if(glupIsEnabled(GLUP_TEXTURING)) {
38 if(glupIsEnabled(GLUP_INDIRECT_TEXTURING)) {
39 tex_coord = tex_coord_in;
40 } else {
41 tex_coord = GLUP_VS.texture_matrix * tex_coord_in;
42 }
43 }
44}
45
46
47void main() {
48
49 R = 2.0*(GLUP_VS.mesh_width/(GLUP_VS.viewport[2]+GLUP_VS.viewport[3]));
50
51 vec4 p1_clipspace = GLUP_VS.modelviewprojection_matrix * vertex_in;
52 vec4 p2_clipspace = GLUP_VS.modelviewprojection_matrix * normal_in;
53
54 p1_ndc = p1_clipspace.xy / p1_clipspace.w;
55 p2_ndc = p2_clipspace.xy / p2_clipspace.w;
56
57 if(glupIsEnabled(GLUP_PICKING)) {
58#ifdef GLUP_ES_100
59 // Note: we need to add 0.5, else there are some precision
60 // issues, and the integer mod() operation creates random
61 // values...
62 primitive_id = float(
63 int(vertex_id_in+0.5)/glup_primitive_nb_vertices
64 )+0.5;
65#else
66 primitive_id = int(vertex_id_in + 0.5)/glup_primitive_nb_vertices;
67#endif
68 }
69
70 vec2 U = R*normalize(p2_ndc-p1_ndc);
71 vec2 V = vec2(U.y,-U.x);
72
73 int v_local_id = glup_mod(int(vertex_id_in+0.5),4);
74 float z_offset = 0.2 * GLUP_VS.modelview_matrix[3][3] * R;
75
76 if(v_local_id == 0) {
77 emit_vertex_2(vertex_in, p1_clipspace,-U-V, z_offset);
78 } else if(v_local_id == 1) {
79 emit_vertex_2(vertex_in, p1_clipspace,-U+V, z_offset);
80 } else if(v_local_id == 2) {
81 emit_vertex_2(normal_in, p2_clipspace, U-V, z_offset);
82 } else {
83 emit_vertex_2(normal_in, p2_clipspace, U+V, z_offset);
84 }
85
86}
vec3 normalize(vec3 v)
Computes a normalized vector.
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors. vecng
Definition vecg.h:995
vecng< 4, Numeric::float64 > vec4
Represents points and vectors in 4d.
Definition geometry.h:71
vecng< 2, Numeric::float64 > vec2
Represents points and vectors in 2d.
Definition geometry.h:59