Graphite Version 3
An experimental 3D geometry processing program
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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(in int i, in vec2 offset, in bool do_clip) {
14#ifndef GLUP_NO_GL_CLIPPING
15 if(glupIsEnabled(GLUP_CLIPPING)) {
16 gl_ClipDistance[0] =
17 clip_distance(vertex_clip_space_in(i),do_clip);
18 }
19#endif
20 gl_Position = vertex_clip_space_in(i) / vertex_clip_space_in(i).w ;
21 gl_Position.x += offset.x;
22 gl_Position.y += offset.y;
23 gl_Position.z -= 0.001; // TODO: polygon offset, do something smarter
24 VertexOut.vertex_clip_space = gl_Position;
25 if(glupIsEnabled(GLUP_VERTEX_COLORS)) {
26 VertexOut.color = color_in(i);
27 }
28 if(glupIsEnabled(GLUP_TEXTURING)) {
29 VertexOut.tex_coord = tex_coord_in(i);
30 }
31 EmitVertex();
32}
33
34void main() {
35 gl_PrimitiveID = gl_PrimitiveIDIn;
36
37 R = 2.0*(GLUP.mesh_width/(GLUP.viewport[2]+GLUP.viewport[3]));
38 p1_ndc = vertex_clip_space_in(0).xy / vertex_clip_space_in(0).w;
39 p2_ndc = vertex_clip_space_in(1).xy / vertex_clip_space_in(1).w;
40 vec2 U = R*normalize(p2_ndc-p1_ndc);
41 vec2 V = vec2(U.y,-U.x);
42 emit_vertex_2(0,-U-V,true);
43 emit_vertex_2(0,-U+V,true);
44 emit_vertex_2(1, U-V,true);
45 emit_vertex_2(1, U+V,true);
46 EndPrimitive();
47}
vec3 normalize(vec3 v)
Computes a normalized vector.
vecng< 2, Numeric::float64 > vec2
Represents points and vectors in 2d.
Definition geometry.h:59