Is there a way to cap the max mipmap level of a generated texture?


Does anyone know how to solve this problem?

alt text

I think it’s related to this post:…-Mipmap-Levels

Is there a way to cap the max mipmap level of a generated texture atlas (using Texture2D.PackTextures())?

(from the picture above, mip level 5 would be the solution for this issue)

If not, is there a shader workaround?


You can calculate the mipmap levels yourself and use Texture2D.SetPixels32 to set each mipmap level manually. Keep in mind, like shown in the example, to pass “false” to the Apply method or Unity will calulate the mipmap levels manually.

I haven’t use it yet, but i’m quite sure it should work if you only set level 0 to 5.

I did some tests myself. Well it seems that you can either use mipmaps or not. If you use them they always to down to the lowest possible resolution. I’m not sure it this is a hardware thing (as the hardware does the mipmapping in the end) or a limitation of Unity. Anyways there seems to be no way to restrict mipmapping to a certain level. One solution could be a hybrid of using a custom shader + manipulated mipmap levels. You could set all higer mip levels to a certain key color (what isn’t used by any texture) and detect that color in the fragment shader. In that case we know that our image is displayed only as a single pixel. Additionally you would set the vertex color of each tile to the wanted color. The vertex color is usually ignored but when the shader detects a miplevel above the limit it ignores the texture and uses the vertex color.

Of course this makes the management of your meshes more complicated and the shader is a bit more complicated but i think it should be doable.