-
-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathresample2.html
217 lines (215 loc) · 6.41 KB
/
resample2.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
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>MathBox - RTT Feedback History</title>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/[email protected]/build/three.min.js"
></script>
<!--
- a minified version mathbox.min.js is also available;
- recommend using a specific version (not @latest) in public sites
-->
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/mathbox@latest/build/bundle/mathbox.js"
></script>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/mathbox@latest/build/mathbox.css"
/>
<meta name="viewport" content="initial-scale=1, maximum-scale=1" />
</head>
<script type="application/glsl" id="map-color">
uniform float modulate1;
uniform float modulate2;
vec4 getSample(vec3 xyz);
vec4 getFramesSample(vec3 xyz) {
vec4 color = (
getSample(xyz) +
getSample(xyz + vec3(0.0, 0.0, 1.0)) +
getSample(xyz + vec3(0.0, 0.0, 2.0)) +
getSample(xyz + vec3(0.0, 0.0, 3.0))
) / 4.0;
color = color * color * color * 1.15;
float v = color.x + color.y + color.z;
vec3 c = vec3(v*v + color.x * .2, v*v, v*v*v + color.z) * .333;
c = mix(c, mix(sqrt(c.yzx * c), c.zxy, modulate1), modulate2);
c = mix(c, mix(c.yzx, c.zxy, modulate1), modulate2);
return vec4(c, 1.0);
}
</script>
<body>
<script>
mathbox = MathBox.mathBox({
plugins: ["core"],
});
three = mathbox.three;
three.renderer.setClearColor(new THREE.Color(0x000000), 1.0);
mathbox
.set({
scale: 720,
})
.rtt({
id: "render",
minFilter: "nearest",
magFilter: "nearest",
type: "unsignedByte",
})
.camera(
{
lookAt: [0, 0, 0],
},
{
position: function (t) {
return [Math.cos(t) * 3, 0, Math.sin(t) * 3];
},
}
)
.cartesian({
range: [
[-2, 2],
[-1, 1],
[-1, 1],
],
scale: [2, 1, 1],
})
.transform({
scale: [0.7, 0.7, 0.7],
})
.grid({
width: 5,
divideX: 2,
divideY: 2,
zBias: 10,
opacity: 0.25,
color: 0xffdfe0,
})
.end()
.end()
.end()
.rtt({
id: "rtt1",
history: 4,
type: "unsignedByte",
minFilter: "linear",
magFilter: "linear",
})
.shader(
{
code: [
"uniform vec3 dataResolution;",
"uniform vec3 dataSize;",
"uniform float cosine;",
"uniform float sine;",
"vec4 getSample(vec3 xyz);",
"vec4 getFramesSample(vec3 xyz) {",
" vec2 pos = xyz.xy * dataResolution.xy - .5;",
" pos = ((pos * dataSize.xy) * mat2(cosine, sine, -sine, cosine) * .999) / dataSize.xy;",
" xyz.xy = (pos + .5) * dataSize.xy;",
" vec4 c = getSample(xyz + vec3( 0.0, 0.0, 1.0));",
" vec3 t = getSample(xyz + vec3( 0.0, 1.5, 0.0)).xyz;",
" vec3 b = getSample(xyz + vec3( 0.0,-1.5, 0.0)).xyz;",
" vec3 l = getSample(xyz + vec3(-1.5, 0.0, 0.0)).xyz;",
" vec3 r = getSample(xyz + vec3( 1.5, 0.0, 0.0)).xyz;",
" return vec4((t + b + l + r) / 2.0 - c.xyz, c.w);",
"}",
].join("\n"),
},
{
cosine: function (t) {
return Math.cos(Math.sin(t * 0.2) * 0.005);
},
sine: function (t) {
return Math.sin(Math.sin(t * 0.2) * 0.005);
},
}
)
.resample({
id: "resample1",
indices: 3,
channels: 4,
})
/**/
.compose()
.compose({
source: "#render",
blending: THREE.AdditiveBlending,
})
.end()
.rtt({
minFilter: "linear",
magFilter: "linear",
type: "unsignedByte",
})
.shader(
{
id: "colormap",
code: [
"uniform float modulate1;",
"uniform float modulate2;",
"uniform float modulate3;",
"uniform float modulate4;",
"vec4 getSample(vec3 xyz);",
"vec4 getFramesSample(vec3 xyz) {",
" vec4 color = (",
" getSample(xyz) +",
" getSample(xyz + vec3(0.0, 0.0, 1.0)) +",
" getSample(xyz + vec3(0.0, 0.0, 2.0)) +",
" getSample(xyz + vec3(0.0, 0.0, 3.0))",
" ) / 4.0;",
" color = color * color * color * 1.15;",
" float v = color.x + color.y + color.z;",
" vec3 c = vec3(v*v + color.x * .2, v*v, v*v*v + color.z) * .333;",
" c = mix(c, mix(sqrt(c.yzx * c), c.zxy, modulate1), modulate2);",
" c = mix(c, mix(c.yzx, c.zxy, modulate1), modulate2);",
" c = mix(c, mix(abs(sin(c.yxz * 2.0)), c.zyx, modulate3), modulate4);",
" return vec4(c, 1.0);",
"}",
].join("\n"),
},
{
modulate1: function (t) {
return Math.cos(t * 0.417) * 0.5 + 0.5;
},
modulate2: function (t) {
return Math.cos(t * 0.617 + Math.sin(t * 0.133)) * 0.5 + 0.5;
},
modulate3: function (t) {
return Math.cos(t * 0.217 + 2.0) * 0.5 + 0.5;
},
modulate4: function (t) {
return (
Math.cos(t * 0.117 + 3.0 + Math.sin(t * 0.133)) * 0.5 + 0.5
);
},
}
)
.resample({
id: "resample2",
source: "#rtt1",
indices: 3,
channels: 4,
})
.compose()
.end()
.shader({
code: [
"vec4 getSample(vec2 xy);",
"vec4 getFramesSample(vec2 xy) {",
" return getSample(xy + vec2(0.5, 0.5));",
"}",
].join("\n"),
})
.resample({
id: "resample3",
indices: 2,
channels: 4,
})
.compose({
source: "#resample2",
});
</script>
</body>
</html>