Created
November 20, 2016 04:13
-
-
Save msfeldstein/ce432e63a3cc1eff3b7549ac06a6dd72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var twgl = require('twgl.js') | |
var canvas = document.createElement('canvas') | |
document.body.appendChild(canvas) | |
const vtx = ` | |
attribute vec4 position; | |
void main() { | |
gl_Position = position; | |
} | |
` | |
const frag = ` | |
precision mediump float; | |
uniform vec2 resolution; | |
uniform float time; | |
void main() { | |
vec2 uv = gl_FragCoord.xy / resolution; | |
float color = 0.0; | |
// lifted from glslsandbox.com | |
color += sin( uv.x * cos( time / 3.0 ) * 60.0 ) + cos( uv.y * cos( time / 2.80 ) * 10.0 ); | |
color += sin( uv.y * sin( time / 2.0 ) * 40.0 ) + cos( uv.x * sin( time / 1.70 ) * 40.0 ); | |
color += sin( uv.x * sin( time / 1.0 ) * 10.0 ) + sin( uv.y * sin( time / 3.50 ) * 80.0 ); | |
color *= sin( time / 10.0 ) * 0.5; | |
gl_FragColor = vec4( vec3( color * 0.5, sin( color + time / 2.5 ) * 0.75, color ), 1.0 ); | |
} | |
` | |
var gl = twgl.getWebGLContext(canvas); | |
var programInfo = twgl.createProgramInfo(gl, [vtx, frag]); | |
var arrays = { | |
position: [-1, -1, 0, 1, -1, 0, -1, 1, 0, -1, 1, 0, 1, -1, 0, 1, 1, 0], | |
}; | |
var bufferInfo = twgl.createBufferInfoFromArrays(gl, arrays); | |
function render(time) { | |
twgl.resizeCanvasToDisplaySize(gl.canvas); | |
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); | |
var uniforms = { | |
time: time * 0.001, | |
resolution: [gl.canvas.width, gl.canvas.height], | |
}; | |
gl.useProgram(programInfo.program); | |
twgl.setBuffersAndAttributes(gl, programInfo, bufferInfo); | |
twgl.setUniforms(programInfo, uniforms); | |
twgl.drawBufferInfo(gl, bufferInfo); | |
requestAnimationFrame(render); | |
} | |
requestAnimationFrame(render); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment