yum-archive/Tooner

A toon shader for Unity's BIRP.

git clone https://git.yummers.dev/yum-archive/Tooner

yumUpdate READMEafc2e44

master
4.0 KiB117 linesraw
1// !! AI ARTIFACT !!
2// This code was originally generated by Claude 3.5 Sonnet.
3using UnityEngine;
4using UnityEditor;
5
6public enum NoiseType
7{
8    OneDimensional,
9    TwoDimensional,
10    ThreeDimensional,
11    FourDimensional,
12    NormalizedThreeDimensional
13}
14
15public class WhiteNoiseTextureGenerator : EditorWindow
16{
17    private int textureWidth = 32;
18    private int textureHeight = 32;
19    private int textureDepth = 32;
20    private string textureName = "WhiteNoiseTexture";
21    private NoiseType noiseType = NoiseType.ThreeDimensional;
22
23    [MenuItem("Tools/yum_food/White Noise Texture Generator")]
24    public static void ShowWindow()
25    {
26        GetWindow<WhiteNoiseTextureGenerator>("White Noise Texture Generator");
27    }
28
29    private void OnGUI()
30    {
31        GUILayout.Label("White Noise Texture Generator", EditorStyles.boldLabel);
32
33        textureWidth = EditorGUILayout.IntField("Texture Width", textureWidth);
34        textureHeight = EditorGUILayout.IntField("Texture Height", textureHeight);
35        textureDepth = EditorGUILayout.IntField("Texture Depth", textureDepth);
36        textureName = EditorGUILayout.TextField("Texture Name", textureName);
37        noiseType = (NoiseType)EditorGUILayout.EnumPopup("Noise Type", noiseType);
38
39        if (GUILayout.Button("Generate Texture"))
40        {
41            if (textureWidth <= 0 || textureHeight <= 0 || textureDepth <= 0)
42            {
43                EditorUtility.DisplayDialog("Error", "Texture dimensions must be greater than zero.", "OK");
44                return;
45            }
46
47            GenerateWhiteNoiseTexture();
48        }
49    }
50
51    private void GenerateWhiteNoiseTexture()
52    {
53        TextureFormat format = GetTextureFormat();
54        Texture3D texture = new Texture3D(textureWidth, textureHeight, textureDepth, format, false);
55        Color[] colors = new Color[textureWidth * textureHeight * textureDepth];
56
57        for (int z = 0; z < textureDepth; z++)
58        {
59            for (int y = 0; y < textureHeight; y++)
60            {
61                for (int x = 0; x < textureWidth; x++)
62                {
63                    int index = x + y * textureWidth + z * textureWidth * textureHeight;
64                    colors[index] = GenerateColor();
65                }
66            }
67        }
68
69        texture.SetPixels(colors);
70        texture.Apply();
71
72        string path = $"Assets/{textureName}.asset";
73        AssetDatabase.CreateAsset(texture, path);
74        AssetDatabase.SaveAssets();
75        AssetDatabase.Refresh();
76
77        EditorUtility.DisplayDialog("Success", $"White noise texture generated and saved at {path}", "OK");
78    }
79
80    private TextureFormat GetTextureFormat()
81    {
82        switch (noiseType)
83        {
84            case NoiseType.OneDimensional:
85                return TextureFormat.R8;
86            case NoiseType.TwoDimensional:
87                return TextureFormat.RG16;
88            case NoiseType.ThreeDimensional:
89            case NoiseType.NormalizedThreeDimensional:
90                return TextureFormat.RGB48;
91            case NoiseType.FourDimensional:
92                return TextureFormat.RGBA32;
93            default:
94                return TextureFormat.RGB24;
95        }
96    }
97
98    private Color GenerateColor()
99    {
100        switch (noiseType)
101        {
102            case NoiseType.OneDimensional:
103                return new Color(Random.value, 0, 0, 1);
104            case NoiseType.TwoDimensional:
105                return new Color(Random.value, Random.value, 0, 1);
106            case NoiseType.ThreeDimensional:
107                return new Color(Random.value, Random.value, Random.value, 1);
108            case NoiseType.FourDimensional:
109                return new Color(Random.value, Random.value, Random.value, Random.value);
110            case NoiseType.NormalizedThreeDimensional:
111                Vector3 normalizedColor = Random.insideUnitSphere.normalized;
112                return new Color(normalizedColor.x * 0.5f + 0.5f, normalizedColor.y * 0.5f + 0.5f, normalizedColor.z * 0.5f + 0.5f, 1);
113            default:
114                return Color.white;
115        }
116    }
117}