8000 Add "up" line segment in the geometry shader · yalue/l_system_3d@ef54851 · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
Add "up" line segment in the geometry shader
Browse files Browse the repository at this point in the history
 - Just an arbitrary thing to continue practicing: Added a second line
   segment in the geometry shader, starting at every line segment's
   midpoint and pointing in the segment's "up" direction.
  • Loading branch information
yalue committed Mar 4, 2022
1 parent 0f6094f commit ef54851
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pipes_shader.geom
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#version 330 core
layout (lines) in;
layout (line_strip, max_vertices = 2) out;
layout (line_strip, max_vertices = 4) out;

in VS_OUT {
vec3 position;
Expand Down Expand Up @@ -36,13 +36,27 @@ void main() {

mat4 projView = shared_uniforms.projection * shared_uniforms.view;
vec4 pos_tmp = model * vec4(gs_in[0].position, 1);
pos_tmp += normalize(vec4(gs_out.right, 1.0)) * timeOffset();
pos_tmp += normalize(vec4(gs_out.forward, 1.0)) * timeOffset();
gs_out.frag_position = pos_tmp.xyz;
gl_Position = projView * pos_tmp;
EmitVertex();

pos_tmp = model * vec4(gs_in[1].position, 1);
pos_tmp += normalize(vec4(gs_out.right, 1.0)) * timeOffset();
pos_tmp += normalize(vec4(gs_out.forward, 1.0)) * timeOffset();
gs_out.frag_position = pos_tmp.xyz;
gl_Position = projView * pos_tmp;
EmitVertex();
EndPrimitive();

// Add a second primitive: a line starting at each midpoint and pointing in
// the "up" direction.
vec3 dir = gs_in[1].position - gs_in[0].position;
vec3 midpoint = gs_in[0].position + dir * 0.5;
pos_tmp = model * vec4(midpoint, 1.0);
gs_out.frag_position = pos_tmp.xyz;
gl_Position = projView * pos_tmp;
EmitVertex();
pos_tmp = model * vec4(midpoint + gs_out.up * (length(dir) * 0.5), 1);
gs_out.frag_position = pos_tmp.xyz;
gl_Position = projView * pos_tmp;
EmitVertex();
Expand Down

0 comments on commit ef54851

Please sign in to comment.
0