Skip to content

Instantly share code, notes, and snippets.

@freeman-lab
Last active May 31, 2016 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save freeman-lab/7914aec22185e7414d18ab7bcd23014b to your computer and use it in GitHub Desktop.
Save freeman-lab/7914aec22185e7414d18ab7bcd23014b to your computer and use it in GitHub Desktop.
looming red sphere in regl
const mat4 = require('gl-mat4')
const sphere = require('primitive-icosphere')
const regl = require('regl')()
const camera = require('lookat-camera')()
var mesh = sphere(1, {subdivisions: 1})
const cube = regl({
frag: `
precision mediump float;
uniform vec3 color;
void main () {
gl_FragColor = vec4(color, 1.0);
}`,
vert: `
precision mediump float;
uniform mat4 proj;
uniform mat4 model;
uniform mat4 view;
attribute vec3 position;
void main () {
gl_Position = proj * view * model * vec4(position, 1.0);
gl_PointSize = 10.0;
}`,
attributes: {
position: regl.buffer(mesh.positions)
},
elements: regl.elements(mesh.cells),
uniforms: {
proj: mat4.perspective([], Math.PI / 2, window.innerWidth / window.innerHeight, 0.01, 1000),
model: regl.prop('model'),
view: regl.prop('view'),
color: regl.prop('color')
}
})
var scale
regl.frame(function (props, context) {
regl.clear({
color: [0, 0, 0, 1]
})
camera.position = [0, 5, 0]
camera.target = [0, 0, 0]
camera.up = [0, 0, 1]
scale = context.count * 0.002 + 1
cube({
view: camera.view(),
color: [1, 0, 0],
model: mat4.scale(mat4.identity([]), mat4.identity([]), [scale, scale, scale])
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment