Canva Fire

Custom this to make it better

Shader code
shader_type canvas_item;

uniform float speed : hint_range(0.5, 8.0) = 3.0;
uniform float noise_scale : hint_range(1.0, 20.0) = 6.0;
uniform float distortion : hint_range(0.0, 1.0) = 0.45;
uniform float flame_height : hint_range(0.3, 1.0) = 0.85;
uniform vec4 core_color : source_color = vec4(1.0, 0.9, 0.4, 1.0);
uniform vec4 outer_color : source_color = vec4(1.0, 0.25, 0.05, 1.0);

float hash(vec2 p) {
	return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);
}

float noise(vec2 p) {
	vec2 i = floor(p);
	vec2 f = fract(p);
	vec2 u = f * f * (3.0 - 2.0 * f);
	return mix(
		mix(hash(i + vec2(0.0, 0.0)), hash(i + vec2(1.0, 0.0)), u.x),
		mix(hash(i + vec2(0.0, 1.0)), hash(i + vec2(1.0, 1.0)), u.x),
		u.y
	);
}

float fbm(vec2 p) {
	float val = 0.0;
	float amp = 0.5;
	for (int i = 0; i < 4; i++) {
		val += amp * noise(p);
		p *= 2.02;
		amp *= 0.5;
	}
	return val;
}

void fragment() {
	float y_norm = clamp((0.9 - UV.y) / flame_height, 0.0, 1.5);
	float taper = mix(0.8, 3.2, y_norm); // Càng lên cao càng nhọn
	vec2 shape_uv = vec2((UV.x - 0.5) * 2.0 * taper, (UV.y - 0.72) * 2.0);
	float dist = length(shape_uv);

	float n = fbm(UV * noise_scale + vec2(0.0, TIME * speed));
	float warped_dist = dist + (n - 0.45) * distortion * (0.4 + y_norm);

	float radius = 0.65;
	float edge_softness = 0.1;
	float mask = 1.0 - smoothstep(radius - edge_softness, radius + edge_softness, warped_dist);

	float top_fade = 1.0 - smoothstep(0.65, 1.05, y_norm);

	float heat = clamp(1.0 - (warped_dist / radius), 0.0, 1.0);
	vec3 col = mix(outer_color.rgb, core_color.rgb, pow(heat, 1.8));
	float alpha = mask * top_fade;

	COLOR = vec4(col, alpha);
}
Live Preview
Tags
fire, simulation
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

Comments 0

No comments yet.