- Home /
Is there a way to cap the max mipmap level of a generated texture?
Hi,
Does anyone know how to solve this problem?
I think it's related to this post: http://forum.unity3d.com/threads/889...-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?
TIA, R.
This is quite old. But I've just now run into this problem and all I can find all over the internet is questions, and not answers. Is there a way to solve this with the newer versions of Unity? Or is it still practically impossible?
Answer by Bunny83 · Nov 08, 2014 at 11:43 PM
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.
edit
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.
I'm not sure how well that will work with anisotropic filtering since you can't set each anisotropic mipmap manually. It's possible that you can't use it at all. Well, just try it ;) $$anonymous$$aybe Unity creates the anisotropic mipmaps automatically out of mip0
$$anonymous$$ips 6 to 10 require so few pixels that it's not possible to have each block separated in the texture - there would be blocks merged together. I wish I could just take mip 5 and write it to mips 6 to 10 so it all looks the same, but you need less pixels.
So what I really wish is that I could just say don't generate mips beyond mip 5.
Hmm, it seems that At least OpenGL allows to set the max mipmap level with GL_TEXTURE_$$anonymous$$AX_LEVEL and GL_TEXTURE_$$anonymous$$AX_LOD. I guess that DirectX should have something similar. However i think Unity doesn't make use of those :|