Created
May 7, 2025 23:52
-
-
Save pema99/c706b38eb94b13a1680c8635c180b228 to your computer and use it in GitHub Desktop.
Creates a texture where each mip level is a different color.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MakeWeirdMips : MonoBehaviour | |
{ | |
[MenuItem("Pema/MakeWeirdMips")] | |
public static void MakeWeirdMipsAsset() | |
{ | |
Texture2D tex = new Texture2D(1024, 1024, GraphicsFormat.R32G32B32A32_SFloat, TextureCreationFlags.MipChain); | |
FillMip(tex, Color.magenta, 0); // 1024 | |
FillMip(tex, Color.green, 1); // 512 | |
FillMip(tex, Color.blue, 2); // 256 | |
FillMip(tex, Color.red, 3); // 128 | |
FillMip(tex, Color.green, 4); // 64 | |
FillMip(tex, Color.blue, 5); // 32 | |
FillMip(tex, Color.red, 6); // 16 | |
FillMip(tex, Color.green, 7); // 8 | |
FillMip(tex, Color.blue, 8); // 4 | |
FillMip(tex, Color.red, 9); // 2 | |
FillMip(tex, Color.magenta, 10); // 1 | |
AssetDatabase.CreateAsset(tex, "Assets/WeirdMips.asset"); | |
var material = AssetDatabase.LoadAssetAtPath<Material>("Assets/WeirdMips.mat"); | |
material.mainTexture = tex; | |
} | |
public static void FillMip(Texture2D tex, Color color, int mipLevel) | |
{ | |
var size = tex.width >> mipLevel; | |
var arr = new Color[size * size]; | |
Array.Fill(arr, color); | |
tex.SetPixels(arr, mipLevel); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment