Skip to content

Instantly share code, notes, and snippets.

@AlexTiTanium
Last active March 12, 2016 21:39
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 AlexTiTanium/5e3679df9ed717d08591 to your computer and use it in GitHub Desktop.
Save AlexTiTanium/5e3679df9ed717d08591 to your computer and use it in GitHub Desktop.
Simple shader test
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();
#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);
}
#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