#Enhanced Texture Atlas Packing

1 messages · Page 1 of 1 (latest)

cold fulcrum
#

Current atlas seems to be fixed in size and it is a large texture. My suggestion is to use atlas packing algorithm that will make atlas dynamically from the textures specified by voxels, and probably the best algorithm for this is "divide and conquer".

Algorithm (my implementation):

  • Collect all required textures
  • Compute texture areas, sort textures from largest to smallest
  • Compute total area of all textures
  • Find atlas possible side as area square root ceiled to the closest power of 2 (200 -> 256, 300 -> 512 and so on)
  • Try to pack atlas by using "divide and conquer":
    1. Define an area equal to atlas size
    2. Place the first texture in top left corner
    3. Divide remaining area into two rectangles
    4. Select second texture
    5. Place it into smallest rectangle that it can fit, divide it into 1 or 2 rectangles depending on remaining area
    6. Repeat until all textures will be placed
  • If algorithm fails increase atlas size to the next power of 2 (512 -> 1024 and so on)

Benefits:

  • Textures can be any size - some voxels can use low-res textures and some can use hi-res
  • Atlas size will be small, but big enough to fit all required textures
  • More textures can be added into it allowing mods to have custom voxel textures
  • It can be re-build dynamically from any texture sets, so it will be possible to make texturepacks that will define only several textures
round stormBOT
#

GG @cold fulcrum, you just advanced to level 2!

cold fulcrum
#

There is a more detailed explanation of this algorithm on "rectpack2D" library github page