Sprite White Edges and Halos: Causes and Fixes for Godot and Unity

· 9 min read · Loopixel team

Engine options checked against the official docs; problem versions in the figures are simulated

A pixel character on white, black and blue backgrounds with hard edges above and a simulated soft-edged version below

The sprite looked clean on a transparent canvas. In the engine there is a thin white line around it, or a dark one, or a faint coloured rim that changes with the background. The art is not wrong: the edge pixels hold colour that does not belong to the character, and filtering, scaling or alpha handling in the engine makes that colour visible. This guide shows where the rim comes from, how to tell which kind you have in under a minute, and the exact settings for Godot 4, Unity and Aseprite.

On this page · 7

Where the rim comes from

A pixel in a PNG has a colour (red, green, blue) and an opacity (alpha). In a soft-edged sprite, the pixels on the outline have an alpha between 0 and 255. When the file was made, those pixels were blended with whatever was behind the character: often a white or black canvas, or the colour left over in a “transparent” area. The engine draws the pixel with the remembered colour at partial opacity. On a background that matches that colour you see nothing; on any other background you see a rim.

Five things make it worse, and they often stack:

CauseWhat happensHow it looks
Anti-aliased edge (alpha 1–254)Outline pixels are half transparent and blended with the old backgroundRim in the old background colour
Colour under transparencyFully transparent pixels hold white or black. Filtering mixes that colour into neighboursWhite or dark halo, even on a hard edge
Bilinear filteringThe GPU averages the colour and the alpha of the nearest four pixelsA soft 1 px band around the sprite
MipmapsSmaller copies of the texture are built by the same averagingRim gets thicker when the sprite is drawn smaller
Straight vs premultiplied alphaA texture is treated as one kind but stored as the otherDark or bright outline on every edge
A pixel character on white, black and blue backgrounds: the top row with hard alpha edges, the bottom row with a simulated soft edge that shows a light rim on dark and blue backgrounds
Top: one real Loopixel frame at 3× on three backgrounds. Bottom: the same frame as a problem version. The problem version is simulated: the transparent area was given a white colour and the frame was resized 3× with a bilinear filter. It illustrates the effect and is not an engine capture.

Tell which kind you have

  1. Place the sprite on three backgrounds: white, black and a saturated colour (the engine’s clear colour works). A rim that changes colour with the background is a semi-transparent edge. A rim that is the same on all three is something else, such as a drawn outline.
  2. Zoom in with the Nearest or Point filter. If the rim vanishes, the cause was filtering mixing colour from transparent neighbours.
  3. Open the PNG in an editor and read the alpha of one edge pixel. Anything between 1 and 254 is a soft edge. In an engine this is the same question as “does the rim move when I change the filter or scale?”.
  4. Scale the sprite up and down in the scene. If the rim gets thicker when the sprite is small, mipmaps are on.
Alpha values along one pixel row: 0 then 255 for the Loopixel frame, and 0, 85, 170, 255 after a bilinear resize
Alpha along the same pixel row. Top: the real Loopixel frame jumps from 0 to 255. Bottom: the simulated 3× bilinear version adds in-between values (85 and 170 here). Those in-between pixels are the rim.

Fix it in Godot 4

  1. Set the texture filter to Nearest: Project Settings > Rendering > Textures > Canvas Textures > Default Texture Filter, or per node under CanvasItem > Texture > Filter. Godot describes Nearest as reading from the nearest pixel only, so no colour is mixed in from transparent neighbours.
  2. Select the PNG in the FileSystem dock and open the Import dock. Keep Process > Fix Alpha Border on. It is on by default and puts pixels of the same surrounding colour in the transition from transparent to opaque areas, which the docs say helps with the outline effect when textures are drawn with bilinear filtering.
  3. Leave Mipmaps > Generate off for 2D pixel art. Godot’s 2D defaults are no mipmaps and Lossless compression. If a texture is detected as used in 3D, Godot turns mipmaps on and changes compression, so check the Import dock if a sprite gets worse after reimport.
  4. Only use Process > Premult Alpha if you know you need it. The docs say a premultiplied texture needs a CanvasItemMaterial with the Premul Alpha blend mode on the nodes that use it, otherwise it draws wrong.
  5. Click Reimport, then check the sprite on a white, a black and a coloured background again.

If the filter is Nearest and the rim is still there, the PNG itself has semi-transparent edge pixels. Jump to repair an existing PNG. Blur and shimmer are a different symptom with a different cause; see the blurry pixel art guide.

Fix it in Unity

  1. Select the PNG. For a sprite sheet set Texture Type to Sprite (2D and UI), Filter Mode to Point (no filter), and Compression to None (the 2D Pixel Perfect package documentation asks for this).
  2. Turn mipmaps off. The Sprite reference calls the option Generate Mipmap; older versions label it Generate Mip Maps.
  3. Look for Alpha is Transparency in the texture’s import settings. Unity describes it as dilating the colour channels, which helps avoid filtering artifacts on the edges of the alpha channel when alpha represents transparency. It is documented on the Default texture type; on a Sprite texture, check whether your Unity version shows it, and if not rely on Point filtering and a clean PNG.
  4. Click Apply, then test on a light and a dark background.
CheckGodot 4Unity
FilterNearestPoint (no filter)
Edge colour bleedProcess > Fix Alpha Border (on by default)Alpha is Transparency
MipmapsGenerate offGenerate Mipmap off
CompressionLosslessNone
Premultiplied alphaProcess > Premult Alpha only with a Premul Alpha materialNo matching setting verified for this post; start with Point filtering and a clean PNG

Repair an existing PNG

When the file itself has a soft edge, engine settings only hide part of it. The fix is two steps, done in an image editor or a short script:

  1. Make alpha hard. Pick a threshold (128 is a sensible start): every pixel at or above it becomes fully opaque, every pixel below it fully transparent. Check the silhouette; a threshold that is too low fattens the sprite, too high thins it.
  2. Fix the colour of the new edge. Pixels that were half transparent still carry a blended colour. Replace each one with the average colour of its fully opaque neighbours. Godot’s Fix Alpha Border and Unity’s Alpha is Transparency are the engine-side version of the same idea.
The simulated soft-edged sprite on white, black and blue backgrounds, above the same sprite after an alpha threshold and edge colour repair with the rim gone
Top: the simulated problem version from above. Bottom: the same image after the two steps (alpha cut at 128, edge colour from the solid neighbours). The problem input was simulated with a bilinear resize; the repair was applied to that simulated image.

In Aseprite, working in Indexed colour mode avoids semi-transparent pixels as long as the palette colours are fully opaque: the Aseprite docs explain that transparent areas in indexed mode use one special palette index, so a pixel is either that index or a palette colour. Export with File > Export Sprite Sheet. If you resize a sprite, use a nearest-neighbour method, not a smoothing one.

Hard alpha from the start

A Loopixel sprite sheet has no semi-transparent pixels: the facts page lists alpha as hard, every pixel fully opaque or fully transparent. In the pipeline, each frame size is downscaled with area averaging and then cut at half coverage, so an edge pixel becomes solid or empty. In the sheets checked for this post, the fully transparent pixels hold black with alpha 0.

That removes the anti-aliased rim at the source. It does not make the engine settings optional: filtering still mixes the colour of neighbouring pixels, and a black colour under transparency can show as a faint dark line if you draw a Loopixel sheet with a smoothing filter. So the checklist is short: Nearest or Point filter, no mipmaps, no lossy compression. The Godot, Unity and Aseprite guides cover importing the sheet, and the slicing guide covers cell size. To preview a sheet as a transparent GIF, use sprite sheet to GIF.

Quick answers

Why is the rim white in one scene and invisible in another?

Because the rim is the old background colour at partial opacity. It disappears on a background of the same colour and shows on every other one.

Is a GIF the problem?

GIF has one transparent colour and no partial transparency, so a GIF made from a soft-edged animation either keeps a matte rim or cuts it hard. If you only see the rim in a GIF, export the animation from the PNG with a hard alpha instead of converting a flattened version.

Should I just use premultiplied alpha?

Only if your renderer and materials expect it. Per the Godot docs it needs a matching blend mode; turning it on without one creates a new rim instead of removing the old one. For pixel art, hard alpha with Nearest filtering is the simpler route.

Sources

Engine menu paths and property names above were checked against the official documentation:

Try it with one image

Upload one image and get an 8-frame pixel sprite sheet in about a minute. 1 credit per animation, credit packs from $2.99, paid once.

Create a sprite sheet