-
-
Save SimonDanisch/07af22d2db25802c5c45eb3cf250a3a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#version 330 | |
layout(lines) in; | |
layout(triangle_strip, max_vertices = 4) out; | |
// dependant type declarations | |
// Julia name: Geom2Fragment | |
struct Geom2Fragment{ | |
float thickness; | |
vec4 color; | |
vec2 uv; | |
}; | |
// Julia name: Uniforms | |
struct Uniforms{ | |
mat4 model; | |
int max_primtives; | |
float maxlength; | |
float thickness; | |
float pattern_length; | |
}; | |
// Julia name: Canvas | |
struct Canvas{ | |
vec2 resolution; | |
mat4 projection; | |
mat4 view; | |
mat4 projectionview; | |
}; | |
// Julia name: Vert2Geom | |
struct Vert2Geom{ | |
vec4 position; | |
vec4 color; | |
float thickness; | |
}; | |
in Vert2Geom geom_in[]; | |
out Geom2Fragment geom_out; | |
// uniform inputs: | |
layout (std140) uniform _gensymed_UniformArg1{ | |
Canvas canvas; | |
}; | |
layout (std140) uniform _gensymed_UniformArg2{ | |
Uniforms uniforms; | |
}; | |
// dependant function declarations | |
void emit_vertex2(Vert2Geom[2] geom_in, Canvas canvas, Uniforms uniforms, vec2 position, vec2 uv, int index) | |
{ | |
Geom2Fragment fragout; | |
vec4 outpos; | |
vec4 inpos; | |
inpos = geom_in[index - 1].position; | |
outpos = vec4((position / canvas.resolution) * inpos.w, inpos.z, inpos.w); | |
fragout = Geom2Fragment(geom_in[index - 1].thickness + 2.0, geom_in[index - 1].color, uv); | |
gl_Position = outpos; | |
geom_out = fragout; | |
EmitVertex(); | |
} | |
vec2 screen_space(vec4 vertex, Canvas canvas) | |
{ | |
return (vertex.xy / vertex.w) * canvas.resolution; | |
} | |
// geometry main function: | |
void main() | |
{ | |
float uv1; | |
float uv0; | |
float l; | |
vec2 n0; | |
vec2 v0; | |
vec2 vun0; | |
float thickness_aa1; | |
float thickness_aa0; | |
vec2 p1; | |
vec2 p0; | |
p0 = screen_space(geom_in[0].position, canvas); | |
p1 = screen_space(geom_in[1].position, canvas); | |
thickness_aa0 = geom_in[0].thickness + 2.0; | |
thickness_aa1 = geom_in[1].thickness + 2.0; | |
vun0 = p1 - p0; | |
v0 = normalize(vun0); | |
n0 = vec2(-(v0.y), v0.x); | |
l = length(p1 - p0); | |
l = l / (uniforms.pattern_length * 10.0); | |
uv0 = thickness_aa0 / geom_in[0].thickness; | |
uv1 = thickness_aa1 / geom_in[1].thickness; | |
emit_vertex2(geom_in, canvas, uniforms, p0 + thickness_aa0 * n0, vec2(0, -uv0), 1); | |
emit_vertex2(geom_in, canvas, uniforms, p0 - thickness_aa0 * n0, vec2(0, uv0), 1); | |
emit_vertex2(geom_in, canvas, uniforms, p1 + thickness_aa1 * n0, vec2(l, -uv1), 2); | |
emit_vertex2(geom_in, canvas, uniforms, p1 - thickness_aa1 * n0, vec2(l, uv1), 2); | |
EndPrimitive(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment