diff options
| author | yum <yum.food.vr@gmail.com> | 2024-10-11 18:39:50 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-10-11 18:39:50 -0700 |
| commit | 0e39a7ef25e7938b84736519057c06c8d84856cc (patch) | |
| tree | 7af1f8822572aa13747e913fbd8b5ca7d5a82819 /Editor | |
| parent | e193c86c869b84dfaaa26465c0e6fb923a27631c (diff) | |
Fog performance optimizations
* Rename albedo cutoff to alpha cutoff
* Add LODs for calculating fog density
* Use 3D noise texture to speed up density calculation
* Eliminate low impact octaves from density calculation
* Add support for multiple emitters
Diffstat (limited to 'Editor')
| -rw-r--r-- | Editor/generate_3d_noise.cs | 67 | ||||
| -rw-r--r-- | Editor/tooner.cs | 46 |
2 files changed, 107 insertions, 6 deletions
diff --git a/Editor/generate_3d_noise.cs b/Editor/generate_3d_noise.cs new file mode 100644 index 0000000..4352d99 --- /dev/null +++ b/Editor/generate_3d_noise.cs @@ -0,0 +1,67 @@ +// !! AI ARTIFACT !! +// This code was originally generated by Claude 3.5 Sonnet. +using UnityEngine; +using UnityEditor; + +public class WhiteNoiseTextureGenerator : EditorWindow +{ + private int textureWidth = 32; + private int textureHeight = 32; + private int textureDepth = 32; + private string textureName = "WhiteNoiseTexture"; + + [MenuItem("Tools/yum_food/White Noise Texture Generator")] + public static void ShowWindow() + { + GetWindow<WhiteNoiseTextureGenerator>("White Noise Texture Generator"); + } + + private void OnGUI() + { + GUILayout.Label("White Noise Texture Generator", EditorStyles.boldLabel); + + textureWidth = EditorGUILayout.IntField("Texture Width", textureWidth); + textureHeight = EditorGUILayout.IntField("Texture Height", textureHeight); + textureDepth = EditorGUILayout.IntField("Texture Depth", textureDepth); + textureName = EditorGUILayout.TextField("Texture Name", textureName); + + if (GUILayout.Button("Generate Texture")) + { + if (textureWidth <= 0 || textureHeight <= 0 || textureDepth <= 0) + { + EditorUtility.DisplayDialog("Error", "Texture dimensions must be greater than zero.", "OK"); + return; + } + + GenerateWhiteNoiseTexture(); + } + } + + private void GenerateWhiteNoiseTexture() + { + Texture3D texture = new Texture3D(textureWidth, textureHeight, textureDepth, TextureFormat.RGBA32, false); + Color[] colors = new Color[textureWidth * textureHeight * textureDepth]; + + for (int z = 0; z < textureDepth; z++) + { + for (int y = 0; y < textureHeight; y++) + { + 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); + } + } + } + + texture.SetPixels(colors); + texture.Apply(); + + string path = $"Assets/{textureName}.asset"; + AssetDatabase.CreateAsset(texture, path); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + + EditorUtility.DisplayDialog("Success", $"White noise texture generated and saved at {path}", "OK"); + } +} diff --git a/Editor/tooner.cs b/Editor/tooner.cs index fdcb678..3c0b951 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -2033,10 +2033,16 @@ public class ToonerGUI : ShaderGUI { FloatProperty(bc, "Noise exponent"); bc = FindProperty("_Gimmick_Fog_00_Normal_Cutoff"); RangeProperty(bc, "Normal cutoff"); - bc = FindProperty("_Gimmick_Fog_00_Albedo_Cutoff"); - RangeProperty(bc, "Albedo cutoff"); + bc = FindProperty("_Gimmick_Fog_00_Alpha_Cutoff"); + RangeProperty(bc, "Alpha cutoff"); bc = FindProperty("_Gimmick_Fog_00_Ray_Origin_Randomization"); RangeProperty(bc, "Ray origin randomization"); + bc = FindProperty("_Gimmick_Fog_00_Lod_Half_Life"); + FloatProperty(bc, "LOD half life"); + bc = FindProperty("_Gimmick_Fog_00_Noise"); + TexturePropertySingleLine( + MakeLabel(bc, "Noise"), + bc); bc = FindProperty("_Gimmick_Fog_00_Emitter_Texture"); TexturePropertySingleLine( @@ -2046,16 +2052,44 @@ public class ToonerGUI : ShaderGUI { if (bc.textureValue) { EditorGUI.indentLevel += 1; - bc = FindProperty("_Gimmick_Fog_00_Emitter_Location"); + bc = FindProperty("_Gimmick_Fog_00_Emitter0_Location"); VectorProperty(bc, "Location (world)"); - bc = FindProperty("_Gimmick_Fog_00_Emitter_Normal"); + bc = FindProperty("_Gimmick_Fog_00_Emitter0_Normal"); VectorProperty(bc, "Normal (world)"); - bc = FindProperty("_Gimmick_Fog_00_Emitter_Scale_X"); + bc = FindProperty("_Gimmick_Fog_00_Emitter0_Scale_X"); FloatProperty(bc, "Scale (x)"); - bc = FindProperty("_Gimmick_Fog_00_Emitter_Scale_Y"); + bc = FindProperty("_Gimmick_Fog_00_Emitter0_Scale_Y"); FloatProperty(bc, "Scale (y)"); + bc = FindProperty("_Gimmick_Fog_00_Emitter_Brightness"); FloatProperty(bc, "Brightness"); + bc = FindProperty("_Gimmick_Fog_00_Emitter_Lod_Half_Life"); + FloatProperty(bc, "LOD half life"); + + for (int i = 0; i < 2; i++) { + bc = FindProperty($"_Gimmick_Fog_00_Emitter{i+1}_Enable_Static"); + enabled = (bc.floatValue != 0.0); + EditorGUI.BeginChangeCheck(); + enabled = Toggle($"Enable emitter {i+1}", enabled); + EditorGUI.EndChangeCheck(); + bc.floatValue = enabled ? 1.0f : 0.0f; + SetKeyword($"_GIMMICK_FOG_00_EMITTER_{i+1}", enabled); + + if (enabled) { + EditorGUI.indentLevel += 1; + + bc = FindProperty($"_Gimmick_Fog_00_Emitter{i+1}_Location"); + VectorProperty(bc, "Location (world)"); + bc = FindProperty($"_Gimmick_Fog_00_Emitter{i+1}_Normal"); + VectorProperty(bc, "Normal (world)"); + bc = FindProperty($"_Gimmick_Fog_00_Emitter{i+1}_Scale_X"); + FloatProperty(bc, "Scale (x)"); + bc = FindProperty($"_Gimmick_Fog_00_Emitter{i+1}_Scale_Y"); + FloatProperty(bc, "Scale (y)"); + + EditorGUI.indentLevel -= 1; + } + } EditorGUI.indentLevel -= 1; } |
