Skip to content

Instantly share code, notes, and snippets.

@mebens mebens/gist:4229527
Created Dec 6, 2012

Embed
What would you like to do?
Here's an interesting noise-based Love2D shader. Simply keep setting factor to a random number every frame (or some other interval).
extern float factor = 1;
extern float addPercent = 0.1;
extern float clamp = 0.85;
// from http://www.ozone3d.net/blogs/lab/20110427/glsl-random-generator/
float rand(vec2 n)
{
return 0.5 + 0.5 * fract(sin(dot(n.xy, vec2(12.9898, 78.233))) * 43758.5453);
}
vec4 effect(vec4 color, Image tex, vec2 tc, vec2 sc)
{
float grey = 1 * rand(tc * factor);
float clampedGrey = max(grey, clamp);
vec4 noise = vec4(grey, grey, grey, 1);
vec4 clampedNoise = vec4(clampedGrey, clampedGrey, clampedGrey, 1);
return (Texel(tex, tc) * clampedNoise * (1 - addPercent) + noise * addPercent) * color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.