-
Notifications
You must be signed in to change notification settings - Fork 351
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
Move useNearest from Drawable to Skin #566
Conversation
77df7e3
to
94e681a
Compare
Could you resolve conflicts? |
94e681a
to
0af5331
Compare
Rebased to latest develop |
71b1e0f
to
116db7b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
For some reason this is making vector sprites look blurry |
116db7b
to
cc2bc3d
Compare
Sorry this fell off our radar :/ |
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.
cc2bc3d
to
26d2677
Compare
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; | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
This PR depends on #555
Resolves
Resolves #565
Proposed Changes
This PR moves the
useNearest
method from theDrawable
class to theSkin
class. The default behavior is to always use nearest-neighbor interpolation, butSkin
subclasses can override the method to provide their own behavior, and two currently do:SVGSkin.useNearest
has absorbed the complex logic previously present inDrawable.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 aPenSkin
is displayed at <100% scale.Reason for Changes
I believe this is the clearest way to implement the desired interpolation behavior for
PenSkin
s.Since textures belong to a
Skin
, it makes sense that deciding the proper way to interpolate a texture should be the responsibility of thatSkin
.