-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.html
205 lines (169 loc) · 5.53 KB
/
main.html
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="gl-matrix.js"></script>
<script id="particle-shader-fs" type="x-shader/x-fragment">
precision mediump float;
varying vec4 r1;
varying vec4 r2;
varying vec4 r3;
varying vec4 r4;
varying vec4 r5;
varying vec4 r6;
varying vec4 r7;
varying vec4 r8a;
varying vec4 r9;
void main(void) {
gl_FragColor = vec4(0.0, 0.0, 0.0,0.0);
if(gl_PointCoord.t < 0.35) {
if(gl_PointCoord.s < 0.35)
gl_FragColor = r1;
else if(gl_PointCoord.s > 0.65)
gl_FragColor = r3;
else
gl_FragColor = r2;
}
else if(gl_PointCoord.t > 0.65) {
if(gl_PointCoord.s < 0.35)
gl_FragColor = r7;
else if(gl_PointCoord.s > 0.65)
gl_FragColor = r9;
else
gl_FragColor = r8a;
}
else {
if(gl_PointCoord.s < 0.35)
gl_FragColor = r4;
else if(gl_PointCoord.s > 0.65)
gl_FragColor = r6;
else
gl_FragColor = r5;
}
}
</script>
<script id="particle-shader-vs" type="x-shader/x-vertex">
attribute vec4 aVertexPosition;
uniform mat4 uPMatrix;
uniform mat4 uAttractors;
uniform int uCallCount;
uniform sampler2D uSampler;
varying vec4 r1;
varying vec4 r2;
varying vec4 r3;
varying vec4 r4;
varying vec4 r5;
varying vec4 r6;
varying vec4 r7;
varying vec4 r8a;
varying vec4 r9;
vec4 EncodeFloatRGBA( float v ) {
vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * v;
enc = fract(enc);
enc -= enc.yzww * vec4(1.0/255.0,1.0/255.0,1.0/255.0,0.0);
return enc;
}
float DecodeFloatRGBA( vec4 rgba ) {
return dot( rgba, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/16581375.0) );
}
void main(void) {
gl_PointSize = 3.0;
vec3 pos;
vec3 vel;
if(uCallCount == 0)
{
pos = vec3(aVertexPosition[0], aVertexPosition[1], aVertexPosition[2]);
vel = vec3(0.0,0.0,0.0);
}
else
{
vec2 texture_pos = vec2(
mod(aVertexPosition[3], 4095.0 / 3.0),
(aVertexPosition[3] - mod(aVertexPosition[3], 4095.0/ 3.0)) / (4095.0 / 3.0)
);
pos = vec3(
DecodeFloatRGBA(texture2D(uSampler, (floor(vec2(texture_pos.x*3.0 + 0.0, texture_pos.y*3.0+2.0)) +0.5) / 4096.0)),
DecodeFloatRGBA(texture2D(uSampler, (floor(vec2(texture_pos.x*3.0 + 1.0, texture_pos.y*3.0+2.0)) +0.5) / 4096.0)),
DecodeFloatRGBA(texture2D(uSampler, (floor(vec2(texture_pos.x*3.0 + 2.0, texture_pos.y*3.0+2.0)) +0.5) / 4096.0))
);
vel = vec3(
DecodeFloatRGBA(texture2D(uSampler, (floor(vec2(texture_pos.x*3.0 + 0.0, texture_pos.y*3.0+0.0)) +0.5) / 4096.0)),
DecodeFloatRGBA(texture2D(uSampler, (floor(vec2(texture_pos.x*3.0 + 1.0, texture_pos.y*3.0+0.0)) +0.5) / 4096.0)),
DecodeFloatRGBA(texture2D(uSampler, (floor(vec2(texture_pos.x*3.0 + 2.0, texture_pos.y*3.0+0.0)) +0.5) / 4096.0))
);
pos = (pos * 1000.0) - 500.0;
vel = (vel * 1000.0) - 500.0;
}
vec3 acc = vec3(0.0,0.0,0.0);
for(int an = 0; an < 4; an++)
{
vec3 at_pos = vec3(uAttractors[an][0], uAttractors[an][1], uAttractors[an][2]);
float strenght = uAttractors[an][3];
vec3 diff = at_pos - pos;
float dist = length(diff);
acc = acc + (diff * strenght ) / ( dist * dist);
}
vel = vel + acc;
pos = pos + vel;
vec3 packed_pos = (pos + 500.0) / 1000.0;
vec3 packed_vel = (vel + 500.0) / 1000.0;
r1 = EncodeFloatRGBA(packed_pos.x);
r2 = EncodeFloatRGBA(packed_pos.y);
r3 = EncodeFloatRGBA(packed_pos.z);
r4 = vec4(1.0, 1.0, 1.0, 1.0);
r5 = vec4(1.0, 1.0, 1.0, 1.0);
r6 = vec4(1.0, 1.0, 1.0, 1.0);
r7 = EncodeFloatRGBA(packed_vel.x);
r8a = EncodeFloatRGBA(packed_vel.y);
r9 = EncodeFloatRGBA(packed_vel.z);
vec2 return_pos = vec2(
mod(aVertexPosition[3], 4095.0 / 3.0),
(aVertexPosition[3] - mod(aVertexPosition[3], 4095.0/ 3.0)) / (4095.0 / 3.0)
);
gl_Position = uPMatrix * vec4(1.5 + 3.0 * return_pos.x , 1.5 + 3.0 * return_pos.y, 0.0, 1.0);
}
</script>
<script id="render-shader-fs" type="x-shader/x-fragment">
precision mediump float;
void main(void) {
gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0);
}
</script>
<script id="render-shader-vs" type="x-shader/x-vertex">
attribute vec4 aVertexPosition;
uniform mat4 uPMatrix;
uniform mat4 uMVMatrix;
uniform sampler2D uSampler;
vec4 EncodeFloatRGBA( float v ) {
vec4 enc = vec4(1.0, 255.0, 65025.0, 16581375.0) * v;
enc = fract(enc);
enc -= enc.yzww * vec4(1.0/255.0,1.0/255.0,1.0/255.0,0.0);
return enc;
}
float DecodeFloatRGBA( vec4 rgba ) {
return dot( rgba, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/16581375.0) );
}
void main(void) {
gl_PointSize = 1.0;
vec2 texture_pos = vec2(
floor(mod(aVertexPosition[3], 4095.0 / 3.0)),
floor((aVertexPosition[3] - mod(aVertexPosition[3], 4095.0/ 3.0)) / (4095.0 / 3.0))
);
vec3 pos = vec3(
DecodeFloatRGBA(texture2D(uSampler, (floor(vec2(texture_pos.x*3.0 + 0.0, texture_pos.y*3.0+2.0)) +0.5) / 4096.0)),
DecodeFloatRGBA(texture2D(uSampler, (floor(vec2(texture_pos.x*3.0 + 1.0, texture_pos.y*3.0+2.0)) +0.5) / 4096.0)),
DecodeFloatRGBA(texture2D(uSampler, (floor(vec2(texture_pos.x*3.0 + 2.0, texture_pos.y*3.0+2.0)) +0.5) / 4096.0))
);
pos = (pos * 1000.0) - 500.0;
//pos.z = 0.0;
gl_Position = uPMatrix * uMVMatrix * vec4(pos, 1.0);
}
</script>
<script type="text/javascript" src="shader.core.js"></script>
<script type="text/javascript" src="shader.particles.js"></script>
<script type="text/javascript" src="shader.render.js"></script>
<script type="text/javascript" src="core.js"></script>
</head>
<body onload="main();">
<canvas id="canvas_main" style="border: none;" width="1280" height="720"></canvas>
</body>
</html>