JavaScript
var regl = createREGL();
// Weird flickering effects start at x = 1000;
var x = 1;
var cubePosition = [
[-x, +x, +x], [+x, +x, +x], [+x, -x, +x], [-x, -x, +x], // positive z face.
[+x, +x, +x], [+x, +x, -x], [+x, -x, -x], [+x, -x, +x], // positive x face
[+x, +x, -x], [-x, +x, -x], [-x, -x, -x], [+x, -x, -x], // negative z face
[-x, +x, -x], [-x, +x, +x], [-x, -x, +x], [-x, -x, -x], // negative x face.
[-x, +x, -x], [+x, +x, -x], [+x, +x, +x], [-x, +x, +x], // top face
[-x, -x, -x], [+x, -x, -x], [+x, -x, +x], [-x, -x, +x] // bottom face
]
var cubeUv = [
[0, 0], [1, 0], [1, 1], [0, 1], // positive z face.
[0, 0], [1, 0], [1, 1], [0, 1], // positive x face.
[0, 0], [1, 0], [1, 1], [0, 1], // negative z face.
[0, 0], [1, 0], [1, 1], [0, 1], // negative x face.
[0, 0], [1, 0], [1, 1], [0, 1], // top face
[0, 0], [1, 0], [1, 1], [0, 1] // bottom face
]
const cubeElements = [
[2, 1, 0], [2, 0, 3], // positive z face.
[6, 5, 4], [6, 4, 7], // positive x face.
[10, 9, 8], [10, 8, 11], // negative z face.
[14, 13, 12], [14, 12, 15], // negative x face.
[18, 17, 16], [18, 16, 19], // top face.
[20, 21, 22], [23, 20, 22] // bottom face
]
const drawCube = regl({
frag: `
precision mediump float;
void main () {
gl_FragColor = vec4(0.403921569, 0.850980392, 1, 0.33);
}`,
vert: `
precision mediump float;
attribute vec3 position;
uniform mat4 projection, view;
void main() {
gl_Position = projection * view * vec4(position, 1);
}`,
blend: {
enable: true,
func: {
srcRGB: 'src alpha',
srcAlpha: 'one',
dstRGB: 'one minus src alpha',
dstAlpha: 'one minus src alpha'
}
},
attributes: {
position: cubePosition,
},
elements: cubeElements,
uniforms: {
view: ({tick}) => {
const t = 0.01 * tick
return mat4.lookAt(
[],
[x * 5 * Math.cos(t), x * 2.5 * Math.sin(t), x * 5 * Math.sin(t)],
[0, 0.0, 0],
[0, 1, 0]
...