Skip to content

Instantly share code, notes, and snippets.

@reinsteam
Last active October 17, 2015 12:56
Show Gist options
  • Save reinsteam/143b165e8b3f292cf10b to your computer and use it in GitHub Desktop.
Save reinsteam/143b165e8b3f292cf10b to your computer and use it in GitHub Desktop.
Snippet for generation helper texture for mip level colorization (http://aras-p.info/blog/2011/05/03/a-way-to-visualize-mip-levels/)
static public Texture2D CreateMipColorsTexture()
{
var MipColorsTexture = new Texture2D(32, 32, TextureFormat.ARGB32, true);
MipColorsTexture.hideFlags = HideFlags.HideAndDontSave;
Color[] colorArray = new Color[6]
{
new Color(0.0f, 0.0f, 1.0f, 0.8f),
new Color(0.0f, 0.5f, 1.0f, 0.4f),
new Color(1.0f, 1.0f, 1.0f, 0.0f),
new Color(1.0f, 0.7f, 0.0f, 0.2f),
new Color(1.0f, 0.3f, 0.0f, 0.6f),
new Color(1.0f, 0.0f, 0.0f, 0.8f)
};
int maxMips = Mathf.Min(6, MipColorsTexture.mipmapCount);
for (int mip = 0; mip < maxMips; ++mip)
{
int mipWidth = Mathf.Max(MipColorsTexture.width >> mip, 1);
int mipHeight = Mathf.Max(MipColorsTexture.height >> mip, 1);
Color[] colors = new Color[mipWidth * mipHeight];
for (int index = 0; index < colors.Length; ++index)
{
colors[index] = colorArray[mip];
}
MipColorsTexture.SetPixels(colors, mip);
}
MipColorsTexture.filterMode = FilterMode.Trilinear;
MipColorsTexture.Apply(false);
return MipColorsTexture;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment