-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathshaders.mjs
51 lines (41 loc) · 1.12 KB
/
shaders.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// this is just for code highlighting in VSCode
// via the glsl-literal extension
const glsl = x => x;
export const frag = glsl`
precision highp float;
const float PI = 3.141592654;
uniform float width;
uniform float height;
uniform float time;
vec2 repeat(in vec2 p, in vec2 c) {
return mod(p, c) - 0.5 * c;
}
// normalize coords and correct for aspect ratio
vec2 normalizeScreenCoords() {
float aspectRatio = width / height;
vec2 result = 2.0 * (gl_FragCoord.xy / vec2(width, height) - 0.5);
result.x *= aspectRatio;
return result;
}
float rand() {
return fract(sin(dot(gl_FragCoord.xy + sin(time),vec2(12.9898,78.233))) * 43758.5453);
}
vec3 palette(float x) {
return vec3(
.5 + .5 * sin(-.1 + x*PI),
.5 + .5 * sin(2.0 + .5 * x*PI),
.5 * .5 * sin(3.0 + x*PI));
}
void main() {
vec2 p0 = normalizeScreenCoords();
vec2 p = repeat(p0, vec2(0.25));
gl_FragColor = vec4((.75 + .25 * sin(p.x * p.y * 180.0 + time * .5)) * palette(time *.01 + .1 * p0.x * p0.y), 1.0);
}
`
export const vert = glsl`
precision mediump float;
attribute vec2 position;
void main () {
gl_Position = vec4(position, 0, 1.0);
}
`