Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

Fix mip map size calculation for non-square textures #273

Merged
merged 1 commit into from
Jan 5, 2024

Conversation

HybridDog
Copy link
Contributor

Problem description

The size of a mip map is max{floor(width / 2 ^ level), 1} x max{floor(height / 2 ^ level), 1}, where width x height is the size of the full-resolution image, level is the integer mip map level and the smallest mip map has 1 x 1 resolution. If regenerateMipMapLevels is called with custom mip map data, the mip map sizes are calculated in this function and separately in uploadTexture. uploadTexture calculates a size by floor(width / 2 ^ level) x floor(height / 2 ^ level).

Proposed changes

To support non-square textures, after this change, uploadTexture sets the mip map width or height to 1 if it is 0.

How to test

  • Compile Minetest with the changes in my mipmap_custom_simple_fill branch
  • Use a texture pack to override the default_desert_sand.png texture with this 2x16 pixel texture: default_desert_sand
  • In the Minetest settings, set the mip_map setting to sharp
  • Play Minetest and look at different nodes, especially at default's Desert Sand

Before the changes: Desert Sand nodes are black and in the inventory it's white.
before

After the changes: Desert Sand looks like the other nodes, i.e. the full resolution and inventory image show the texture and only the mip maps are cyan, which is supposed to happen with the code in my mipmap_custom_simple_fill branch.
after

The size of a mip map is `max{floor(width / 2 ^ level), 1} x max{floor(height / 2 ^ level), 1}`,
where `width x height` is the size of the full-resolution image,
`level` is the integer mip map level
and the smallest mip map has `1 x 1` resolution.
If `regenerateMipMapLevels` is called with custom mip map data,
the mip map sizes are calculated in this function and separately in `uploadTexture`.
`uploadTexture` calculates a size by `floor(width / 2 ^ level) x floor(height / 2 ^ level)`.

To support non-square textures, after this change,
`uploadTexture` sets the mip map width or height to `1` if it is `0`.
@sfan5 sfan5 merged commit fb4ee6a into minetest:master Jan 5, 2024
14 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants