bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
36.75k stars 3.62k forks source link

Implementing PixelArt scaling mode in ImageSampler #9349

Open Veliladon opened 1 year ago

Veliladon commented 1 year ago

What problem does this solve or what need does it fill?

Right now we have two options for scaling with pixel art: Nearest and Linear. Nearest is great for integer scaling, Linear has the trademark blurriness that accompanies Bilinear filtering.

What solution would you like?

Cole Cecil has come up with an innovative way to take advantage of bilinear filtering using a custom vertex and fragment shader to implement arbitrary scaling factors with a minimal amount of blurriness:

https://colececil.io/blog/2017/scaling-pixel-art-without-destroying-it/

I think it would be great to implement on the 2D camera as a scaling method.

What alternative(s) have you considered?

I'm currently using nearest using only integer scaling factors. This would enable arbitrary scaling factors.

Additional context

I'd really like to help implement this because it'd be a great learning exercise. I'm just not sure where I'd start to implement a custom set of shaders into the pipeline.

dmyyy commented 1 year ago

Previous discussion on a pixel perfect shader: https://github.com/bevyengine/bevy/issues/1856

Seems like there is a pixel camera plugin here: https://github.com/drakmaniso/bevy_pixel_camera

It doesn't currently use a shader because of issues with sprites: https://github.com/drakmaniso/bevy_pixel_camera/issues/11

As an aside - I think this makes sense in a 3d context as well for billboarded sprites. It makes sense to me to implement this as a custom material on Image - that way it can be used both in 2d/3d and avoids the issues bevy_pixel_camera has. There's several approaches that can be taken here so I'm curious what other people think.

Relevant video for 3d: https://youtu.be/d6tp43wZqps