Skip to content

Move image scaling into the UI shaders rather than precomputing it on the CPU

Imbris requested to merge veloren/dev/veloren:imbris/pixel-perfection-v2 into master
  • By opening this merge request, you agree to release your code and all other changes under the GPL 3 license and to abide by the terms set by this license.
  • Migrations have been added if applicable
  • Significant changes of this merge request have been added to the changelog.

Closes #257 (closed)

Rather than re-scaling a UI image on the CPU we now perform this scaling when sampling in the shaders. To keep the same algorithm which is favorable for pixel art we use bilinear filtering with the sample point adjusted to account for the coverage of the current fragment by the sampled texels. Upscaling only needs to perform 1 adjusted bilinearly filtered sample. When downscaling we will perform up to 4 bilinear samples in order to perfectly compute the result for up to 1/3 downscaling (under which the results will be less accurate than before).

This change is really useful for preventing stutters when initially displaying large images like the map screen, or when regularly updating medium size images like the voxel minimap.

Since we now sample with bilinear filtering and images can be partially transparent, the colors need to have alpha values premultiplied in for bilinear filtering to produce the correct results. For this I implemented both a GPU based path and a CPU based path for alpha premultiplication. The CPU path is used on smaller images where the per image costs of extra interaction with the GPU API outweigh the cost of running the premultiplication on the CPU. The balance here has room to shift by making improvements to the GPU path to reduce the CPU side overhead.

Edited by Imbris

Merge request reports