Created
November 19, 2019 06:05
-
-
Save nani1337/06e2db701575f5b67015a60ce3c2973f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <canvas id="c" width=400 height=400></canvas> | |
| <script> | |
| var gl = c.getContext("webgl"); | |
| var vshader = `void main(){ | |
| gl_Position=vec4(0,0,0,1); | |
| gl_PointSize=400.0; | |
| }`; | |
| var fshader = `precision lowp float; | |
| uniform vec3 r; | |
| void main(){ | |
| vec4 p=vec4(gl_FragCoord.xy/r.xy*2.-1.,0,1); | |
| gl_FragColor=p+sin(atan(p.y,p.x)*9.)*sin(p*r.z/2.+9./dot(p,p)+r.z*8.); // <= edit your shader here | |
| }`; | |
| var vs = gl.createShader(gl.VERTEX_SHADER); | |
| gl.shaderSource(vs, vshader); | |
| gl.compileShader(vs); | |
| var fs = gl.createShader(gl.FRAGMENT_SHADER); | |
| gl.shaderSource(fs, fshader); | |
| gl.compileShader(fs); | |
| var program = gl.createProgram(); | |
| gl.attachShader(program, vs); | |
| gl.attachShader(program, fs); | |
| gl.linkProgram(program); | |
| gl.useProgram(program); | |
| setInterval(() => { | |
| gl.uniform3f(gl.getUniformLocation(program, "r"), c.width, c.height, performance.now()/1e3); | |
| gl.drawArrays(gl.POINTS,0,1); | |
| },16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment