forked from possan/webglass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
305 lines (276 loc) · 11.7 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
<html>
<head>
<script src="sylvester.js" type="text/javascript">
</script>
<script src="glUtils.js" type="text/javascript">
</script>
<script src="seedrandom.js" type="text/javascript">
</script>
<script src="compability.js" type="text/javascript">
</script>
<!-- common junk -->
<script src="parts/newmath.js" type="text/javascript">
</script>
<script src="parts/gla_stuff.js" type="text/javascript">
</script>
<script src="music.js" type="text/javascript">
</script>
<script src="parts/images.js" type="text/javascript">
</script>
<script src="parts/events.js" type="text/javascript">
</script>
<!-- parts -->
<script src="parts/p_tunnel.js" type="text/javascript">
</script>
<script src="parts/p_intro.js" type="text/javascript">
</script>
<script src="parts/p_cubes.js" type="text/javascript">
</script>
<script src="parts/p_greetings.js" type="text/javascript">
</script>
<script src="parts/p_misc.js" type="text/javascript">
</script>
<script src="parts/p_name.js" type="text/javascript">
</script>
<script src="parts/p_twist.js" type="text/javascript">
</script>
<script src="parts/p_twist3d.js" type="text/javascript">
</script>
<script src="parts/p_twister.js" type="text/javascript">
</script>
<script src="parts/p_silu.js" type="text/javascript">
</script>
<script src="parts/p_klask.js" type="text/javascript">
</script>
<script src="parts/p_cubes.js" type="text/javascript">
</script>
<script src="parts/p_flareblob.js" type="text/javascript">
</script>
<script src="parts/p_psyk.js" type="text/javascript">
</script>
<script src="parts/p_wirelandscape.js" type="text/javascript">
</script>
<script src="parts/p_sphere.js" type="text/javascript">
</script>
<script src="parts/p_aftershit.js" type="text/javascript">
</script>
<!-- app -->
<script src="parts/testapp.js" type="text/javascript">
</script>
<script type="text/javascript">
var gl;
var frametime = 0.0;
function initGL(canvas){
try {
gl = canvas.getContext("experimental-webgl");
gl.viewportWidth = canvas.width;
gl.viewportHeight = canvas.height;
}
catch (e) {
}
if (!gl) {
alert("Could not initialise WebGL, sorry :-(");
}
}
var shaderProgram;
function initShaders(){
var fragmentShader = getShader(gl, "shader-fs");
var vertexShader = getShader(gl, "shader-vs");
shaderProgram = gl.createProgram();
gl.attachShader(shaderProgram, vertexShader);
gl.attachShader(shaderProgram, fragmentShader);
gl.linkProgram(shaderProgram);
if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
alert("Could not initialise shaders");
}
gl.useProgram(shaderProgram);
shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord");
shaderProgram.vertexColorAttribute = gl.getAttribLocation(shaderProgram, "aVertexColor");
shaderProgram.vertexNormalAttribute = gl.getAttribLocation(shaderProgram, "aVertexNormal");
shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
shaderProgram.nMatrixUniform = gl.getUniformLocation(shaderProgram, "uNMatrix");
shaderProgram.tMatrixUniform = gl.getUniformLocation(shaderProgram, "uTMatrix");
shaderProgram.textureEnabler = gl.getUniformLocation(shaderProgram, "uUseTexture");
shaderProgram.textureSampler = gl.getUniformLocation(shaderProgram, "uSampler");
gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
gl.enableVertexAttribArray(shaderProgram.textureCoordinateAttribute);
gl.enableVertexAttribArray(shaderProgram.vertexColorAttribute);
gl.enableVertexAttribArray(shaderProgram.vertexNormalAttribute);
}
function getShader(gl, id){
var shaderScript = document.getElementById(id);
if (!shaderScript) {
return null;
}
var str = "";
var k = shaderScript.firstChild;
while (k) {
if (k.nodeType == 3)
str += k.textContent;
k = k.nextSibling;
}
var shader;
if (shaderScript.type == "x-shader/x-fragment") {
shader = gl.createShader(gl.FRAGMENT_SHADER);
}
else
if (shaderScript.type == "x-shader/x-vertex") {
shader = gl.createShader(gl.VERTEX_SHADER);
}
else {
return null;
}
gl.shaderSource(shader, str);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
alert(gl.getShaderInfoLog(shader));
return null;
}
return shader;
}
function mvTranslate(v){
var m = Matrix.Translation($V([v[0], v[1], v[2]])).ensure4x4();
multMatrix(m);
}
var starttime;
function webGLStart(){
var canvas = document.getElementById("video");
initGL(canvas);
initShaders();
initBuffers();
testApp__setup();
/*
gl.clearColor(0.2, 0.2, 0.2, 1.0);
gl.clearDepth(1.0)
gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE,gl.ONE);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
*/
frametime = 0.0;
starttime = (new Date()).getTime();
setInterval(drawScene, 1000.0 / 60.0);
}
// var triangleVertexPositionBuffer;
// var squareVertexPositionBuffer;
function initBuffers(){
}
function drawScene(){
glCompabilityBeforeFrame();
gl.clearColor(0.05, 0.05, 0.05, 1.0);
gl.clearDepth(20.0);
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
frametime = (new Date()).getTime() - starttime;
frametime /= 1000.0;
// frametime *= 1.0;
// frametime += 0.0;
glaSetTime(frametime);
testApp__draw();
}
</script>
<script id="shader-fs" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
varying vec4 vTextureCoord;
varying vec4 vVertexColor;
varying vec3 vLightWeighting;
uniform sampler2D uSampler;
uniform bool uUseTexture;
void main(void) {
vec4 textureColor;
textureColor = vec4(vTextureCoord.x,vTextureCoord.y,1,1);
if(uUseTexture)
textureColor = texture2D(uSampler, vec2( vTextureCoord.s, vTextureCoord.t ));
gl_FragColor = vVertexColor * textureColor;
// vec4(textureColor.rgb * vVertexColor * vLightWeighting, textureColor.a * uAlpha);
}
</script>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
attribute vec4 aVertexColor;
attribute vec2 aTextureCoord;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat4 uNMatrix;
uniform mat4 uTMatrix;
// uniform vec3 uAmbientColor;
// uniform vec3 uLightingDirection;
// uniform vec3 uDirectionalColor;
// uniform bool uUseLighting;
uniform bool uUseTexture;
varying vec4 vTextureCoord;
varying vec4 vVertexColor;
varying vec3 vLightWeighting;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
// vTextureCoord = uTMatrix * vec4(aTextureCoord.s,aTextureCoord.t,0,1);
vTextureCoord = vec4(aTextureCoord.s,aTextureCoord.t,0,1);
// vTextureCoord = vec4( gl_Position.x, gl_Position.y, 0, 1 );
// if (!uUseLighting) {
vLightWeighting = vec3( 1, 1, 1 );
vVertexColor = aVertexColor;
// } else {
// vec4 transformedNormal = uNMatrix * vec4(aVertexNormal, 1.0);
// float directionalLightWeighting = max(dot(transformedNormal.xyz, uLightingDirection), 0.0);
// vLightWeighting = uAmbientColor + uDirectionalColor * directionalLightWeighting;
// }
}
</script>
<style>
html {
border: 0;
margin: 0;
padding: 0
}
body {
border: 0;
margin: 0;
padding: 0
background-color: #000;
}
canvas {
width: 100%;
height: 100%;
position: absolute;
left: 0px;
top: 0px;
background-color: #000;
}
#banner {
position: absolute;
left: 10px;
bottom: 5px;
width: 500px;
height: 30px;
color: #ccc;
z-index: 999;
font: 8pt Arial;
}
#banner a {
color: #fff;
}
</style>
</head>
<body onload="webGLStart();">
<canvas id="video" style="border: none;" width="1280" height="720">
</canvas>
<audio id="music" autoplay="no" src="parts/intromusic.mp3" preload="auto">
</audio>
<div id="banner">
<a href="http://possan.se/2011/01/27/webglass/">webgl-port</a>
of our winning <a href="http://pouet.net/prod.php?which=94">64k intro "glass"</a>
from the gathering 2000 - tested in chrome
<br/>
ported by: <a href="http://possan.se">per-olov jernberg</a>
(illuminator/psikorp)
- <a href="http://github.com/possan/webglass">code available on github</a>
</div>
</body>
</html>