Pixel art anti aliasing #10083
alex5nader
started this conversation in
Ideas
Replies: 4 comments 4 replies
-
Relevant: #9349 |
Beta Was this translation helpful? Give feedback.
1 reply
-
Likewise relevant: #1856 (comment) |
Beta Was this translation helpful? Give feedback.
1 reply
-
For what it counts, I'd love to have this in Bevy. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Unanswered questions are perfectly fine for a PR! Opening a PR would be the best way to make sure your questions don't get accidentally overlooked by the project maintainers. If you don't want it merged yet, just mark as draft. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Objective
Better anti aliasing for upscaled pixel art.
Pixel art often uses nearest-neighbor sampling when upscaling. This works well for 2D environments with an integer scale factor, but otherwise leads to aliasing artifacts.
Solution
I'm proposing an implementation of the solution described in this video: https://youtu.be/d6tp43wZqps
The video explains it well and includes graphics to better illustrate why the process works, but here's a simplified summary if you'd prefer:
Simplified explanation
I've implemented this in my fork here and have a sample project using it here. Because of the following questions, though, I don't think it's ready for a PR quite yet.
Unanswered questions
For the following questions, I'm not sure which approach is best. In the current implementation, I arbitrarily chose to add
pbr_functions::texture_sample
and use a shader definePIXEL_ART_ANTI_ALIASING
. This can be easily changed depending on the discussion.When to check if enabled
To actually implement this strategy within Bevy, all relevant instances of texture sampling must be replaced with this function. I'll call it
pixel_art_texture_sample
. There are a few ways to approach this:texture_sample
) that checks if this feature is enabled. Use this to replace all relevant calls to a built-in texture sample.Pseudocode
pixel_art_texture_sample
.Example
From
pbr.wgsl
:(Most of the builtin texture samples use a mip bias. This can be compensated for as explained here)
How to check if enabled
There are also two approaches for the enabled check itself. We can either add a new shader define, or add a new flag to the standard material's flags.
What is a "relevant texture sample"?
There's also the question of what texture samples should use the new method. Bevy's PBR shaders have many different textures, and any time one of them is sampled, we have to choose whether this new behaviour is necessary.
Obviously, base color texture should use it. Using it for the normal map and emissive textures also seems useful. The metallic/roughness and occlusion textures don't seem particularly likely to be provided with pixel art, but if they were, I think using this technique would produce more consistent results.
There are more texture samples than these in the PBR shaders, though. A grep shows the following files:
I don't really know enough about PBR to judge if these should also use this technique. But, since this technique shouldn't change the overall shape of the texture, perhaps shadows don't need to use it.
Possible issues
Beta Was this translation helpful? Give feedback.
All reactions