-
Notifications
You must be signed in to change notification settings - Fork 100
/
deferred.html
536 lines (423 loc) · 20.6 KB
/
deferred.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
<!DOCTYPE html>
<!--
The MIT License (MIT)
Copyright (c) 2017 Tarek Sherif
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<html>
<head>
<title>WebGL 2 Example: Deferred Rendering</title>
<meta charset="utf-8">
<script src="utils/gl-matrix.js"></script>
<script src="utils/utils.js"></script>
<link rel="stylesheet" href="css/webgl2examples.css">
</head>
<body>
<div id="example-title">
<header>WebGL 2 Example: Deferred Rendering</header>
<div id="features">
Features: Vertex Arrays, Uniform Buffers, Immutable Textures, Multiple Render Targets, Float Textures, texelFetch, EXT_color_buffer_float
</div>
<div>
<a href="https://github.com/tsherif/webgl2examples/blob/master/deferred.html">Source code</a>
</div>
</div>
<canvas id="gl-canvas"></canvas>
<script id="geo-vs" type="x-vertex-shader">
#version 300 es
layout(std140, column_major) uniform;
layout(location=0) in vec4 aPosition;
layout(location=1) in vec3 aNormal;
layout(location=2) in vec4 aUV;
uniform Matrices {
mat4 uModelMatrix;
mat4 uMVP;
};
out vec4 vPosition;
out vec4 vNormal;
out vec4 vUV;
void main() {
vPosition = uModelMatrix * aPosition;
vNormal = uModelMatrix * vec4(aNormal, 0.0);
vUV = aUV;
gl_Position = uMVP * aPosition;
}
</script>
<script id="geo-fs" type="x-fragment-shader">
#version 300 es
precision highp float;
in vec4 vPosition;
in vec4 vNormal;
in vec4 vUV;
layout(location=0) out vec4 fragPosition;
layout(location=1) out vec4 fragNormal;
layout(location=2) out vec4 fragUV;
void main() {
fragPosition = vPosition;
fragNormal = vec4(normalize(vNormal.xyz), 0.0);
fragUV = vUV;
}
</script>
<script id="main-vs" type="x-vertex-shader">
#version 300 es
layout(std140, column_major) uniform;
layout(location=0) in vec4 aPosition;
uniform LightUniforms {
mat4 mvp;
vec4 position;
vec4 color;
} uLight;
void main() {
gl_Position = uLight.mvp * aPosition;
}
</script>
<script id="main-fs" type="x-fragment-shader">
#version 300 es
precision highp float;
uniform LightUniforms {
mat4 mvp;
vec4 position;
vec4 color;
} uLight;
uniform vec3 uEyePosition;
uniform sampler2D uPositionBuffer;
uniform sampler2D uNormalBuffer;
uniform sampler2D uUVBuffer;
uniform sampler2D uTextureMap;
out vec4 fragColor;
void main() {
ivec2 fragCoord = ivec2(gl_FragCoord.xy);
vec3 position = texelFetch(uPositionBuffer, fragCoord, 0).xyz;
vec3 normal = normalize(texelFetch(uNormalBuffer, fragCoord, 0).xyz);
vec2 uv = texelFetch(uUVBuffer, fragCoord, 0).xy;
vec4 baseColor = texture(uTextureMap, uv);
vec3 eyeDirection = normalize(uEyePosition - position);
vec3 lightVec = uLight.position.xyz - position;
float attenuation = 1.0 - length(lightVec);
vec3 lightDirection = normalize(lightVec);
vec3 reflectionDirection = reflect(-lightDirection, normal);
float nDotL = max(dot(lightDirection, normal), 0.0);
vec3 diffuse = nDotL * uLight.color.rgb;
float ambient = 0.1;
vec3 specular = pow(max(dot(reflectionDirection, eyeDirection), 0.0), 20.0) * uLight.color.rgb;
fragColor = vec4(attenuation * (ambient + diffuse + specular) * baseColor.rgb, baseColor.a);
}
</script>
<script>
var canvas = document.getElementById("gl-canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var gl = canvas.getContext("webgl2");
if (!gl) {
console.error("WebGL 2 not available");
document.body.innerHTML = "This example requires WebGL 2 which is unavailable on this system."
}
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);
gl.blendFunc(gl.ONE, gl.ONE);
if (!gl.getExtension("EXT_color_buffer_float")) {
console.error("FLOAT color buffer not available");
document.body.innerHTML = "This example requires EXT_color_buffer_float which is unavailable on this system."
}
////////////////////////////
// GBUFFER PROGRAM SETUP
////////////////////////////
var geoVsSource = document.getElementById("geo-vs").text.trim();
var geoFsSource = document.getElementById("geo-fs").text.trim();
var geoVertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(geoVertexShader, geoVsSource);
gl.compileShader(geoVertexShader);
if (!gl.getShaderParameter(geoVertexShader, gl.COMPILE_STATUS)) {
console.error(gl.getShaderInfoLog(geoVertexShader));
}
var geoFragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(geoFragmentShader, geoFsSource);
gl.compileShader(geoFragmentShader);
if (!gl.getShaderParameter(geoFragmentShader, gl.COMPILE_STATUS)) {
console.error(gl.getShaderInfoLog(geoFragmentShader));
}
var geoProgram = gl.createProgram();
gl.attachShader(geoProgram, geoVertexShader);
gl.attachShader(geoProgram, geoFragmentShader);
gl.linkProgram(geoProgram);
if (!gl.getProgramParameter(geoProgram, gl.LINK_STATUS)) {
console.error(gl.getProgramInfoLog(geoProgram));
}
//////////////////////////////////////////
// GET GBUFFFER PROGRAM UNIFORM LOCATIONS
//////////////////////////////////////////
var matrixUniformLocation = gl.getUniformBlockIndex(geoProgram, "Matrices");
gl.uniformBlockBinding(geoProgram, matrixUniformLocation, 0);
////////////////////////////
// GBUFFER SETUP
////////////////////////////
var gBuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, gBuffer);
gl.activeTexture(gl.TEXTURE0);
var positionTarget = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, positionTarget);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA16F, gl.drawingBufferWidth, gl.drawingBufferHeight);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, positionTarget, 0);
var normalTarget = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, normalTarget);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA16F, gl.drawingBufferWidth, gl.drawingBufferHeight);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, gl.TEXTURE_2D, normalTarget, 0);
var uvTarget = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, uvTarget);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RG16F, gl.drawingBufferWidth, gl.drawingBufferHeight);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT2, gl.TEXTURE_2D, uvTarget, 0);
var depthTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, depthTexture);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.DEPTH_COMPONENT16, gl.drawingBufferWidth, gl.drawingBufferHeight);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTexture, 0);
gl.drawBuffers([
gl.COLOR_ATTACHMENT0,
gl.COLOR_ATTACHMENT1,
gl.COLOR_ATTACHMENT2
]);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
/////////////////////////////
// MAIN PROGRAM SETUP
/////////////////////////////
var mainVsSource = document.getElementById("main-vs").text.trim();
var mainFsSource = document.getElementById("main-fs").text.trim();
var mainVertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(mainVertexShader, mainVsSource);
gl.compileShader(mainVertexShader);
if (!gl.getShaderParameter(mainVertexShader, gl.COMPILE_STATUS)) {
console.error(gl.getShaderInfoLog(mainVertexShader));
}
var mainFragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(mainFragmentShader, mainFsSource);
gl.compileShader(mainFragmentShader);
if (!gl.getShaderParameter(mainFragmentShader, gl.COMPILE_STATUS)) {
console.error(gl.getShaderInfoLog(mainFragmentShader));
}
var mainProgram = gl.createProgram();
gl.attachShader(mainProgram, mainVertexShader);
gl.attachShader(mainProgram, mainFragmentShader);
gl.linkProgram(mainProgram);
if (!gl.getProgramParameter(mainProgram, gl.LINK_STATUS)) {
console.error(gl.getProgramInfoLog(mainProgram));
}
//////////////////////////////////////////////
// GET MAIN PROGRAM UNIFORM LOCATIONS
//////////////////////////////////////////////
var lightUniformsLocation = gl.getUniformBlockIndex(mainProgram, "LightUniforms");
gl.uniformBlockBinding(mainProgram, lightUniformsLocation, 0);
var eyePositionLocation = gl.getUniformLocation(mainProgram, "uEyePosition");
var positionBufferLocation = gl.getUniformLocation(mainProgram, "uPositionBuffer");
var normalBufferLocation = gl.getUniformLocation(mainProgram, "uNormalBuffer");
var uVBufferLocation = gl.getUniformLocation(mainProgram, "uUVBuffer");
var textureMapLocation = gl.getUniformLocation(mainProgram, "uTextureMap");
///////////////////////
// GEOMETRY SET UP
///////////////////////
var cubeVertexArray = gl.createVertexArray();
gl.bindVertexArray(cubeVertexArray);
var box = utils.createBox();
var positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, box.positions, gl.STATIC_DRAW);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(0);
var normalBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, normalBuffer);
gl.bufferData(gl.ARRAY_BUFFER, box.normals, gl.STATIC_DRAW);
gl.vertexAttribPointer(1, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(1);
var uvBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, uvBuffer);
gl.bufferData(gl.ARRAY_BUFFER, box.uvs, gl.STATIC_DRAW);
gl.vertexAttribPointer(2, 2, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(2);
var sphereVertexArray = gl.createVertexArray();
gl.bindVertexArray(sphereVertexArray);
var numCubeVertices = box.positions.length / 3;
var sphere = utils.createSphere();
positionBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
gl.bufferData(gl.ARRAY_BUFFER, sphere.positions, gl.STATIC_DRAW);
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(0);
var indexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sphere.indices, gl.STATIC_DRAW);
var numSphereElements = sphere.indices.length;
gl.bindVertexArray(null);
////////////////////
// UNIFORM DATA
////////////////////
var projMatrix = mat4.create();
mat4.perspective(projMatrix, Math.PI / 2, canvas.width / canvas.height, 0.1, 10.0);
var viewMatrix = mat4.create();
var eyePosition = vec3.fromValues(1, 1, 1);
mat4.lookAt(viewMatrix, eyePosition, vec3.fromValues(0, 0, 0), vec3.fromValues(0, 1, 0));
var viewProjMatrix = mat4.create();
mat4.multiply(viewProjMatrix, projMatrix, viewMatrix);
var boxes = [
{
scale: [1, 1, 1],
rotate: [0, 0, 0],
translate: [0, 0, 0],
modelMatrix: mat4.create(),
mvpMatrix: mat4.create(),
},
{
scale: [0.1, 0.1, 0.1],
rotate: [0, 0, Math.PI / 3],
translate: [0.8, 0.8, 0.4],
modelMatrix: mat4.create(),
mvpMatrix: mat4.create(),
}
];
var matrixUniformData = new Float32Array(32);
var matrixUniformBuffer = gl.createBuffer();
gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, matrixUniformBuffer);
gl.bufferData(gl.UNIFORM_BUFFER, 128, gl.DYNAMIC_DRAW);
var lights = [
{
position: vec3.fromValues(0, 1, 0.5),
color: vec3.fromValues(0.8, 0.0, 0.0),
uniformData: new Float32Array(24),
uniformBuffer: gl.createBuffer()
},
{
position: vec3.fromValues(1, 1, 0.5),
color: vec3.fromValues(0.0, 0.0, 0.8),
uniformData: new Float32Array(24),
uniformBuffer: gl.createBuffer()
},
{
position: vec3.fromValues(1, 0, 0.5),
color: vec3.fromValues(0.0, 0.8, 0.0),
uniformData: new Float32Array(24),
uniformBuffer: gl.createBuffer()
},
{
position: vec3.fromValues(0.5, 0, 1),
color: vec3.fromValues(0.0, 0.8, 0.8),
uniformData: new Float32Array(24),
uniformBuffer: gl.createBuffer()
}
];
var mvpMatrix = mat4.create();
for (var i = 0, len = lights.length; i < len; ++i) {
utils.xformMatrix(mvpMatrix, lights[i].position);
mat4.multiply(mvpMatrix, viewProjMatrix, mvpMatrix);
lights[i].uniformData.set(mvpMatrix);
lights[i].uniformData.set(lights[i].position, 16);
lights[i].uniformData.set(lights[i].color, 20);
gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, lights[i].uniformBuffer);
gl.bufferData(gl.UNIFORM_BUFFER, lights[i].uniformData, gl.STATIC_DRAW);
}
var image = new Image();
image.onload = function() {
var colorTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, colorTexture);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
var levels = levels = Math.floor(Math.log2(Math.max(this.width, this.height))) + 1;
gl.texStorage2D(gl.TEXTURE_2D, levels, gl.RGBA8, image.width, image.height);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, gl.RGBA, gl.UNSIGNED_BYTE, image);
gl.generateMipmap(gl.TEXTURE_2D);
gl.generateMipmap(gl.TEXTURE_2D);
//////////////////
// BIND TEXTURES
//////////////////
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, positionTarget);
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, normalTarget);
gl.activeTexture(gl.TEXTURE2);
gl.bindTexture(gl.TEXTURE_2D, uvTarget);
gl.activeTexture(gl.TEXTURE3);
gl.bindTexture(gl.TEXTURE_2D, colorTexture);
//////////////////////////////
// SET MAIN PROGRAM UNIFORMS
//////////////////////////////
gl.useProgram(mainProgram);
gl.uniform3fv(eyePositionLocation, eyePosition);
gl.uniform1i(positionBufferLocation, 0);
gl.uniform1i(normalBufferLocation, 1);
gl.uniform1i(uVBufferLocation, 2);
gl.uniform1i(textureMapLocation, 3);
function draw() {
/////////////////////////
// DRAW TO GBUFFER
/////////////////////////
gl.bindFramebuffer(gl.FRAMEBUFFER, gBuffer);
gl.useProgram(geoProgram);
gl.bindVertexArray(cubeVertexArray);
gl.depthMask(true);
gl.disable(gl.BLEND);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
for (var i = 0, len = boxes.length; i < len; ++i) {
boxes[i].rotate[0] += 0.01;
boxes[i].rotate[1] += 0.02;
utils.xformMatrix(boxes[i].modelMatrix, boxes[i].translate, boxes[i].rotate, boxes[i].scale);
mat4.multiply(boxes[i].mvpMatrix, viewProjMatrix, boxes[i].modelMatrix);
matrixUniformData.set(boxes[i].modelMatrix);
matrixUniformData.set(boxes[i].mvpMatrix, 16);
gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, matrixUniformBuffer);
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, matrixUniformData);
gl.drawArrays(gl.TRIANGLES, 0, numCubeVertices);
}
/////////////////////////
// MAIN DRAW PASS
/////////////////////////
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.useProgram(mainProgram);
gl.bindVertexArray(sphereVertexArray);
gl.depthMask(false);
gl.enable(gl.BLEND);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
for (var i = 0, len = lights.length; i < len; ++i) {
gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, lights[i].uniformBuffer);
gl.drawElements(gl.TRIANGLES, numSphereElements, gl.UNSIGNED_SHORT, 0);
}
requestAnimationFrame(draw);
}
requestAnimationFrame(draw);
}
image.src = "img/khronos_webgl.png";
</script>
</body>
</html>