-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
306 lines (255 loc) · 10.8 KB
/
index.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<!DOCTYPE html>
<html>
<head>
<base target="_blank">
<style type="text/css">
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
overflow: hidden;
background: #000000;
}
.data-image {
display: none;
}
</style>
<script src="lib/jsmodplayer/src/modfile.js"></script>
<script src="lib/jsmodplayer/src/xmfile.js"></script>
<script src="lib/jsmodplayer/src/modplayer.js"></script>
<script src="lib/jsmodplayer/src/support.js"></script>
<script src="lib/cubicvr/CubicVR.js"></script>
<script src="lib/dsp.js"></script>
<script src="lib/popcorn/popcorn.js"></script>
<script src="lib/popcorn/popcorn.baseplayer.js"></script>
<script src="lib/popcorn/popcorn.code.js"></script>
<script src="js/audio.js"></script>
<script src="js/bitFont.js" type="text/javascript" charset="utf-8"></script>
<script src="js/bitFont3D.js" type="text/javascript" charset="utf-8"></script>
<script src="js/AnimationKit.js" type="text/javascript" charset="utf-8"></script>
<script src="js/segment.js"></script>
<script src="js/segment1.js"></script>
<script src="js/segment2.js"></script>
<script src="js/segment3.js"></script>
<script id="cubicvr-core-vs" src="lib/cubicvr/CubicVR_Core.vs" type="x-shader/x-vertex"></script>
<script id="cubicvr-core-fs" src="lib/cubicvr/CubicVR_Core.fs" type="x-shader/x-fragment"></script>
<script id="cubicvr-fx-general-vs" src="lib/cubicvr/post_shaders/fx_general.vs" type="x-shader/x-vertex"></script>
<script id="cubicvr-alpha-depth-fs" src="lib/cubicvr/post_shaders/alpha_depth.fs" type="x-shader/x-fragment"></script>
<script id="cubicvr-invert-fs" src="lib/cubicvr/post_shaders/invert.fs" type="x-shader/x-fragment"></script>
<script id="cubicvr-dof-6tap-fs" src="lib/cubicvr/post_shaders/dof_6tap.fs" type="x-shader/x-fragment"></script>
<script id="cubicvr-ssao-fs" src="lib/cubicvr/post_shaders/ssao.fs" type="x-shader/x-fragment"></script>
<script id="cubicvr-bloom-6tap-fs" src="lib/cubicvr/post_shaders/bloom_6tap.fs" type="x-shader/x-fragment"></script>
<script>
var shaderList = [];
var fxChain;
var shaders = {};
var gl;
var canvas_w, canvas_h, aspect;
var canvas, scene;
var audioData;
document.addEventListener('DOMContentLoaded', function (e) {
canvas = document.createElement('canvas');
canvas.style.position="absolute";
aspect = 1280/720;
canvas_w = window.innerWidth;
canvas_h = canvas_w*(1.0/aspect);
if (canvas_h>window.innerHeight) canvas_h = window.innerHeight;
var toppx = (window.innerHeight/2)-(canvas_h/2);
canvas.width = canvas_w;
canvas.height = canvas_h;
canvas.style.top = toppx+"px";
canvas.style.left = "0px";
gl = CubicVR.GLCore.init(canvas, 'cubicvr-core-vs', 'cubicvr-core-fs');
if (!gl) {
return;
}
// expose the alphaDepth buffer
var shaderDepth = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/alpha_depth.fs",
});
shaders['depth'] = shaderDepth;
// simple color invert
var shaderInvert = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/invert.fs"
});
shaders['invert'] = shaderInvert;
var shaderDOF6 = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/dof_6tap.fs",
init: function(shader) {
shader.addFloat("near_depth");
shader.addFloat("far_depth");
},
onupdate: function(shader) {
// linear depth
var d = CubicVR.vec3.length(scene.camera.position, scene.camera.target);
shader.setFloat("near_depth", (d - 0.5 - scene.camera.nearclip) / scene.camera.farclip);
shader.setFloat("far_depth", (d + 4 - scene.camera.nearclip) / scene.camera.farclip);
}
});
shaders['dof'] = shaderDOF6;
var shaderSSAO = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/ssao.fs",
});
shaders['ssao'] = shaderSSAO;
// Bloom + 1/2 divisor + blend
var shaderHalfBloom = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/bloom_6tap.fs",
outputMode: CubicVR.enums.post.output.ADD,
outputDivisor: 2
});
shaders['halfbloom'] = shaderHalfBloom;
// Bloom + 1/4 divisor + blend
var shaderQuarterBloom = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/bloom_6tap.fs",
outputMode: CubicVR.enums.post.output.ADD,
outputDivisor: 4
});
shaders['quarterbloom'] = shaderQuarterBloom;
/*
var i = 0;
var shaderActive = 0;
fxSelect = document.getElementById("shaderSelector");
fxSelect.options[i] = new Option("Depth Buffer View", i++);
fxSelect.options[i] = new Option("Invert Color", i++);
fxSelect.options[i] = new Option("Screen-Space Ambient Occlusion", i++);
fxSelect.options[shaderActive = i] = new Option("6-Tap Depth Of Field", i++);
fxSelect.options[i] = new Option("6-Tap Bloom, 1/2 blend", i++);
fxSelect.options[i] = new Option("6-Tap Bloom, 1/4 blend", i++);
//fxSelect.selectedIndex = fxSelect.options.length-1;
fxSelect.selectedIndex = shaderActive;
*/
shaderList.push(shaderDepth);
shaderList.push(shaderInvert);
shaderList.push(shaderSSAO);
shaderList.push(shaderDOF6);
shaderList.push(shaderHalfBloom);
shaderList.push(shaderQuarterBloom);
fxChain = new CubicVR.PostProcessChain(canvas.width, canvas.height, true);
fxChain.setBlurOpacity(1.0);
fxChain.setBlurIntensity(0.0);
for (var i = 0; i < shaderList.length; i++) {
fxChain.addShader(shaderList[i]);
shaderList[i].enabled = false;
} //for
//shaderList[fxSelect.selectedIndex].enabled = true;
var fft;
var audioBuffer;
var signal = new Float32Array(4096);
var audioEngine = new AudioEngine(audioData, function (data) {
fft.forward(data);
audioBuffer = data;
audioEngine.audioBuffer = data;
for (var i=0, l=4096; i<l; ++i) {
if (fft.spectrum[i] > signal[i]) {
signal[i] = fft.spectrum[i];
}
else {
signal[i]*=0.45;
} //if
} //for
});
audioEngine.playMod('mod.mod');
audioEngine.audioObject.volume = 1;
var basePlayer = Popcorn.baseplayer();
basePlayer.timeupdate = function () {
//purposely empty
};
var popcorn = Popcorn(basePlayer);
fft = new FFT(4096, 44100);
audioEngine.fft = fft;
scene = new CubicVR.Scene(canvas.width, canvas.height, 80);
scene.camera.position = [0, 0.5, 2];
scene.camera.target = [0, 0, 0];
CubicVR.setGlobalDepthAlpha(true, scene.camera.nearclip, scene.camera.farclip);
for (var i=0, s=SegmentList.segments, l=s.length; i<l; ++i) {
var startTime = s[i].startTime;
popcorn.code({
start: startTime,
end: startTime+1,
onStart: function (options) {
SegmentList.nextSegment();
},
});
} //for
SegmentList.prepareSegments({
popcorn: popcorn,
audioEngine: audioEngine,
scene: scene,
canvas: canvas,
});
CubicVR.MainLoop(function(timer, gl) {
var seconds = timer.getSeconds();
SegmentList.updateSegments(timer);
basePlayer.currentTime = seconds;
basePlayer.dispatchEvent('timeupdate');
scene.evaluate(seconds);
scene.updateShadows();
fxChain.begin();
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
scene.render();
fxChain.end();
fxChain.render();
});
document.body.appendChild(canvas);
popcorn.play();
basePlayer.readyState = 2;
}, false);
function selectShaderFX(elem) {
fxSelect = document.getElementById("shaderSelector");
for (var i = 0; i < fxSelect.length; i++) {
shaderList[i].enabled = (fxSelect.options[i].selected) ? true : false;
}
}
function setSize() {
if (!gl) {
return;
}
var width = window.innerWidth,
height = width / aspect;
function resize(elem) {
elem.width = width;
elem.height = height;
elem.style.top= ((window.innerHeight/2) - (elem.height/2)) + 'px';
}
resize(canvas);
gl.viewport(0, 0, canvas.width, canvas.height);
scene.camera.setDimensions(canvas.width, canvas.height);
fxChain.resize(canvas.width, canvas.height);
};
window.addEventListener('resize', function() { setSize(); }, false);
</script>
</head>
<body>
<!--
<div style='position:absolute; top:10px; left:10px; color:white; font-family:Arial; font-size:14px;'>
Change FX (multi):
<a href="javascript:void(0)" onclick="document.getElementById('fxDiv').style.display=(document.getElementById('fxDiv').style.display=='none')?'':'none';"
style='text-decoration:none'>( toggle )</a>
<div style='display:none' id='fxDiv'>
<br />
<select id="shaderSelector" onchange="selectShaderFX(this)" multiple size="15" style='vertical-align:top'>
</select>
<br/>
Blur opac:
<input type='text' onchange="fxChain.setBlurOpacity(parseFloat(this.value))" size='4'
value="1">
intens:
<input type='text' onchange="fxChain.setBlurIntensity(parseFloat(this.value))" size='4'
value="0">
<br/>
</div>
</div>
-->
<img class="data-image" src="img/fract_reflections.jpg" id="img/fract_reflections.jpg"/>
<img class="data-image" src="img/logo.jpg" id="img/logo.jpg"/>
<img class="data-image" src="img/logo-alpha.jpg" id="img/logo-alpha.jpg"/>
</body>
</html>