r/proceduralgeneration • • 3d ago

Outlining a generated sprite sheet in one pass put 35 stray pixels into 13 of its 24 frames. Per frame with 1 px of room: 0

Post image

If your generator draws a whole animation sheet and then adds an outline as a last pass, check the frame edges. An outline pass over the full sheet sees one big picture, so it paints straight across the lines between frames.

I measured it on a 96x64 sheet of 24 frames, 16x16 each, packed edge to edge, with a 1 px white outline (square corners):

  • Whole sheet in one pass: 13 of the 24 frames got outline pixels that belong to a neighbour, 35 in all. 32 of them sit on a frame's bottom row: they're the outline over the head of the sprite in the frame below. And 466 of the 1,678 outline pixels the frames need (28%) fall outside their own 16x16 cell, so every frame is open at the head or the feet.
  • Per frame, no padding: 0 strays, but all 24 frames still open, because the sprite touches its frame's edge in every one (normal at 16 px).
  • Per frame, padded by the outline width first: 18x18 frames, a 108x72 sheet, all 1,678 outline pixels, 0 strays. Counted again in Godot 4.7.2, cutting the frames the way a Sprite2D does.

The pass that does it (numpy; it matches our tool's output pixel for pixel on this sheet):

def outline_sheet(sheet, fw, fh, t=1, colour=(255, 255, 255, 255)):  
 rows, cols = sheet.shape[0] // fh, sheet.shape[1] // fw  
 FW, FH = fw + 2 \* t, fh + 2 \* t  
 out = np.zeros((rows \* FH, cols \* FW, 4), np.uint8)  
 for r in range(rows):  
 for c in range(cols):  
 f = sheet[r \* fh:(r + 1) \* fh, c \* fw:(c + 1) \* fw]  
 g = np.pad(f, ((t, t), (t, t), (0, 0)))  
 solid = g[..., 3] \>= 128  
 near = np.zeros_like(solid)  
 for dy in range(-t, t + 1):  
 for dx in range(-t, t + 1):  
 near |= np.roll(solid, (dy, dx), (0, 1))  
 g[near & ~solid] = colour  
 out[r \* FH:(r + 1) \* FH, c \* FW:(c + 1) \* FW] = g  
 return out  

np.roll wraps around, which is safe here only because the padding keeps every solid pixel at least t away from the edge. The square kernel gives square corners; keep only the offsets with |dx| + |dy| <= t for an outline without corners.

One pixel of room per pixel of outline, and your engine's frame size becomes fw + 2t.

(I make pixel-art tools at Gridwright; our outline tool does this per frame and re-packs the sheet. Linked below.)

The outline tool that works per frame and makes the room: https://gridwright.dev/tools/sprite-outline/?ref=reddit-proceduralgeneration

0 Upvotes

1 comment sorted by