Skip to content

Instantly share code, notes, and snippets.

@joelpryde
Created October 16, 2013 16:22
Show Gist options
  • Save joelpryde/7010658 to your computer and use it in GitHub Desktop.
Save joelpryde/7010658 to your computer and use it in GitHub Desktop.
glsl good flames (screen space)
#ifdef GL_ES
precision mediump float;
#endif
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
vec3 iResolution = vec3(resolution.x,resolution.y,100.);
vec4 iMouse = vec4(mouse.x,mouse.y,5.,5.);
float iGlobalTime = time;
uniform sampler2D iChannel0;
// by @301z
float rand(vec2 n) {
return fract(cos(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
}
float noise(vec2 n) {
const vec2 d = vec2(0.0, 1.0);
vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));
return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);
}
float fbm(vec2 n) {
float total = 0.0, amplitude = 1.0;
for (int i = 0; i < 7; i++) {
total += noise(n) * amplitude;
n += n;
amplitude *= 0.5;
}
return total;
}
void main() {
const vec3 c1 = vec3(0.1, 0.0, 0.0);
const vec3 c2 = vec3(0.7, 0.0, 0.0);
const vec3 c3 = vec3(0.2, 0.0, 0.0);
const vec3 c4 = vec3(1.0, 0.9, 0.0);
const vec3 c5 = vec3(0.1);
const vec3 c6 = vec3(0.9);
vec2 p = gl_FragCoord.xy * 8.0 / iResolution.xx;
float q = fbm(p - iGlobalTime * 0.1);
vec2 r = vec2(fbm(p + q + iGlobalTime * 0.7 - p.x - p.y), fbm(p + q - iGlobalTime * 0.4));
vec3 c = mix(c1, c2, fbm(p + r)) + mix(c3, c4, r.x) - mix(c5, c6, r.y);
gl_FragColor = vec4(c * cos(1.57 * gl_FragCoord.y / iResolution.y), 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment