Geogram Version 1.9.9
A programming library of geometric algorithms
Loading...
Searching...
No Matches
thick_lines_geometry_shader.h
1//import <GLUP/current_profile/geometry_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
7// Send the two extremities of the segment and the radius to
8// the fragment shader (used to create nicer joints)
9out vec2 p1_ndc;
10out vec2 p2_ndc;
11out float R;
12
13void emit_vertex_2(
14 in int i, in vec2 offset, in float z_offset, in bool do_clip
15) {
16#ifndef GLUP_NO_GL_CLIPPING
17 if(glupIsEnabled(GLUP_CLIPPING)) {
18 gl_ClipDistance[0] =
19 clip_distance(vertex_clip_space_in(i),do_clip);
20 }
21#endif
22 gl_Position = vertex_clip_space_in(i) / vertex_clip_space_in(i).w ;
23 gl_Position.x += offset.x;
24 gl_Position.y += offset.y;
25 gl_Position.z -= z_offset;
26 VertexOut.vertex_clip_space = gl_Position;
27 if(glupIsEnabled(GLUP_VERTEX_COLORS)) {
28 VertexOut.color = color_in(i);
29 }
30 if(glupIsEnabled(GLUP_TEXTURING)) {
31 VertexOut.tex_coord = tex_coord_in(i);
32 }
33 EmitVertex();
34}
35
36void main() {
37 gl_PrimitiveID = gl_PrimitiveIDIn;
38
39 R = 2.0*(GLUP.mesh_width/(GLUP.viewport[2]+GLUP.viewport[3]));
40 p1_ndc = vertex_clip_space_in(0).xy / vertex_clip_space_in(0).w;
41 p2_ndc = vertex_clip_space_in(1).xy / vertex_clip_space_in(1).w;
42 vec2 U = R*normalize(p2_ndc-p1_ndc);
43 vec2 V = vec2(U.y,-U.x);
44 float z_offset = 0.2 * GLUP.modelview_matrix[3][3] * R;
45 emit_vertex_2(0,-U-V, z_offset, true);
46 emit_vertex_2(0,-U+V, z_offset, true);
47 emit_vertex_2(1, U-V, z_offset, true);
48 emit_vertex_2(1, U+V, z_offset, true);
49 EndPrimitive();
50}
vec3 normalize(vec3 v)
Computes a normalized vector.
vecng< 2, Numeric::float64 > vec2
Represents points and vectors in 2d.
Definition geometry.h:59