Skip to content

Instantly share code, notes, and snippets.

@theoparis
Created July 11, 2024 05:14
Show Gist options
  • Save theoparis/99bf448f57b83f34140624f2191a6991 to your computer and use it in GitHub Desktop.
Save theoparis/99bf448f57b83f34140624f2191a6991 to your computer and use it in GitHub Desktop.
wavy aah line shader with glslViewer
// vim:ft=glsl
uniform float u_time;
uniform vec2 u_resolution;
float line(vec2 p, vec2 a, vec2 b) {
vec2 a2b = b - a;
vec2 a2p = p - a;
float h = clamp(dot(a2p,a2b) / dot(a2b,a2b), 0.0, 1.0);
vec2 p1 = mix(a, b, h);
return length(p1 - p);
}
float rand(float n) {
return fract(sin(n) * 43758.5453123);
}
float noise(float p){
float fl = floor(p);
float fc = fract(p);
return mix(rand(fl), rand(fl + 1.0), fc);
}
void main() {
vec2 uv = gl_FragCoord.xy / u_resolution.xy;
vec2 uv2 = gl_FragCoord.xy / u_resolution.xy;
float speed = 1.0;
float line_size = 0.005;
uv.y += sin(uv.x * 10.0 + u_time * speed) * 0.06 * noise(uv.x + u_time);
uv2.y += cos(uv.x * 10.0 + u_time * speed) * 0.06 * noise(uv.x + u_time);
float line = line(uv, vec2(0.0, 0.9), vec2(1.0, 0.9));
float line2 = line(uv2, vec2(0.0, 0.9), vec2(1.0, 0.9));
float distance_field = length(max(abs(uv) - 1.0, 0.0) / 0.3);
float glow = 1.0 - distance_field;
gl_FragColor = mix(vec4(0.0, 0.0, 0.0, 1.0), vec4(1.0, 1.0, 1.0, 1.0) / line * line_size, glow);
gl_FragColor += vec4(1.0, 1.0, 1.0, 1.0) / line2 * line_size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment