thombruce / verse

🚀 A universe in progress
Other
8 stars 0 forks source link

Image Pixelation [Hypothetical] #26

Closed thombruce closed 1 year ago

thombruce commented 1 year ago

One way to pixelate coordinates is to multiply the UVs by a large number, floor them, and then divide by that same number

Source: https://youtu.be/pGOLstWBCDA?si=WuHGnX0LaNb-VpTq&t=497


This is a question of art style, but I do think we're eventually aiming for that pixelated kind of look and feel - retro vibes. I'd been thinking about this in terms of rotation... How do we rotate a pixelated ship and still have those pixels oriented along X and Y instead of some diagonal?

The solution may be to do the above. But then there's the follow up question of, well okay, does that mean we ought to use larger sprites? Probably.


This Bevy crate is also worth a look: https://github.com/drakmaniso/bevy_pixel_camera I don't think it handles the pixelation though; merely corrects some of the camera settings for use with pixel art?

See also, the Bevy pixel perfect example: https://bevyengine.org/examples/2D%20Rendering/pixel-perfect/ This isn't applying any such effect, but it does clearly show some of the core settings we do need to adjust.

thombruce commented 1 year ago

Consider in parallel with #21: 2D Lighting

If the lighting from bevy-magic-light-2d can also be pixelated correctly on our pixel grid, that's a massive win.

All of these considerations are art direction, for which I should probably add an issues tag.

thombruce commented 1 year ago

Also, knowing the pixel scale of our screen would be a massive help in determining planet sizes generated from the Pixel Planets shaders I intend to implement (#25). It also yields the question: What's more efficient? Regenerating the planets when the camera is scaled, or generating the planet once and applying the pixelation filter as we would for rotating objects? Speaking of which...

Do we only need to recalculate pixels if an object's angvel is non-zero and/or if the camera is scaling? 'Cause adding those conditionals could be a big performance saver if this is costly to compute.

thombruce commented 1 year ago

Pixel perfect imagery probably means we'd prefer pixel perfect movement too. Should sprites only move integer values? If so, how would we handle this?

No need to contemplate this too hard yet. This is a stylistic tweak that may not be needed at all, and is left here for reference at a later time.

thombruce commented 1 year ago

Shaders are tricky, a lot of work.

I did manage to get this example to work by porting the code to my camera module: https://github.com/bevyengine/bevy/blob/main/examples/shader/post_processing.rs (_The shader it uses is here: https://github.com/bevyengine/bevy/blob/main/assets/shaders/post_processing.wgsl_)

I then tried to port some pixelation shader code from here: https://github.com/torsteingrindvik/bevy-vfx-bag/blob/main/assets/shaders/pixelate.wgsl Couldn't get that to work.

Tried installing the crate it's from. Specifically ivakam's v0.11 upgrade found here: https://github.com/ivakam/bevy-vfx-bag This also doesn't wanna work - maybe because I'm using a 2D camera?


So the only thing I have managed to get working is the wrong effect for my purposes.

That said...

This crate does have a chromatic aberration effect as well. I could try to re-port the original CA effect again (done - Ctrl+Z'd a bunch but I got there), then compare to this crate's implementation of the same effect... and see if I can work out from those how I need to modify the pixelate effect to get it working.