The see-through pixels of a PNG still have a colour, and most tools save it as black. When a sprite is scaled with the linear filter, its edge pixels are blended with that hidden black. In our Godot 4.7 test, a white 64 px disc with a hard edge, drawn 2 times larger on a light gray background, got a gray ring when it skipped Godot's Fix Alpha Border: 652 pixels darker than the background, down to 0.64 on a background of 0.80. That happened with Fix Alpha Border turned off in the Import dock, and with the PNG loaded at runtime with Image.load_from_file(). Imported with the default settings, or cleaned with the script below, it had 0. A second cause looks the same: a premultiplied smoke sheet drawn with the normal blend mode had 5,688 pixels darker than the background and kept about half of its white. With the Premult Alpha blend mode, 0.
The code
Save it as clean_png.gd and load it with const CleanPng := preload("res://clean_png.gd"). Use CleanPng.load_texture(path) for a PNG from user://, a mod folder or a download, or CleanPng.clean(image) for an Image you already have. PNGs in your project do not need it: select the PNG, check that Fix Alpha Border is on in the Import dock (it is by default) and click Reimport.
extends RefCounted
## Load a PNG at runtime without a dark fringe around its soft edges.
## Imported PNGs: keep Fix Alpha Border on in the Import dock (it is on by default).
## A PNG you load yourself (mods, user://, downloads) skips the importer, so it is cleaned here.
## const CleanPng := preload("res://clean_png.gd")
## $Smoke.texture = CleanPng.load_texture("user://mods/smoke.png")
static func load_texture(path: String) -> ImageTexture:
var img := Image.load_from_file(path)
if img == null or img.is_empty():
return null
return ImageTexture.create_from_image(clean(img))
static func clean(img: Image) -> Image:
## Gives the see-through pixels the colour of their visible neighbours, so the
## linear filter blends an edge towards the sprite's own colour instead of black.
if img.is_compressed():
img.decompress()
if img.get_format() != Image.FORMAT_RGBA8:
img.convert(Image.FORMAT_RGBA8)
img.fix_alpha_edges()
return img
What we measured
Two 64 px white PNGs saved the way most tools save them, with the fully see-through pixels stored as black (0, 0, 0, 0): a disc with a hard edge and a smoke puff with a soft edge. Each was drawn 2 times larger with the default linear filter on a gray background of 0.80, and we counted the screen pixels darker than the background. White over gray should never be darker than the gray. Two runs gave the same numbers.
- Hard disc, imported with the default settings (the .import file says fix_alpha_border=true): 0 darker pixels.
- Hard disc, imported with Fix Alpha Border off: 652 darker pixels, the darkest 0.64. Loaded at runtime with Image.load_from_file(): the same 652.
- Hard disc, loaded at runtime and cleaned with the script, or with load_texture(): 0.
- Soft smoke in all four of those cases: 0, the darkest 0.79. A soft edge fades out slowly, so it hides the problem.
- Soft smoke as a premultiplied PNG with the normal blend mode: 5,688 darker pixels, the darkest 0.64, and 2,928 white pixels instead of 5,576. With a CanvasItemMaterial set to Premult Alpha: 0 darker and 5,576 white.
- The hard disc loaded at runtime on a dark background of 0.10: 0 pixels darker than the background, so the same ring is easy to miss until the sprite is shown on something light.
Why it happens
The linear filter works out each screen pixel from the 4 texture pixels around it. On the edge of a sprite some of those are see-through, and their colour, usually black, is blended in too. With a hard edge the result is a half see-through dark gray pixel, which shows as a ring on a light background. Fix Alpha Border, and Image.fix_alpha_edges() in code, copy the colour of the visible neighbours into the see-through pixels, so the blend stays white. Godot's importer does this by default, but a PNG loaded at runtime never goes through the importer.
A premultiplied PNG has its colour already multiplied by its alpha. The normal blend mode multiplies by alpha again, so every soft pixel comes out darker and the smoke looks thin and dirty. The Premult Alpha blend mode skips that second multiply.
What to change
- A premultiplied sheet: give the sprite a
CanvasItemMaterialand setblend_modeto Premult Alpha. Check the export settings of the tool that made the sheet if you are not sure which kind it is. - Glowing effects drawn with Add blending have a different problem on light backgrounds: additive particles that disappear on white.
- Lines at the edge of a frame cut from a sprite sheet come from the next cell, not from alpha: filter_clip for sprite sheet frames.
Sheets that are clean on any background: HD VFX Sprite Sheets Vol 1 has 106 effects as transparent PNG sprite sheets for any engine, with smoke and dust that keep their soft edges on light and dark backgrounds. A free sample of 16 2D effects is on the free page.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: HD VFX Sprite Sheets Vol 1 has 106 effects as transparent PNG sprite sheets for any engine, with smoke and dust that keep their soft edges on light and dark backgrounds.
More how-tos for HD VFX Sprite Sheets Vol 1: Play a 2D sprite sheet effect once and remove it, even if its animation loops · Sprite sheet frames without the empty cells
More how-tos: When particles do not show up
- Big particle effects that stay on screen
- Stop flipbook particles from vanishing at the end of their life
- GPUParticles3D not showing in Godot 4
- GPUParticles2D not showing in Godot 4
- GPUParticles2D collision: fall through or vanish
- Particles look black or dark
- Particles only fall down or fly sideways
- Particles not working in a web export
- Particles fall through the floor
- Particles on terrain and uneven ground
- Flipbook animation on GPUParticles3D
- GPUParticles2D sprite sheet not animating
- Pixel art particles look blurry
- Particle trails in the Compatibility renderer
- GPUParticles2D trails not working
- Particle color over lifetime not working
- Particle texture shows a square box
- Custom particle shader ignores the color ramp
- Particle scale curve not working
- Additive particles invisible on a white background
- Scale a 3D particle effect evenly
- Particles the same size on screen at any distance