Skip to content

vtfpp: distancealpha 2.0 - #154

Merged
craftablescience merged 8 commits into
craftablescience:mainfrom
partyvan:distancealpha-2.0
Oct 25, 2026
Merged

craftablescience merged 8 commits into
craftablescience:mainfrom
partyvan:distancealpha-2.0

Conversation

@partyvan

Copy link
Copy Markdown
Contributor

hoo whee. ok so:

  • using edge reflect could segfault
  • euclidean was meaningless because hits were already getting clamped to a circular radius (this managed to elude me for months :DD)
  • aa was basically doing the opposite of what it was supposed to so i Crafted some Science: img below is the difference between a full-res precise distance function for a couple of shapes, and a --distance-reduce 4 --distance-spread 2 of a half-res antialiased shape, @ 8x bilinear:
    • aadiff
    • aa actually helps a bunch now so at least for the past 5 months it was the thought that counted :')
  • dither did ~nothing outside of a very particular set of images; practically everything about it was wrong and the few textures in my game looked better with it on basically by complete accident because the quadtree was basically one big FIGUREITOUT leaf so the indices weren't completely wrong (but even then it was diffusing error in the wrong direction oopsie)
    • it's roughly on par with a naive floyd-steinberg so hard to say where the value is besides maybe being faster cause it skips a bunch of pixels but hey it's got a unique character to it
  • speaking of faster it goes way faster now thanks to this paper: https://cs.brown.edu/people/pfelzens/papers/dt-final.pdf
    • basically turns the distance transform separable, which is cool except it also discards a bunch of hits, so adapting dither/AA, now that they're Good Actually and not Hot Garbage, was a bit of a pain
      • super extreme reductions with AA are kind of unavoidably slow cause it does still bail out to a manual scan when it didn't get anything close enough from the transform; tying it more tightly/""""elegantly"""" to the transform would basically i think amount to running the transform over a supersampled coverage estimation? cant think of a way youd make that fast on cpu but theres a fun google summer of code project for someone
      • practical settings like --distance-reduce 16 --distance-spread 4 still go basically as fast as plain when you turn on aa, and are noticeably higher quality than default

this was already no-op because the distance always got clipped
at the end anyway WHOOPS LOL
oof ow owie ow. ok so:
- vector distance was just straight up wrong due to a typo
- atan2 had backwards args (certified hood classic)
- quantum divisor was off by one so it wasn't even diffusing the
  right amount of error
- cutesy clever coord flipping wasn't quiiiiite there (projecting
  westward was still possible)
- saved angle wasn't even the one corresponding to the distance hit

wew. previous impl seemed to correct things from a visual inspection
of certain test textures, so i just assumed it was doing its job,
but now it's really cookin. much more noticeable impact on
low-frequency error with big simple shapes. yippee!!!
@craftablescience

Copy link
Copy Markdown
Owner

Holy shit, awesome, thanks!

@craftablescience craftablescience added the enhancement New feature or request label Oct 25, 2026
@craftablescience
craftablescience merged commit 1540277 into craftablescience:main Oct 25, 2026
6 checks passed
@partyvan

Copy link
Copy Markdown
Contributor Author

i leave the particulars of updating language binding docs about the two flags to you, as you've done before, but i've put in a maretf pr that i think says everything it needs to, when maretf gets this sourcepp revision

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants