A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Discussion in 'General Graphics' started by jianyingmengcan, May 24, 2019.
in unity 2017.4,i cannot find this api,have any idea to get it?thanks
Do you mean the mip level uploaded to the GPU by the texture mip streaming system?
This is a new API related to texture mip map streaming and was only added in 2018.2
Prior to this all the mipmap levels would be loaded to the GPU.
The number of mip levels in the original texture can be retrieved with:
If you want to get the mip level that the GPU has selected based on the position on screen, you would have to do that per pixel in the shader. This post might be helpful.
If you want to query the number of mip levels a GPU texture has in the shader, see GetMipCount in the code here:
hi,my unity version is 2017.4,cannot use this api.i read those url,try use maintex_texelsize and ddx.but it is unuseful.i want to get the texture current mimap level,thanks
You're going to have to describe where and how you intend to use the mip level. The options @lyndon_unity listed are kind of the only options available.
If you want the largest available mipmap level of a texture in C# for Unity 2017, if the texture is loaded then it's always effectively 0, or perhaps more specifically the mip level set in the quality settings, since 2017 doesn't support mip streaming.
If you want the current per pixel mipmap level in a shader you have to use the techniques mentioned in the thread linked above.
If what you want is to get the mipmap level for an object on screen in c#, that's not easily possible. It's not information the CPU knows, nor is it a constant value across the entire mesh as it's determined on the GPU on each pixel the object renders independent* of the rest of the mesh. You'd have to write out the mip levels to a render texture, then iterate over all the pixels with a compute shader or copy the contents back to the CPU to iterate over in script.
* Actually it's determined for each 2x2 quad of pixels.