diff options
| author | yum <yum.food.vr@gmail.com> | 2024-11-04 01:03:17 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-11-04 01:04:59 -0800 |
| commit | b80cbe56d30e0f5a12d77dae029b883338187711 (patch) | |
| tree | 89d8f71a300a828521911e97d5eae16cef4201cd /Editor | |
| parent | 5f4b58803d1f1d0c61a031e8563df4024682b328 (diff) | |
3d white noise generator now supports different dimensionality
Diffstat (limited to 'Editor')
| -rw-r--r-- | Editor/generate_3d_noise.cs | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/Editor/generate_3d_noise.cs b/Editor/generate_3d_noise.cs index 13cdf70..adf6242 100644 --- a/Editor/generate_3d_noise.cs +++ b/Editor/generate_3d_noise.cs @@ -3,12 +3,22 @@ using UnityEngine; using UnityEditor; +public enum NoiseType +{ + OneDimensional, + TwoDimensional, + ThreeDimensional, + FourDimensional, + NormalizedThreeDimensional +} + public class WhiteNoiseTextureGenerator : EditorWindow { private int textureWidth = 32; private int textureHeight = 32; private int textureDepth = 32; private string textureName = "WhiteNoiseTexture"; + private NoiseType noiseType = NoiseType.ThreeDimensional; [MenuItem("Tools/yum_food/White Noise Texture Generator")] public static void ShowWindow() @@ -24,6 +34,7 @@ public class WhiteNoiseTextureGenerator : EditorWindow textureHeight = EditorGUILayout.IntField("Texture Height", textureHeight); textureDepth = EditorGUILayout.IntField("Texture Depth", textureDepth); textureName = EditorGUILayout.TextField("Texture Name", textureName); + noiseType = (NoiseType)EditorGUILayout.EnumPopup("Noise Type", noiseType); if (GUILayout.Button("Generate Texture")) { @@ -39,7 +50,8 @@ public class WhiteNoiseTextureGenerator : EditorWindow private void GenerateWhiteNoiseTexture() { - Texture3D texture = new Texture3D(textureWidth, textureHeight, textureDepth, TextureFormat.R8, false); + TextureFormat format = GetTextureFormat(); + Texture3D texture = new Texture3D(textureWidth, textureHeight, textureDepth, format, false); Color[] colors = new Color[textureWidth * textureHeight * textureDepth]; for (int z = 0; z < textureDepth; z++) @@ -49,7 +61,7 @@ public class WhiteNoiseTextureGenerator : EditorWindow for (int x = 0; x < textureWidth; x++) { int index = x + y * textureWidth + z * textureWidth * textureHeight; - colors[index] = new Color(Random.value, Random.value, Random.value, 1f); + colors[index] = GenerateColor(); } } } @@ -64,4 +76,42 @@ public class WhiteNoiseTextureGenerator : EditorWindow EditorUtility.DisplayDialog("Success", $"White noise texture generated and saved at {path}", "OK"); } + + private TextureFormat GetTextureFormat() + { + switch (noiseType) + { + case NoiseType.OneDimensional: + return TextureFormat.R8; + case NoiseType.TwoDimensional: + return TextureFormat.RG16; + case NoiseType.ThreeDimensional: + case NoiseType.NormalizedThreeDimensional: + return TextureFormat.RGB24; + case NoiseType.FourDimensional: + return TextureFormat.RGBA32; + default: + return TextureFormat.RGB24; + } + } + + private Color GenerateColor() + { + switch (noiseType) + { + case NoiseType.OneDimensional: + return new Color(Random.value, 0, 0, 1); + case NoiseType.TwoDimensional: + return new Color(Random.value, Random.value, 0, 1); + case NoiseType.ThreeDimensional: + return new Color(Random.value, Random.value, Random.value, 1); + case NoiseType.FourDimensional: + return new Color(Random.value, Random.value, Random.value, Random.value); + case NoiseType.NormalizedThreeDimensional: + Vector3 normalizedColor = Random.insideUnitSphere.normalized; + return new Color(normalizedColor.x * 0.5f + 0.5f, normalizedColor.y * 0.5f + 0.5f, normalizedColor.z * 0.5f + 0.5f, 1); + default: + return Color.white; + } + } } |
