Pixelated burn

Heavily inspired by these two shaders
https://godotshaders.com/shader/burn-sprite/
https://godotshaders.com/shader/2d-burn-dissolve-from-point-v-1-0/

I needed something like this but which had both effects (from one point and multiple colors) and also was pixelated, so that it could fit better with pixel art.

Shader code
shader_type canvas_item;

uniform vec2 position;
uniform float radius;
uniform float borderWidth = 0.2;
uniform float burnMult = 0.34;
uniform sampler2D noiseTexture;
uniform vec4 burnColor : source_color;
uniform float pixel_size = 0.004;
uniform float blend_steps = 8.5; // lower number = more saturated

uniform sampler2D colorCurve;


void fragment() {
    vec2 snapped_uv = floor(UV / pixel_size) * pixel_size;

    float dist = length(position - snapped_uv) + (texture(noiseTexture, snapped_uv).b) * burnMult;
    float mask = clamp((dist - (radius - borderWidth)) / (2.0 * borderWidth), 0.0, 1.0);
    mask = 1.0 - mask;
    mask = floor(mask * blend_steps) / blend_steps;
	
    vec4 curve_value = texture(colorCurve, vec2(mask, 0.0));
    
    float blendMask = pow(mask, 0.1); 
    COLOR.rgb = mix(COLOR.rgb, curve_value.rgb, blendMask);
    
	COLOR.a *= min(COLOR.a,1.0-(float(dist<radius)));
}
Live Preview
Tags
burn, disolve, pixel
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

4 Comments
Oldest
Newest Most Voted
shadecore_dev
7 months ago

Very nice effect. Thank you for sharing!

randyheart
1 month ago

Wonderful shader. I think there may be an unintended error that I wanted to bring to your attention or anyone else who may find and use this; I noticed that burnColor is an unused variable. On line 26:

COLOR.rgb = mix(COLOR.rgb, curve_value.rgb, blendMask);

can be corrected to:

COLOR.rgb = mix(COLOR.rgb, curve_value.rgb * burnColor.rgb, blendMask);

I believe this was your intention, or maybe close to it at least. This should at least allow the user to blend to/from the chosen color along a curve.

randyheart
1 month ago
Reply to  randyheart

I was wrong – my edit is unnecessary if you use a gradient1D in the colorCurve parameter and set all your colors within that gradient. My bad!

Last edited 1 month ago by randyheart