Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate convex hulls in texture space #724

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

adroitwhiz
Copy link
Contributor

@adroitwhiz adroitwhiz commented Nov 9, 2020

Depends on #479

Resolves

Resolves #208
Resolves #528
Resolves #592

Proposed Changes

(The last 4 commits contain actual changes--everything else is part of a rebase)

The first commit adds some handy debugging code that draws drawables' convex hulls when getBounds is called and there is a "debug canvas". The code previously only drew bounding boxes. This should make it easier to debug convex hull issues.

The second commit changes the convex hull calculation to operate in texture space--it now samples every texture pixel rather than every "Scratch-space" pixel. This ensures, for instance, that every pixel is counted on double-resolution bitmap sprites.

The third commit incorporates the bounds expansion from #529, but in a more precise way that doesn't "overshoot" at all--it now precisely calculates the dimensions of a rotated costume pixel and expands the bounds outwards by that much.

The fourth commit makes drawables now mark their convex hull as "dirty" (needing to be recalculated) if their skin's silhouette is updated. This is used for SVG skins, which update their silhouette every time a larger mipmap is calculated.

Reason for Changes

This should make the calculation of sprites' "precise"/"tight" bounds, which use the convex hull, visually match up much better with reality, and prevent sprites from being cut off as a result of their bounds being calculated too far inwards.

Test Coverage

I'd love to add convex hull tests, but I'm not sure how to run Node unit tests on real skins.

Christopher Willis-Ford and others added 14 commits March 3, 2024 14:29
Previously, the `color-touching-tests.sb2` test "touches a color that
doesn't actually exist right now" would use a sprite with ghost 50,
blended against another sprite, to create the color that "doesn't
actually exist" when the query sprite is skipped. Unfortunately the
blend result was near a bit-boundary and, depending on the specific
hardware used, that test could fail on the GPU. When the renderer uses
the CPU path this test works fine, though, so the existing problem went
unnoticed.

To fix the problem I changed the project to use ghost 30 instead, which
results in a color that is less near a bit boundary and is therefore
less likely to fail on specific hardware.

As an example of what was happening: the `touching color` block was
checking for `RGB(127,101,216)` with a mask of `RGB(0xF8,0xF8,0xF0)`. On
the CPU it would find `RGB(120,99,215)`, which is in range, but on some
GPUs the closest color it could find was `RGB(119,98,215)` which
mismatches on all four of the least significant bits -- one of which is
enabled in the mask.
Fix direction for Y iteration on CPU path

For some reason the JavaScript engine insists on running the code
instead of doing what the comment says. I guess they should match.

Fix (x,y) => point[] conversion comments
This should ensure that CPU/GPU diffs are actually useful,
and not improperly shifted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant