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