Skip to content

Move useNearest from Drawable to Skin #566

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

Merged
merged 3 commits into from
Nov 13, 2020

Conversation

adroitwhiz
Copy link
Contributor

This PR depends on #555

Resolves

Resolves #565

Proposed Changes

This PR moves the useNearest method from the Drawable class to the Skin class. The default behavior is to always use nearest-neighbor interpolation, but Skin subclasses can override the method to provide their own behavior, and two currently do:

  • SVGSkin.useNearest has absorbed the complex logic previously present in Drawable.useNearest (checking if certain effects are set, the sprite is rotated, and the scale is close to 100%).
  • PenSkin.useNearest will use nearest-neighbor interpolation when being scaled up, and linear interpolation when being scaled down. This prevents pen lines from appearing "dashed" when a PenSkin is displayed at <100% scale.

Reason for Changes

I believe this is the clearest way to implement the desired interpolation behavior for PenSkins.

Since textures belong to a Skin, it makes sense that deciding the proper way to interpolate a texture should be the responsibility of that Skin.

@fsih
Copy link
Contributor

fsih commented Jun 25, 2020

Could you resolve conflicts?

@adroitwhiz
Copy link
Contributor Author

Rebased to latest develop

@adroitwhiz adroitwhiz force-pushed the usenearest-skin branch 3 times, most recently from 71b1e0f to 116db7b Compare July 24, 2020 16:05
fsih
fsih previously approved these changes Jul 24, 2020
Copy link
Contributor

@fsih fsih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@adroitwhiz
Copy link
Contributor Author

For some reason this is making vector sprites look blurry

@fsih
Copy link
Contributor

fsih commented Sep 24, 2020

Sorry this fell off our radar :/
It looks like there's a somewhat tricky conflict here, do you mind resolving it?

This makes the code messier but I'm not sure what else to do since the
texture filtering method to be used depends on the drawable's properties
(e.g. transform, enabled effects). We still need to pass in the scale
separately because in the main rendering path, we multiply it by the
screen-space scale factor.
Comment on lines +64 to +76
if ((drawable.enabledEffects & (
ShaderManager.EFFECT_INFO.fisheye.mask |
ShaderManager.EFFECT_INFO.whirl.mask |
ShaderManager.EFFECT_INFO.pixelate.mask |
ShaderManager.EFFECT_INFO.mosaic.mask
)) !== 0) {
return false;
}

// We can't use nearest neighbor unless we are a multiple of 90 rotation
if (drawable._direction % 90 !== 0) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of keeping the drawable.useNearest function, having these lines stay there, and then having it return skin.useNearest? Then both drawable and skin get to have a say in whether we useNearest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are very SVGSkin-specific--it kinda sucks that SVGSkin depends on its parent drawable to know whether it should use nearest-neighbor interpolation but I'm not sure what else can be done.

Copy link
Contributor

@cwillisf cwillisf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks!

There are some weird things going on here -- such as https://github.com/LLK/scratch-render/pull/566/files#r510419973 -- but after some thinking and discussing I think I agree that the weirdness is sort of inherent to the way it's all set up and isn't a problem introduced by this change. Maybe we can find a way to clean it up later, but I'm happy to move forward.

@cwillisf cwillisf merged commit c19971b into scratchfoundation:develop Nov 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pen lines appear dashed in small stage mode
3 participants