Skip to content

Instantly share code, notes, and snippets.

@akilism
Created June 4, 2017 16:34
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 akilism/55fdc1401fa1ae6f32393c46fb749036 to your computer and use it in GitHub Desktop.
Save akilism/55fdc1401fa1ae6f32393c46fb749036 to your computer and use it in GitHub Desktop.
jam-3-exploding-bunny-regl
const regl = require('regl')();
const mat4 = require('gl-mat4');
const fNormals = require('face-normals');
const unindex = require('unindex-mesh');
const bunny = require('bunny');
const pos = unindex(bunny);
const draw = regl({
frag: `
precision mediump float;
varying vec3 vNormal;
void main() {
gl_FragColor = vec4(vNormal, 1.0);
}
`,
vert: `
precision mediump float;
attribute vec3 position;
attribute vec3 normal;
uniform mat4 model, view, projection;
uniform float t;
varying vec3 vNormal;
void main() {
vNormal = normal;
vec4 offset = vec4(position, 1);
float dist = sin(t) * 1.0 + 1.0;
offset.xyz += normal * dist;
gl_Position = projection * view * model * offset;
}
`,
attributes: {
position: pos,
normal: fNormals(pos)
},
count: pos.length / 3,
uniforms: {
model: mat4.identity([]),
view: mat4.lookAt([],
[-10, 2.5, 20],
[0, 4, 0],
[0, 1, 0]
),
projection: ({ viewportWidth, viewportHeight }) => {
return mat4.perspective([],
Math.PI / 4,
viewportWidth / viewportHeight,
0.01,
1000)
},
t: ({ time }) => time
}
});
regl.frame((context) => {
regl.clear({
depth: 1,
color: [0, 0, 0, 1]
})
draw();
});
@akilism
Copy link
Author

akilism commented Jun 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment