Orama-Interactive / Pixelorama

Unleash your creativity with Pixelorama, a powerful and accessible open-source pixel art multitool. Whether you want to create sprites, tiles, animations, or just express yourself in the language of pixel art, this software will realize your pixel-perfect dreams with a vast toolbox of features. Available on Windows, Linux, macOS and the Web!
https://orama-interactive.itch.io/pixelorama
MIT License
6.83k stars 372 forks source link

Layer blend modes #911

Closed OverloadedOrama closed 10 months ago

OverloadedOrama commented 11 months ago

Alternative to #688, much more straightforward way to handle layer blending now that we use Godot 4, but I would really appreciate feedback as I'm not sure if this is the best way to handle layer blending and if it has any disadvantages over any other methods. CC @AlphinAlbukhari @mrtripie.

I also didn't encounter any layer limit with this method, I tested up to 300 layers and it seemed to be working perfectly with no performance issue. I did have to add a 1024 layer limit though in order to pass opacities and blend modes for each layer as arrays to the shader, since shaders don't support uniform arrays with unknown sizes. I am worried that 1024 might be too high for certain GPUs, so we may have to lower the number even more. Alternatively, we could either pass opacities and blend modes as textures, where each pixel would represent a layer, or we could change the shader code during runtime to update the size of the array, although I am worried this might affect performance as we would re-generate the shader every time we add or remove a layer.

image

Current blending modes supported (thanks to #688 and https://godotshaders.com/snippet/blending-modes/):

This PR only works as a preview, I would like feedback first to ensure that this method is indeed a good one before I continue the work.

To-do:

Can be done after this PR is merged:

OverloadedOrama commented 10 months ago

I think I will merge this PR as it is so it will get tested more as part of the master branch, and potential issues can be fixed later. For now, it should be stable enough.