Pixelated Fire

A simple 3D billboard fire shader for retro styled games. Comes with the ability to set pixelation level and FPS.

This shader was made for my game EXUVIA

How to use:

  1. Create a MeshInstance3D node with a QuadMesh property.
  2. Add the shader to the node’s Material property.
  3. Add your flame texture to the shader’s Albedo Texture property.
  4. Add a NoiseTexture2D to the shader’s Noise Texture property.
  5. Set the Noise Texture‘s Seamless and Normalize properties to True.
  6. Experiement with changing the parameters of the shader to achieve your ideal result.
Shader code
shader_type spatial;
render_mode unshaded;

uniform sampler2D albedo_texture: source_color, filter_nearest, repeat_disable;
uniform sampler2D noise_texture: source_color, filter_linear;
uniform float intensity = 0.7;
uniform float framerate = 30.0;
uniform float resolution = 64.0;

void vertex() {
	MODELVIEW_MATRIX = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], INV_VIEW_MATRIX[1], INV_VIEW_MATRIX[2], MODEL_MATRIX[3]);
}

void fragment() {
    vec2 flame_uv = (floor(UV * resolution) + 0.5) / resolution;
    vec2 uv = flame_uv - vec2(0.0, 0.2);

    float vertical_intensity = (1.0 - flame_uv.y) * intensity;
	
	float time_seed = (NODE_POSITION_WORLD.x + NODE_POSITION_WORLD.y + NODE_POSITION_WORLD.z);
	float frame_time = floor(TIME * framerate) / framerate;
	float time = (frame_time * 10.0) + time_seed;
	float noise_time = (frame_time * 1.0) + time_seed;

    float noise = texture(noise_texture, flame_uv + vec2(sin(noise_time + vertical_intensity * 10.0) * 0.1, noise_time)).r;
    float normal_noise = noise - 0.5;

    float flame_offset = sin(time + uv.y * 10.0 * noise);

    uv.y += flame_offset * (vertical_intensity * 0.1);
    uv.x += normal_noise * 0.5 * vertical_intensity;

    vec4 color = texture(albedo_texture, uv);

    ALBEDO = color.rgb + (noise * vertical_intensity);
    ALPHA = color.a;
}
Live Preview
Tags
fire, pixel, psx, retro
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.

More from Elliptical

Related shaders

guest

0 Comments
Oldest
Newest Most Voted