From cbe1a5f96fc6e518744bfe5d8ee78364c1fd298b Mon Sep 17 00:00:00 2001 From: MMT Date: Wed, 27 Jul 2022 12:25:05 +0430 Subject: [PATCH] write stipple line with shaders --- lineStipple.fs | 16 ++++++++++++++++ lineStipple.vs | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 lineStipple.fs create mode 100644 lineStipple.vs diff --git a/lineStipple.fs b/lineStipple.fs new file mode 100644 index 0000000..633a7ee --- /dev/null +++ b/lineStipple.fs @@ -0,0 +1,16 @@ +#version 330 core +in vec4 color; + +in float dist; +uniform vec2 u_resolution; +uniform float u_dashSize; +uniform float u_gapSize; + +out vec4 FragColor; +void main() +{ + if (fract(dist / (u_dashSize + u_gapSize)) > u_dashSize/(u_dashSize + u_gapSize)) + discard; + + FragColor = color; +} diff --git a/lineStipple.vs b/lineStipple.vs new file mode 100644 index 0000000..71f52ca --- /dev/null +++ b/lineStipple.vs @@ -0,0 +1,16 @@ +#version 330 core +layout (location = 0) in vec3 vertices; +layout (location = 1) in float distances; +uniform vec4 ourColor; + +out float dist; +out vec4 color; + +uniform mat4 MVP; + +void main() +{ + dist = distances; + gl_Position = MVP * vec4(vertices,1.0); + color = ourColor; +} \ No newline at end of file