sp614x / optifine

1.78k stars 419 forks source link

[Bug] Mipmaps not working when there are NPOT textures (Confirmed in 1.12.2-1.20.1) #7513

Open BloCamLimb opened 12 months ago

BloCamLimb commented 12 months ago

Description of Issue

When the Mipmap level is set to 4 and the type is Trilinear, OptiFine should use linear_mipmap_linear when textures are min filtering (e.g. blocks away from the camera). However, it stops working as long as there are many NPOT (non-power-of-two) textures, the result will be like nearest_neighbor is used. But Vanilla won't have this problem, that is:

  1. Minecraft + Forge -> mipmaps working
  2. Minecraft + Forge + Mods with NPOT textures -> mipmaps working
  3. Minecraft + Forge + OptiFine -> mipmaps working
  4. Minecraft + Forge + OptiFine + Mods with NPOT textures -> mipmaps not working

For example, with MTR mod installed, the log says a lot of

[OptiFine] Scaled non power of 2: mtr:block/sign/door_overlay_a_train_tcl_right, 380 -> 384 [OptiFine] Scaled non power of 2: mtr:block/sign/door_overlay_c_train_right, 380 -> 384 [OptiFine] Scaled non power of 2: mtr:block/sign/door_overlay_k_train_right, 380 -> 384 [OptiFine] Scaled non power of 2: mtr:block/sign/door_overlay_mlr_right, 380 -> 384 [OptiFine] Scaled non power of 2: mtr:block/sign/door_overlay_q_train_left, 380 -> 384 [OptiFine] Scaled non power of 2: mtr:block/psd_door_end_top_right_2_1, 40 -> 48 [OptiFine] Scaled non power of 2: mtr:block/sign/door_overlay_light_rail_5_right, 380 -> 384 [OptiFine] Scaled non power of 2: mtr:block/sign/door_overlay_mlr_left, 380 -> 384 [OptiFine] Scaled non power of 2: mtr:block/psd_door_top_right_1, 72 -> 80 ... [net.minecraft.client.renderer.texture.SpriteLoader/]: minecraft:textures/atlas/blocks.png: dropping miplevel from 4 to 0, because of minimum power of two: 1

The more NPOT textures, the worse the mipmaps linear effect. Fianlly, mipmaps behave just like nearest_neighbor. If there are only a few NPOT textures and each sprite is small, the mipmaps still work.

Steps to Reproduce

This bug appears when there are a large number of NPOT textures and each texture sprite size is > 256px in general. You can reproduce this bug with any mod that contains NPOT textures.

OptiFine Version

OptiFine_1.20.1_HD_U_I6_pre6.

Actually the bug exists in all OptiFine versions from Minecraft 1.12.2 to Minecraft 1.20.1. I haven't tested versions earlier than 1.12 yet.

Installation Method

Forge.

Forge Version

Forge 1.20.1 - 47.1.0

Other Installed Mods

The MTR mod requires architectury. There are so many mods have NPOT textures, so MTR is not an exception.

Log Files

Minecraft + Forge + OptiFine + MTR Mod, the key part of the log https://pastebin.com/vaYUyBd2

Without OptiFine (i.e. Minecraft + Forge + MTR Mod), there's no such lines like minecraft:textures/atlas/blocks.png: dropping miplevel from 4 to 0, because of minimum power of two: 1, so mipmaps work.

Screenshot

Minecraft + Forge + OptiFine + MTR Mod, mipmaps are broken, no linear filtering for blocks aways from player: With OptiFine Without OptiFine (i.e. Minecraft + Forge + MTR Mod), mipmaps work as usual: Without OptiFine The above two images are both MIPMAP LEVEL=4 and MIPMAP TYPE=Trilinear