材质不上传到 GPU 的高分辨率图像金字塔级别数量。(只读)
Unity 会根据材质的图像金字塔级别限制设置来确定主动图像金字塔级别限制,这会影响上传到 GPU 的材质图像金字塔级别数量。此属性提供了 Unity 不上传到 GPU 的材质图像金字塔级别的主动数量。此数字相对于构建中包含的材质图像金字塔级别数量。
无论材质的图像金字塔级别限制如何,Unity 确保始终会上传特定于平台的几个图像金字塔级别。因此,在某些情况下,activeMipmapLimit
可能比预期的要小。
以下代码示例演示了如何使用 activeMipmapLimit
在 GPU 上执行 Graphics.CopyTexture 操作,以将使用图像金字塔级别的材质的分辨率最高图像金字塔级别复制到不使用图像金字塔级别的的新材质中。
using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Experimental.Rendering;
public class Example : MonoBehaviour { [SerializeField] Texture2DArray m_SourceTexture;
public void ExecuteCopyTexture() { if ((SystemInfo.copyTextureSupport & CopyTextureSupport.Basic) == 0) { Debug.LogError("Cannot perform CopyTexture, there is no support on this platform."); return; }
if (!SystemInfo.IsFormatSupported(m_SourceTexture.graphicsFormat, GraphicsFormatUsage.Sample)) { Debug.LogError("Cannot perform CopyTexture, the source texture's GraphicsFormat is not supported on this platform."); return; }
// The width and height of the texture in the build need to be halved for each mipmap level that wasn't uploaded to the GPU int width = m_SourceTexture.width >> m_SourceTexture.activeMipmapLimit; int height = m_SourceTexture.height >> m_SourceTexture.activeMipmapLimit;
// No mipmap limit applies because the texture doesn't have mipmaps. Texture2D destinationTexture = new Texture2D(width, height, m_SourceTexture.format, false);
// GPU copy of the mipmap level 0 of element 0 to the mipmap level 0 of the destination texture. // The mipmap level 0 on the GPU is smaller than the mipmap level 0 of the texture in the build when m_SourceTexture.activeMipmapLimit is greater than 0. Graphics.CopyTexture(m_SourceTexture, 0, 0, 0, 0, m_SourceTexture.width, m_SourceTexture.height, destinationTexture, 0, 0, 0, 0); } }