Browse Source

Improved shader (thanks BYP!)

ssao
A.Olokhtonov 10 months ago
parent
commit
40dd278f21
  1. 19
      client/webgl_shaders.js

19
client/webgl_shaders.js

@ -197,23 +197,8 @@ const sdf_fs_src = `#version 300 es @@ -197,23 +197,8 @@ const sdf_fs_src = `#version 300 es
vec2 b = v_line.zw;
vec2 pa = v_texcoord - a.xy, ba = b.xy - a.xy;
float h = dot(pa, ba) / dot(ba, ba);
/*
float dist = length(pa - ba * h) - v_thickness.y / 2.0;
*/
float dist;
float r1 = v_thickness.x;
float r2 = v_thickness.y;
if (h < 0.0) {
dist = length(v_texcoord - a) - r1;
} else if (0.0 <= h && h < 1.0) {
vec2 Q = a + ba * h;
dist = length(v_texcoord - Q) - (r1 + (r2 - r1) * length(Q - a) / length(ba));
} else {
dist = length(v_texcoord - b) - r2;
}
float h = clamp(dot(pa, ba) / dot(ba, ba), 0.0, 1.0);
float dist = length(v_texcoord - (a + ba * h)) - mix(v_thickness.x, v_thickness.y, h);
float fade = 0.5 * length(fwidth(v_texcoord));
float alpha = 1.0 - smoothstep(-fade, fade, dist);

Loading…
Cancel
Save