-
Notifications
You must be signed in to change notification settings - Fork 0
/
electric.gdshader
72 lines (61 loc) · 1.42 KB
/
electric.gdshader
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
shader_type canvas_item;
uniform sampler2D noiseTexture: repeat_enable;
uniform vec3 baseColorRGB: source_color = vec3(0.2, 0.1, 0.4);
uniform float speed = 0.15;
mat2 makem2(in float theta)
{
float c = cos(theta);
float s = sin(theta);
vec2 part1 = vec2(c, -s);
vec2 part2 = vec2(s, c);
return mat2(part1, part2);
}
float noise(in vec2 x)
{
return texture(noiseTexture, x * 0.01).x;
}
float fbm(in vec2 p)
{
float z = 2.0;
float rz = 0.0;
vec2 bp = p;
for (float i = 1.0; i < 6.0; i++)
{
rz += abs((noise(p) - 0.5) * 2.0) / z;
z = z * 2.0;
p = p * 2.0;
}
return rz;
}
float dualfbm(in vec2 p)
{
//get two rotated fbm calls and displace the domain
vec2 p2 = p * 0.7;
vec2 basis = vec2(fbm(p2 - (TIME * speed) * 1.6), fbm(p2 + (TIME * speed) * 1.7));
basis = (basis - 0.5) * 0.2;
p += basis;
//coloring
return fbm(p * makem2((TIME * speed) * 0.2));
}
float circ(vec2 p)
{
float tau = 6.2831853;
float r = length(p);
r = 0.5 * log(r);
return abs(mod(r * 4.0, tau) - 3.14) * 3.0 + 0.2;
}
void fragment()
{
//setup system
vec2 p = UV.xy / (1.0 / TEXTURE_PIXEL_SIZE).xy - 0.5;
p.x *= (1.0 / TEXTURE_PIXEL_SIZE).x / (1.0 / TEXTURE_PIXEL_SIZE).y;
p *= 4.0;
float rz = dualfbm(p);
//rings
//p /= exp(mod((TIME * speed) * 10.0, 3.14159));
//rz *= pow(abs((0.1 - circ(p))), 0.9);
//final color
vec3 col = baseColorRGB / rz;
col = pow(abs(col), vec3(0.99));
COLOR = vec4(col, clamp(0.3 - rz, 0.0, 1.0));
}