Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This code works in Shader Editor
- #ifdef GL_FRAGMENT_PRECISION_HIGH
- precision highp float;
- #else
- precision mediump float;
- #endif
- uniform vec2 resolution;
- uniform float time;
- // Matrix settings
- const float size = 0.03225;
- const float padding = 0.05;
- // Sine properties
- const float scale = 0.4;
- const float speed = 1.0;
- const float freq = 2.0;
- const float offset = 0.5;
- const float lineWidth = 0.02;
- // Returns a value 1..0..-inf
- // that represents how far a and b are from each other
- // 1 means a == b and 0 means abs(a - b) == epsilon
- float eq(float a, float b, float epsilon)
- {
- return (epsilon - abs(a - b)) / epsilon;
- }
- // This function is called when
- // the current pixel is within a matrix dot
- vec4 draw(vec2 uv)
- {
- float sine = sin(time * speed + uv.x * freq) * scale + offset;
- float aa = eq(sine, uv.y, 0.02);
- if(aa > 0.0)
- return mix(vec4(0.05), vec4(0.1, 0.8, 0.6, 1.0), aa);
- return vec4(0.05);
- }
- void main(void) {
- float aspect = resolution.y / resolution.x;
- vec2 uv = gl_FragCoord.xy / resolution.xy;
- vec2 uvac = uv * vec2(1.0, aspect);
- // UV coordinates repeated in a square grid
- vec2 uv_grid = mod(uvac, size) * (1.0 / size);
- // Pixelated UV coords, where a pixel is equal to a dot
- vec2 uv_px = vec2(
- size * floor(uv.x / size),
- size / aspect * floor(uv.y / size * aspect)
- );
- // Is the pixel within a dot?
- if(distance(uv_grid, vec2(0.5)) < size * (1.0 / size / 2.0) - padding)
- gl_FragColor = vec4(draw(uv_px));
- }
Advertisement
Add Comment
Please, Sign In to add comment