precision mediump float; uniform vec2 u_resolution; uniform float u_time; float random(in vec2 st) { return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123); } // based on Morgan McGuire @morgan3d // https://www.shadertoy.com/view/4dS3Wd float noise(in vec2 st) { vec2 i = floor(st); vec2 f = fract(st); // four corners in 2D of a tile float a = random(i); float b = random(i + vec2(1.0, 0.0)); float c = random(i + vec2(0.0, 1.0)); float d = random(i + vec2(1.0, 1.0)); vec2 u = f * f * (3.0 - 2.0 * f); return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y; } #define OCTAVES 7 float fbm(in vec2 st) { // initial values float value = 0.0; float amplitude = 1.; float frequency = 0.; // loop of octaves for(int i = 0; i < OCTAVES; i++) { value += amplitude * noise(st); st *= 2.; amplitude *= .5; } return value; } void fire(out vec4 fragColor, in vec2 fragCoord) { const float speed = 100.; const float details = 0.04; const float force = 0.6; const float shift = 0.4; const float scaleFactor = 1.6; // noise vec2 xyFast = details * vec2(fragCoord.x, fragCoord.y - u_time * speed); float noise1 = fbm(xyFast); float noise2 = force * (fbm(xyFast + noise1 + u_time) - shift); float nnoise1 = force * fbm(vec2(noise1, noise2)); float nnoise2 = fbm(vec2(noise2, noise1)); // cg (blue fire) const vec3 steelBlue = vec3(0.14, 0.42, 0.55); const vec3 lightSteelBlueBlue = vec3(0.56, 0.56, 0.73); const vec3 darkBlue = vec3(0.1, .1, 0.3); const vec3 dark = vec3(.1, .1, 0.8); vec3 c1 = mix(steelBlue, darkBlue, nnoise1 + shift); vec3 c2 = mix(lightSteelBlueBlue, dark, nnoise2); // mask vec3 gradient = vec3(scaleFactor * fragCoord.y / u_resolution.y) - shift; vec3 c = c1 + c2 - gradient - noise2; fragColor = vec4(c, 1.); } void main() { fire(gl_FragColor, gl_FragCoord.xy); }