Baltor Get started

Gallery / Godot shaders

Pixel-exact sprite outline

In your harnessGodot shaderMIT

Draw an outline of a chosen width in texels around the opaque shape of a 2D sprite, with square or rounded corners, for selection highlights, pickups and pixel art.

Render of Pixel-exact sprite outline
The render its check recorded in Godot 4.7.2, 256 by 256 pixels.

What it takes and gives

Shader type
canvas_item
Parameters
outline_color (vec4 = 1, 1, 1, 1), thickness (int = 2), alpha_cutoff (float = 0.5), rounded (bool = yes), outline_only (bool = no)
Use it on
A sprite texture with transparent space around the shape, assigned to the node as usual. The outline is drawn inside the texture's rectangle, so leave a margin at least thickness texels wide.
Result
The sprite with a solid line of the chosen colour hugging its silhouette.
Renderers
compatibility: compiled and rendered, forward plus: not verified, mobile: not verified
Placement
res://baltor/godot_shaders/sprite_pixel_outline/

Limits. The outline cannot extend past the texture rectangle; trim or pad sprites accordingly. Cost grows with the square of thickness (up to 289 samples at 8). With texture filtering on and the sprite scaled, edges are as soft as the texture sampling. Texture atlases need padding between regions or neighbouring sprites bleed into the outline.

Details

Kind
Godot shader
Engine
Godot 4.3 or later
Files
11 files, 65.8 KB
Licence
MIT
Declared effects
reads files, runs commands
Checked with
Godot 4.7.2, opengl3 compatibility (Mesa llvmpipe, Xvfb)
Checks
contract static, engine run, engine log clean, shader in scene, capture written, render not uniform, shader changes pixels
Techniques
Neighbourhood alpha dilation, Euclidean and Manhattan distance kernels
Tags
godot shader, canvas item, outline, sprite, pixel art, 2d, selection
Identity
library.supply.creative_originals.826eadd85ff1007a761a50f8.327e6c138f4c7083
Version
327e6c138f4c7083a18d3dcfab497f05e5f6790d7a2deb6c6e84d7468ba9106d

The version is the SHA-256 of the item your harness downloads; every file in it names its own checksum.

Something wrong with this item, its rights or its safety? Report it on the support page, or from your harness after a download.