Created
April 7, 2016 07:18
-
-
Save xaxxon/b8df6cd3880cc75876ea513eb249e99a to your computer and use it in GitHub Desktop.
fat line shaders
This file contains hidden or 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
const char * LineSegmentList::VERTEX_SHADER = R"VERTEXSHADER(#version 410 | |
in vec2 vertex; | |
in vec2 normal; | |
in vec4 color; | |
in float width; | |
out vec2 normal_g; | |
out vec4 color_g; | |
out float width_g; | |
void main(){ | |
normal_g = normal / length(normal); | |
color_g = color; | |
width_g = width; | |
gl_Position = vec4(vertex, 0, 1); | |
} | |
)VERTEXSHADER"; | |
const char * LineSegmentList::GEOMETRY_SHADER = R"GEOMETRYSHADER(#version 410 | |
layout(lines) in; | |
in vec2 normal_g[]; | |
in float width_g[]; | |
in vec4 color_g[]; | |
uniform mat4 mvp_matrix; | |
layout(triangle_strip, max_vertices = 4) out; | |
out vec2 normal_f; | |
out float width_f; | |
out vec4 color_f; | |
void main() | |
{ | |
width_f = width_g[0]; | |
color_f = color_g[0]; | |
normal_f = -normal_g[0]; | |
gl_Position = mvp_matrix * (gl_in[0].gl_Position - vec4(((normal_g[0]/length(normal_g[0])) * width_g[0]), 0, 0)); | |
EmitVertex(); | |
normal_f = -normal_g[1]; | |
gl_Position = mvp_matrix * (gl_in[1].gl_Position - vec4(((normal_g[0]/length(normal_g[0])) * width_g[0]), 0, 0)); | |
EmitVertex(); | |
normal_f = normal_g[0]; | |
gl_Position = mvp_matrix * (gl_in[0].gl_Position + vec4(((normal_g[0]/length(normal_g[0])) * width_g[0]), 0, 0)); | |
EmitVertex(); | |
normal_f = normal_g[1]; | |
gl_Position = mvp_matrix * (gl_in[1].gl_Position + vec4(((normal_g[0]/length(normal_g[0])) * width_g[0]), 0, 0)); | |
EmitVertex(); | |
} | |
)GEOMETRYSHADER"; | |
const char * LineSegmentList::FRAGMENT_SHADER = R"FRAGSHADER(#version 410 | |
in vec4 color_f; | |
in vec2 normal_f; | |
in float width_f; | |
out vec4 fragment_color; | |
void main(){ | |
fragment_color = vec4(1,0,0, (width_f-length(normal_f)) / width_f ); | |
//fragment_color = vec4(1,0,0,0.5); | |
} | |
)FRAGSHADER"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment