Fire Shader

This is a fire shader for 3D meshes.

You can change by shader parameters:

  • noise texture
  • fire root color
  • fire tip color
  • fire alpha
  • fire animation speed
  • fire aperture

and You can see 2D version fire shader on here

Shader code
/*
	炎シェーダー by あるる(きのもと 結衣)
	Fire Shader by Yui Kinomoto @arlez80

	MIT License
*/
shader_type spatial;
render_mode depth_draw_opaque, unshaded, shadows_disabled;

uniform sampler2D noise_tex : hint_white;
uniform vec4 root_color : hint_color = vec4( 1.0, 0.75, 0.3, 1.0 );
uniform vec4 tip_color : hint_color = vec4( 1.0, 0.03, 0.001, 1.0 );

uniform float fire_alpha : hint_range( 0.0, 1.0 ) = 1.0;
uniform vec2 fire_speed = vec2( 0.0, 1.0 );
uniform float fire_aperture : hint_range( 0.0, 3.0 ) = 0.22;

/*
	noise_texを使わないパターン

float random( vec2 pos )
{ 
	return fract(sin(dot(pos, vec2(12.9898,78.233))) * 43758.5453);
}

float value_noise( vec2 pos )
{
	vec2 p = floor( pos );
	vec2 f = fract( pos );

	float v00 = random( p + vec2( 0.0, 0.0 ) );
	float v10 = random( p + vec2( 1.0, 0.0 ) );
	float v01 = random( p + vec2( 0.0, 1.0 ) );
	float v11 = random( p + vec2( 1.0, 1.0 ) );

	vec2 u = f * f * ( 3.0 - 2.0 * f );

	return mix( mix( v00, v10, u.x ), mix( v01, v11, u.x ), u.y );
}

float procedural_noise_tex( vec2 shifted_uv )
{
	return (
		value_noise( shifted_uv * 0.984864 ) * 20.0
	+	value_noise( shifted_uv * 2.543 ) * 10.0
	+	value_noise( shifted_uv * 9.543543 ) * 8.0
	+	value_noise( shifted_uv * 21.65436 ) * 5.0
	+	value_noise( shifted_uv * 42.0 ) * 2.0
	+	value_noise( shifted_uv * 87.135148 ) * 2.0
	+	value_noise( shifted_uv * 340.66534654 )
	) / 48.0;
}
*/

void fragment( )
{
	vec2 shifted_uv = UV + TIME * fire_speed;
	float fire_noise = texture( noise_tex, shifted_uv ).r;
	float noise = UV.y * ( ( ( UV.y + fire_aperture ) * fire_noise - fire_aperture ) * 75.0 );
	vec4 fire_color = mix( tip_color, root_color, noise * 0.05 );

	ALPHA = clamp( noise, 0.0, 1.0 ) * fire_alpha;
	ALBEDO = fire_color.rgb;
}
Tags
fire, Procedural
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from arlez80

Saw Transition Shader

Procedural Burberry Check Shader

Anime-esque Quicksand Shader

Related shaders

Stylized fire (3D)

Procedural Marble Shader

Voronoi Synapse-ish Background Shader

guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Jesper B. Bech
Jesper B. Bech
1 year ago

I downloaded this, and using it, in my Godot games <3 Thank you . . .