Facts
Evidence
Code (2)
Verified (1)
Dev blog (1)
Sources
5
On this page
  1. Related
  2. References
  3. Sources

A subpixel is the undrawn fraction of a pixel in a position or speed. It lets things move by less than a pixel per frame, as in a slow walk. The fraction sits beside the whole-pixel position and carries into it when it adds up to a pixel. Its storage and resolution decide which speeds a game can represent.

  • Super Mario Bros. stores vertical speed as a pixel byte and a fraction byte, in 1/256 px. Each frame, it adds the fraction into a subpixel byte of the position1. Horizontal speeds are coarser, in 1/16 px/frame2.
  • Sonic the Hedgehog keeps 32-bit 16.16 positions and shifts 8.8 speeds into them, so its motion also resolves to 1/256 px3.
  • Celeste keeps whole-pixel positions plus a float remainder per axis, and moves by the rounded remainder4.

All three draw only the whole-pixel part, so jump heights here are in whole drawn pixels.

References

  1. ^CodeXkeeper0/smb1prg.asm 6666–6687
    How we know

    Vertical motion is 8.8 fixed point; each frame, the gravity routine adds speed to position, the fraction via a subpixel byte, then gravity to speed.

    6668	ADC SprObject_Y_MoveForce,x
    6669	STA SprObject_YMF_Dummy,x
    ⋮
    6676	ADC SprObject_Y_Position,x                   ; add vertical position to vertical speed plus carry
    ⋮
    6683	ADC $00                                      ; add downward movement amount to contents of $0433
    ⋮
    6685	LDA SprObject_Y_Speed,x                      ; add carry to vertical speed and store
    
    src/prg.asm lines 6666–6687 at 1cc3c92 · upstream ↗

    Claim page

  2. ^CodeXkeeper0/smb1prg.asm 6492–6503
    How we know

    Horizontal speeds are 4.4 fixed point, whole pixels and sixteenths per frame; the horizontal-move routine shifts the sixteenths into the subpixel byte.

    6495	ASL                                          ; and move low nybble to high
    6496	ASL
    6497	ASL
    ⋮
    6500	LSR                                          ; move high nybble to low
    6501	LSR
    6502	LSR
    6503	LSR
    
    src/prg.asm lines 6492–6503 at 1cc3c92 · upstream ↗

    Claim page

  3. ^Verifiedsonicretro/s1disasm · Sonic Retro, “Sonic Physics Guide: Calculations (Pixel and Subpixel)”sub ObjectFall & SpeedToPos.asm 16–20
    How we know

    In the running game, the object fall routine and the speed-to-position routine move Sonic's 32-bit position each frame by his speed shifted left 8 bits, X by this frame's X speed and Y, in the air, by the Y speed before gravity, so positions are 16.16 and speeds 8.8 fixed point.

    16		move.w	obVelY(a0),d0				; load vertical speed
    17		addi.w	#gravity,obVelY(a0)			; increase vertical speed (apply gravity)
    18		ext.l	d0					; extend speed to longword
    19		asl.l	#8,d0					; shift speed up a byte (16.16 fixed point)
    20		add.l	d0,d3					; add speed to Y-axis position
    
    _incObj/sub ObjectFall & SpeedToPos.asm lines 16–20 at 15dfa3a · upstream ↗
    Each pixel is effectively split into 256 slices along both axis and this means the finest fidelity available for movement is 1/256th of a pixel (aka 0.00390625).
    Pixel and Subpixel · archived copy ↗

    Measured by a script. It fails if the result disagrees with the claim.

    Claim page

  4. ^Dev blogThorson 2020 · NoelFB/CelestePlayer.cs 935
    How we know

    Celeste's actors sit on whole pixels; the vertical move adds the float distance to a remainder, moves by its rounded value, and keeps the fraction.

    xRemainder += amount; int move = Round(xRemainder); if (move != 0) { xRemainder -= move;
    Actor Basics · archived copy ↗
    935                MoveV(Speed.Y * Engine.DeltaTime, onCollideV);
    
    Source/Player/Player.cs line 935 at 1b0ce45 · upstream ↗

    Claim page

Sources

Code

Primary

Secondary