-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcomputeShaders.js
136 lines (103 loc) · 2.52 KB
/
computeShaders.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import {hash12, cnoise4} from './glslNoise.js';
import {PI} from './glslUtils.js';
function createPosTargetShader ()
{
return `
${PI}
${hash12}
uniform float time;
void main ()
{
float nPoints = resolution.x * resolution.y;
float i = (gl_FragCoord.y * resolution.x) + gl_FragCoord.x;
vec2 uv = gl_FragCoord.xy / resolution.xy;
vec3 pos = vec3(0.0);
float angle = (i / nPoints) * PI * 2.0;
float rad = sin(time * 0.0001) * 200.0;
rad = 80.0 + hash12(vec2(i * 0.123, i * 3.453)) * 80.0;
pos.x = cos(angle) * rad;
pos.y = sin(angle) * rad;
pos.z = 0.0;
gl_FragColor = vec4(pos, 1.0);
}
`;
}
function createAccShader ()
{
return `
${PI}
${cnoise4}
${hash12}
uniform float time;
void main ()
{
float nPoints = resolution.x * resolution.y;
float i = (gl_FragCoord.y * resolution.x) + gl_FragCoord.x;
vec2 uv = gl_FragCoord.xy / resolution.xy;
vec3 a = vec3(0.0);
vec4 p = texture2D(pos, uv);
vec4 tar = texture2D(posTarget, uv);
vec3 turb;
float t = time * 0.0001;
float n = hash12(uv * 0.02 + i);
float s = .2;
turb.x = cnoise(vec4(p.xyz * 0.006 + n * 35.4, t));
turb.y = cnoise(vec4(p.xyz * 0.007 + n * 32.3, t));
turb.z = cnoise(vec4(p.xyz * 0.006 + n * 43.3, t));
turb *= pow(cnoise(vec4(p.xyz * 0.01, time * 0.0003)), 3.0) * s * 20.0;
a += turb;
vec3 back = tar.xyz - p.xyz;
//back *= 0.001;
back *= ((1.0 + pow(cnoise(vec4(tar.xyz * 0.002, time * 0.0001) ), 1.0)) / 2.0) * 0.003;
a += back;
vec3 collect;
collect = p.xyz * -.0003;
//a += collect;
gl_FragColor = vec4(a, 1.0);
}
`;
}
function createVelShader ()
{
return `
${PI}
uniform float time;
void main ()
{
float nPoints = resolution.x * resolution.y;
float i = (gl_FragCoord.y * resolution.x) + gl_FragCoord.x;
vec2 uv = gl_FragCoord.xy / resolution.xy;
vec4 a = texture2D(acc, uv);
vec4 v = texture2D(vel, uv);
v += a;
v *= .97;
gl_FragColor = vec4(v.xyz, 1.0);
}
`;
}
function createPosShader ()
{
return `
${PI}
uniform float time;
uniform int frame;
void main ()
{
float nPoints = resolution.x * resolution.y;
float i = (gl_FragCoord.y * resolution.x) + gl_FragCoord.x;
vec2 uv = gl_FragCoord.xy / resolution.xy;
vec4 p;
if (frame < 2)
{
p = texture2D(posTarget, uv);
}
else
{
p = texture2D(pos, uv);
p += texture2D(vel, uv);
}
gl_FragColor = vec4(p.xyz, 1.0);
}
`;
}
export {createPosTargetShader, createAccShader, createVelShader, createPosShader};