Last active
August 29, 2015 14:06
-
-
Save doxas/4b16f7abc534aff52bb2 to your computer and use it in GitHub Desktop.
glsl_asset_test
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
<!DOCTYPE html><meta charset="utf-8"><script id="fs" type="xs/fs"> | |
precision mediump float; uniform float t; uniform vec2 r; | |
vec3 hsv(float h, float s, float v){ | |
vec4 t = vec4(1., 2. / 3., 1. / 3., 3.); | |
vec3 p = abs(fract(vec3(h) + t.xyz) * 6. - vec3(t.w)); | |
return v * mix(vec3(t.x), clamp(p - vec3(t.x), 0., 1.), s);} | |
void main(void){ | |
vec2 x = vec2(-.345, .654); vec2 y = vec2(t * .005, 0.); | |
vec2 z = (gl_FragCoord.xy * 2. - r) / max(r.x, r.y); int j = 0; | |
for(int i = 0; i < 360; i++){j++; if(length(z) > 2.){break;} | |
z = vec2(z.x * z.x - z.y * z.y, 2. * z.x * z.y) + x + y;} | |
float h = abs(mod(t * 15. - float(j), 360.) / 360.); | |
gl_FragColor = vec4(hsv(h, 1., 1.), 1.); | |
}</script><script id="vs" type="xs/vs">attribute vec3 position; | |
void main(void){gl_Position = vec4(position, 1.0);}</script><script> | |
window.onload = function(){var a, b, c, d, e, f, g, p, t, u, v, w, x, y, z; | |
b = function(s){return document.getElementById(s)}; | |
w = window; w.addEventListener('keydown', k, true); | |
c = b('c'); g = c.getContext('webgl'); c.width = x = w.innerWidth; c.height = y = w.innerHeight; | |
v = g.createShader(g.VERTEX_SHADER); g.shaderSource(v, b('vs').text); g.compileShader(v); | |
f = g.createShader(g.FRAGMENT_SHADER); g.shaderSource(f, b('fs').text); g.compileShader(f); | |
if(!g.getShaderParameter(v, g.COMPILE_STATUS)){alert(g.getShaderInfoLog(v)); return;} | |
if(!g.getShaderParameter(f, g.COMPILE_STATUS)){alert(g.getShaderInfoLog(f)); return;} | |
p = g.createProgram(); g.attachShader(p, v); g.attachShader(p, f); g.linkProgram(p); | |
if(!g.getProgramParameter(p, g.LINK_STATUS)){alert(g.getProgramInfoLog(p)); return;} | |
e = (p != null); g.useProgram(p); u = []; | |
u[0] = g.getUniformLocation(p, 't'); u[1] = g.getUniformLocation(p, 'r'); | |
g.bindBuffer(g.ARRAY_BUFFER, g.createBuffer()); | |
g.bufferData(g.ARRAY_BUFFER, new Float32Array([-1,1,0,-1,-1,0,1,1,0,1,-1,0]), g.STATIC_DRAW); | |
a = g.getAttribLocation(p, 'position'); | |
g.enableVertexAttribArray(a); g.vertexAttribPointer(a, 3, g.FLOAT, false, 0, 0); | |
g.clearColor(0, 0, 0, 1); z = new Date().getTime(); | |
(function(){if(!e){return;} c.width = x = w.innerWidth; c.height = y = w.innerHeight; | |
g.viewport(0, 0, x, y); d = (new Date().getTime() - z) * 0.001; | |
g.clear(g.COLOR_BUFFER_BIT); g.uniform1f(u[0], d); g.uniform2fv(u[1], [x, y]); | |
g.drawArrays(g.TRIANGLE_STRIP, 0, 4); g.flush(); setTimeout(arguments.callee, 16);})(); | |
function k(h){e = (h.keyCode !== 27);}}; | |
</script><style>*{margin:0;padding:0;overflow:hidden;}html,body{height:100%}</style> | |
<title>2.5k asset</title><canvas id="c"></canvas> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment