(Demo) Fire Shader

Simple fire shader made with GeeXLab

Here is a simple fire shader based on ideas from this tweet and this tweet.

You can download the GeeXLab demo from THIS LINK (the demo is also available in the full code sample pack in the gl-21/fire-shader/ folder). As usual, GeeXLab can be downloaded from the THIS PAGE.

You should be able to run this demo on any OpenGL 2.1-capable platform: Windows, Linux, macOS and Raspberry Pi with OpenGL desktop enabled.

For any feedback, a thread is available HERE on Geeks3D forums.

Here is a crappy video of the fire shader. Better to see it with GeeXLab!

Here is the pixel shader in GLSL:

#version 120
uniform sampler2D tex_noise;
uniform sampler2D tex_gradient;
uniform sampler2D tex_gradient_color;
uniform sampler2D tex_distortion;
uniform sampler2D tex_color;
uniform float alpha_threshold;
uniform float time;
uniform float speed;
void main (void)
  vec2 uv = gl_TexCoord[0].xy * vec2(4.0, 1.0);
  vec2 uv_noise = uv * 0.3;
  uv_noise.y -= time * speed;
  vec2 uv_grad = uv * vec2(1.0, 1.0);
  vec2 uv_distor = uv;
  vec3 tdistortion = texture2D(tex_distortion,uv_distor).rgb * 0.015;
  vec2 uv_noise_distor = vec2(uv_noise.x + tdistortion.g, uv_noise.y + tdistortion.r);  
  vec3 tnoise = texture2D(tex_noise, uv_noise_distor).rgb;
  tnoise *= 1.75;
  float tgradient = 1.0-texture2D(tex_gradient,uv_grad).r;
  vec3 tgradientcolor = texture2D(tex_gradient_color,uv_grad).rgb;
  vec3 tcolor = texture2D(tex_color,uv_noise_distor*3.0).rgb * vec3(2.0, 1.6, 1.2);
  float alpha0 = (tnoise.x + tnoise.y + tnoise.z) / 3.0;
  float flamewob = ((1.0 + (sin(time + uv.x*8.0) * cos(time - uv.x*5.0)))*0.5) * 0.30;
  float thres = alpha_threshold * tgradient *2.15 + flamewob;
  float alpha = 1.0-smoothstep(thres-0.15, thres+0.3, alpha0);  
  vec3 flame = clamp(tnoise * 2.1, 0.0, 1.0) * tgradientcolor; 
  vec3 color = mix(tcolor, flame, (alpha-alpha0)*1.5);
  gl_FragColor = vec4(color, alpha);

Leave a Comment

Your email address will not be published. Required fields are marked *