3D Pixelated Fire Shader

Hello, I created this pixelated fire shader for my project and I wanted to share it with the Godot Shaders community so you guys can use it too.

 

Here’s some quick instructions on how to use it correctly:

  1. Add a MeshInstance3D and add a PlaneMesh in it.
  2. In material or material_override add a ShaderMaterial and add the shader shown below.
  3. In ShaderParameters, add a NoiseTexture2D and customize it at your liking.
    • Recommended settings: 
      • Size: 512×512
      • Seamless: ON
      • Seamless Blend Skirt: 0.0 – 0.2
      • Pixelation: 8×8 – 16×16 – 32×32 – 64×64 – 128×128…
      • Frequency: 0.01
  4. Enjoy the shader!
Shader code
shader_type spatial;

render_mode blend_add, depth_draw_opaque, unshaded, cull_disabled;

uniform sampler2D noise_texture : repeat_enable, filter_nearest;
uniform vec4 color_bottom : source_color = vec4(1.0, 0.9, 0.0, 1.0);
uniform vec4 color_mid : source_color = vec4(1.0, 0.4, 0.0, 1.0);
uniform vec4 color_top : source_color = vec4(0.8, 0.1, 0.0, 1.0);
uniform float speed = 1.5;
uniform float distortion_strength = 0.2;
uniform float pixelation = 32.0;
uniform float emission_energy = 2.0;

void vertex() {
    MODELVIEW_MATRIX = VIEW_MATRIX * mat4(
        vec4(normalize(cross(vec3(0.0, 1.0, 0.0), INV_VIEW_MATRIX[2].xyz)), 0.0),
        vec4(0.0, 1.0, 0.0, 0.0),
        vec4(normalize(cross(INV_VIEW_MATRIX[0].xyz, vec3(0.0, 1.0, 0.0))), 0.0),
        MODEL_MATRIX[3]
    );
    MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX);
}

void fragment() {
    vec2 pixelated_uv = floor(UV * pixelation) / pixelation;

    vec2 scroll = pixelated_uv + vec2(0.0, -TIME * speed * -1.0);
    float noise_val = texture(noise_texture, scroll).r;

    float offset = (noise_val - 0.5) * distortion_strength;
    vec2 distorted_uv = pixelated_uv + vec2(offset, 0.0);
    
    float dist_x = abs(distorted_uv.x - 0.5);
    float mask_x = 1.0 - smoothstep(0.0, 0.5, dist_x);
    
    float mask_y = smoothstep(0.1, 0.5, distorted_uv.y); 

    float shape = mask_x * mask_y * 2.0;
    shape = clamp(shape, 0.0, 1.0);

    float fire_intensity = noise_val * shape;

    fire_intensity = floor(fire_intensity * 4.0) / 4.0;

    vec3 fire_color = color_top.rgb;
    fire_color = mix(fire_color, color_mid.rgb, step(0.3, fire_intensity));
    fire_color = mix(fire_color, color_bottom.rgb, step(0.6, fire_intensity));

    float alpha = step(0.1, fire_intensity);

    ALBEDO = fire_color;
    EMISSION = fire_color * emission_energy;
    ALPHA = alpha;
}
Live Preview
Tags
3d, billboard, fire, pixel, Voxel
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

Related shaders

guest

0 Comments
Oldest
Newest Most Voted