Last active
March 12, 2016 21:39
-
-
Save AlexTiTanium/5e3679df9ed717d08591 to your computer and use it in GitHub Desktop.
Simple shader 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
var vertices = [ | |
-1, -1, 0, | |
1, -1, 0, | |
1, 1, 0, | |
-1, -1, 0, | |
1, 1, 0, | |
-1, 1, 0 | |
]; | |
setVerticesPosition(vertices); | |
setUniform("uRenderScale", "1f", Math.min(gl.canvas.width, gl.canvas.height)); | |
setUniform("uDensity", "1f", 0.005); | |
render(); |
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
#version 100 | |
precision highp float; | |
uniform float uDensity; | |
uniform float uRenderScale; | |
float qnoise(vec2 p) { | |
return fract(sin(dot(p.xy, vec2(12.9898, 78.233))) * 43758.5453); | |
} | |
float exprand(vec2 p) { | |
float u = qnoise(p); | |
return log(1.0 - u)/(-2.0 * 3.14159); | |
} | |
float noise(vec2 p) { | |
return qnoise(p) * 0.5 + 0.5; | |
} | |
void main() { | |
vec2 p = gl_FragCoord.xy/uRenderScale; | |
float c = 0.0; | |
if (qnoise(p*2.0+11.0) < uDensity) { | |
c = exprand(p); | |
} | |
gl_FragColor = vec4(1,1,1, c); | |
} |
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
#version 100 | |
precision highp float; | |
attribute vec3 aPosition; | |
void main() { | |
gl_Position = vec4(aPosition, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment