-
Notifications
You must be signed in to change notification settings - Fork 1
/
shader.frag
102 lines (82 loc) · 4.05 KB
/
shader.frag
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifdef GL_ES
precision mediump float;
#endif
//This shader makes use of noise functions with the following license, found here: https://www.shadertoy.com/view/4sfGzS
// The MIT License
// Copyright © 2013 Inigo Quilez
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Start of code Inigo Quilez
float hash(vec3 p)// replace this by something better
{
p = fract(p * 0.3183099 + 0.1);
p *= 17.0;
return fract(p.x * p.y * p.z * (p.x + p.y + p.z));
}
float noise(in vec3 x)
{
vec3 i = floor(x);
vec3 f = fract(x);
f = f*f * (3.0 - 2.0 * f);
return mix(mix(mix(hash(i + vec3(0, 0, 0)),
hash(i + vec3(1, 0, 0)), f.x),
mix(hash(i + vec3(0, 1, 0)),
hash(i + vec3(1, 1, 0)), f.x), f.y),
mix(mix(hash(i + vec3(0, 0, 1)),
hash(i + vec3(1, 0, 1)), f.x),
mix(hash(i + vec3(0, 1, 1)),
hash(i + vec3(1, 1, 1)), f.x), f.y), f.z);
}
const mat3 m = mat3(0.00, 0.80, 0.60,
- 0.80, 0.36, - 0.48,
- 0.60, - 0.48, 0.64);
float octaveNoise(in vec2 realuv, in float time) {
float f = 0.0;
//scale
vec2 uv = realuv * 8.0;
mat2 m = mat2(1.6, 1.2, - 1.2, 1.6);
f = 0.7 * noise(vec3(uv, time * 0.6));
uv = m*uv;
f += 0.3 * noise(vec3(uv, time * 0.2 + 100.0));
return 0.5 + 0.5 * f;
}
// ---- End of code by Inigo Quilez
float findEdgeOfNoise(in float n, in float a, in float b, in float borderWidth) {
float f1 = smoothstep(a, b, n);
float f2 = smoothstep(b, b + borderWidth, n);
return f1 - f2;
}
uniform vec2 u_resolution; // This is passed in as a uniform from the sketch.js file
uniform float u_time; // This is passed in as a uniform from the sketch.js file
uniform int u_layer; // makes each shader (layer) distinct
float Line(float v, float ctr, float end) {
return smoothstep(ctr, ctr + end, v);
}
void main() {
// position of the pixel divided by resolution, to get normalized positions on the canvas
//vec2 uv = gl_FragCoord.xy / u_resolution.xy / 2.;
vec2 uv = (gl_FragCoord.xy - u_resolution.xy) / min(u_resolution.x, u_resolution.y);
vec4 col = vec4(0.0, 0.0, 0.0, 0.0);
float time = u_time;
float layerSpacing = 0.5 / 8.0;
vec3 plateCol = vec3(0.0);
//there is no plate offset in x or y terms, only in 3ds dimension (time)
//vec2 plateOffset = vec2(0., 3.45-layerSpacing * float(u_layer));
vec2 apparentUV = 0.3 * uv.xy; // + plateOffset;
//TODO: layers should all be running with the same time input to noise
float apparentTime = time * 1.0 + 0.3 * float(u_layer);
//generate noise, find the stepped body of it, find the edge of it.
float f = octaveNoise(apparentUV, apparentTime);
float n1 = smoothstep(0.79, 0.791, f);
float n2 = smoothstep(0.681, 0.68, smoothstep(0.62, 0.621, f));
//float nBorder = findEdgeOfNoise(f, 0.782, 0.79, 0.0001);
float nBorder1 = findEdgeOfNoise(f, 0.79, 0.791, 0.002);
float nBorder2 = findEdgeOfNoise(f, 0.62, 0.621, 0.002);
vec4 c1 = vec4(89, 79, 79, 255) / 255.0;
vec4 c2 = vec4(69, 173, 168, 255) / 255.0;
vec4 c3 = vec4(229, 252, 194, 255) / 255.0;
col = mix(col, c2, n1);
col = mix(col, c3, n2);
col = mix(col, c1, nBorder1);
col = mix(col, c1, nBorder2);
gl_FragColor = col; // R,G,B,A
}