← Pixel Dreamer Studio

Transparent PNGs without a dark outline

Imported PNGs: leave Fix Alpha Border on. PNGs you load yourself: run fix_alpha_edges() on them. Premultiplied sheets: draw them with the Premult Alpha blend mode.

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.

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

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