Skip to content

Instantly share code, notes, and snippets.

@aolo2
Created August 22, 2023 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aolo2/698be42b7a703e957b1649e10818a8bf to your computer and use it in GitHub Desktop.
Save aolo2/698be42b7a703e957b1649e10818a8bf to your computer and use it in GitHub Desktop.
#version 300 es
precision highp float;
uniform sampler2D u_texture_points;
uniform highp usampler2D u_texture_indices;
in vec2 v_texcoord;
in vec3 v_color;
flat in float v_thickness;
flat in int v_vertexid;
out vec4 FragColor;
void main() {
float mindist = 99999999.9;
uvec4 indices = texelFetch(u_texture_indices, ivec2(v_vertexid / 6, 0), 0);
uint v_from = indices.x;
uint v_to = indices.y;
for (uint i = v_from; i < v_to - uint(1); ++i) {
uint x1 = i % uint(8192);
uint y1 = i / uint(8192);
uint x2 = x1 + uint(1);
uint y2 = y1;
if (x2 == uint(8192)) {
x2 = uint(0);
y2 = y1 + uint(1);
}
vec4 a = texelFetch(u_texture_points, ivec2(x1, y1), 0);
vec4 b = texelFetch(u_texture_points, ivec2(x2, y2), 0);
vec2 pa = v_texcoord - a.xy, ba = b.xy - a.xy;
float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
float dist = length(pa - ba * h) - v_thickness;
mindist = min(mindist, dist);
}
float fade = 0.5 * length(fwidth(v_texcoord));
float alpha = 1.0 - smoothstep(-fade, fade, mindist);
FragColor = vec4(v_color * alpha, alpha);
// FragColor = vec4(v_color * alpha, 0.1 + alpha);
// FragColor = vec4(v_color, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment