Archived
1
0
Fork 0
This repository has been archived on 2025-09-02. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
skcblitz/shaders/grid.fsh

39 lines
1.6 KiB
Text
Raw Permalink Normal View History

2025-09-02 14:43:36 +02:00
out vec4 FragColor;
in vec3 vertex;
in vec2 tex_coord;
uniform float time;
#define GLM_PI 3.14159265358979323846264338327950288
#define GLM_SQRT2 1.41421356237309504880168872420969808
#define vis_div 24.0
float v2rand(vec2 uv) {
return fract(sin(dot(uv, vec2(12.9898,78.233))) * 43758.5453123);
}
float avg(vec4 v) {
return ((v.r + v.g + v.b) / 3.0) * v.a;
}
float gauss(float v, float b, float c) {
return (1.0 / (c * sqrt(2.0 * GLM_PI))) * exp(-(pow(v - b, 2.0) / (2.0 * pow(c, 2.0))));
}
float dgauss(float v, float b, float c) {
return b + v * c;
}
float inside(vec2 vec, vec2 offs, float a, float b, float scale, float x1, float x2, float y1, float y2) {
vec2 cscaled = (mod(vec + offs + 1.0, 1.0)) * scale;
return (x2 < x1 ? (cscaled.x >= x1 || cscaled.x <= x2) : (cscaled.x >= x1 && cscaled.x <= x2)) || (y2 < y1 ? (cscaled.y >= y1 || cscaled.y <= y2) : (cscaled.y >= y1 && cscaled.y <= y2)) || (abs(cscaled.y - (cscaled.x - (x2 < x1 ? (x1 - x2) : (x2 - x1)) * GLM_SQRT2 * (x2 < x1 ? 0.0 : (x1 < scale / 2.0 ? x1 : (x2 - scale))))) < GLM_SQRT2) ? b : a;
}
void main() {
vec2 shift = vec2(v2rand(tex_coord + fract(time)) * 2.0 - 1.0, v2rand(tex_coord + 0.5 + fract(time)) * 2.0 - 1.0);
shift = vec2(dgauss(shift.x, 0.0, 1.0), dgauss(shift.y, 0.0, 1.0)) * 0.015;
vec3 cl = vec3(inside(tex_coord / vis_div, shift, 0.0, 1.0, 64.0, 1.0, 3.0, 1.0, 3.0), inside(tex_coord / vis_div, shift, 0.0, 1.0, 64.0, 63.0, 1.0, 63.0, 1.0), inside(tex_coord / vis_div, shift, 0.0, 1.0, 64.0, 61.0, 63.0, 61.0, 63.0));
FragColor = vec4(mix(vec3(0.0, 0.0, clamp(0.1 + 0.2 * (vertex.y + 64.0) / 128.0, 0.0, 1.0)), cl, clamp(cl.x + cl.y + cl.z, 0.0, 1.0)), 1.0);
}