Files
2026-08-06 18:56:32 +03:00

172 lines
11 KiB
C#

using UnityEditor;
using UnityEngine;
public class ftSettingsProvider
{
static BakeryProjectSettings pstorage;
static int toolsMenuSet = -1;
static bool showAdvanced = false;
static void GUIHandler(string searchContext)
{
if (pstorage == null) pstorage = ftLightmaps.GetProjectSettings();
if (pstorage == null) return;
var so = new SerializedObject(pstorage);
var prev = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 280;
var fhdr = so.FindProperty("formatHDR");
var f8bit = so.FindProperty("format8bit");
EditorGUILayout.PropertyField(so.FindProperty("mipmapLightmaps"), new GUIContent("Mipmap Lightmaps", "Enable mipmapping on lightmap assets. Can cause leaks across UV charts as atlases get smaller."));
EditorGUILayout.PropertyField(fhdr, new GUIContent("Color file format", ""));
EditorGUILayout.PropertyField(f8bit, new GUIContent("Mask/Direction file format", ""));
EditorGUILayout.PropertyField(so.FindProperty("lightmapCompression"), new GUIContent("Compress lightmaps", "Apply texture compression to lightmaps?"));
EditorGUILayout.PropertyField(so.FindProperty("dirHighQuality"), new GUIContent("High quality direction", "Use high quality compression for directional and SH L1 maps? (on desktop, high = BC7, not high = DXT1)"));
if (fhdr.intValue == 1 || f8bit.intValue == 2)
{
EditorGUILayout.PropertyField(so.FindProperty("maxAssetMip"), new GUIContent("Maximum mipmap count", "Limit mipmap count for Asset files."));
}
showAdvanced = EditorGUILayout.Foldout(showAdvanced, "Advanced format options", true);
if (showAdvanced)
{
EditorGUILayout.PropertyField(so.FindProperty("forceSpecificColorFormat"), new GUIContent(" Force color format"), GUILayout.ExpandWidth(true));
EditorGUILayout.PropertyField(so.FindProperty("forceSpecificDirFormat"), new GUIContent(" Force direction format"), GUILayout.ExpandWidth(true));
EditorGUILayout.PropertyField(so.FindProperty("forceSpecificMaskFormat"), new GUIContent(" Force mask format"), GUILayout.ExpandWidth(true));
}
EditorGUILayout.PropertyField(so.FindProperty("texelPaddingForDefaultAtlasPacker"), new GUIContent("Texel padding (Default atlas packer)", "How many empty texels to add between objects' UV layouts in lightmap atlases."), GUILayout.ExpandWidth(true));
EditorGUILayout.PropertyField(so.FindProperty("texelPaddingForXatlasAtlasPacker"), new GUIContent("Texel padding (xatlas packer)", "How many empty texels to add between objects' UV layouts in lightmap atlases."));
EditorGUILayout.PropertyField(so.FindProperty("alphaMetaPassResolutionMultiplier"), new GUIContent("Alpha Meta Pass resolution multiplier", "Scales resolution for alpha Meta Pass maps."));
//EditorGUILayout.PropertyField(so.FindProperty("volumeRenderMode"), new GUIContent("Volume render mode", "Render mode for volumes."));
var volMode = (BakeryLightmapGroup.RenderMode)so.FindProperty("volumeRenderMode").intValue;
var newVolMode = (BakeryLightmapGroup.RenderMode)EditorGUILayout.EnumPopup(new GUIContent("Volume render mode", "Render mode for volumes."), volMode);
if (volMode != newVolMode) so.FindProperty("volumeRenderMode").intValue = (int)newVolMode;
EditorGUILayout.PropertyField(so.FindProperty("deletePreviousLightmapsBeforeBake"), new GUIContent("Delete previous lightmaps before bake", "Should previously rendered Bakery lightmaps be deleted before the new bake?"));
EditorGUILayout.PropertyField(so.FindProperty("logLevel"), new GUIContent("Log level", "Print information about the bake process to console? 0 = don't. 1 = info only; 2 = warnings only; 3 = everything."));
EditorGUILayout.PropertyField(so.FindProperty("alternativeScaleInLightmap"), new GUIContent("Alternative Scale in Lightmap", "Make 'Scale in Lightmap' renderer property act more similar to built-in Unity behaviour."));
if (so.FindProperty("alternativeScaleInLightmap").boolValue)
{
EditorGUILayout.PropertyField(so.FindProperty("texelRoundingBehaviour"), new GUIContent("Texel rounding", "How texels are rounded during atlas packing."));
EditorGUILayout.PropertyField(so.FindProperty("alternativeGroupPacking"), new GUIContent("Alternative LMGroup packing"));
}
EditorGUILayout.PropertyField(so.FindProperty("alignToTextureBlocksWithXatlas"), new GUIContent("Align to texture compression blocks with xatlas", "Make xatlas align charts to 4x4 block boundaries to make texture compression happy."));
EditorGUILayout.PropertyField(so.FindProperty("generateSmoothPos"), new GUIContent("Generate smooth positions", "Should we adjust sample positions to prevent incorrect shadowing on very low-poly meshes with smooth normals?"));
bool smoothPos = so.FindProperty("generateSmoothPos").boolValue;
if (!smoothPos) GUI.enabled = false;
EditorGUILayout.PropertyField(so.FindProperty("perTriangleSmoothPos"), new GUIContent("Smooth positions per-triangle", "Should smooth/flat position be decided per-triangle?"));
if (!smoothPos) GUI.enabled = true;
EditorGUILayout.PropertyField(so.FindProperty("takeReceiveGIIntoAccount"), new GUIContent("Use 'Receive GI' values", "Take 'Receive Global Illumination' values into account on renderers. Originally Bakery ignored it."));
EditorGUILayout.PropertyField(so.FindProperty("removeRinging"), new GUIContent("Remove ringing in Legacy light probes (GI)", "Use softer light probe convolution in Legacy mode to prevent artifacts in high-contrast areas."));
EditorGUILayout.PropertyField(so.FindProperty("removeDirectRinging"), new GUIContent("Remove ringing in Legacy light probes (Lights)", "Properly convolve directional/point lights with the cosine lobe to avoid ringing."));
//EditorGUILayout.PropertyField(so.FindProperty("deringL2MaxLaplacian"), new GUIContent("Ringing removal for L2 light probes / APV", ""));
var sp = so.FindProperty("deringL2MaxLaplacian");
int sliderVal = sp.intValue == 0 ? 0 : (9 - sp.intValue);
int newSliderVal = EditorGUILayout.IntSlider(new GUIContent("Ringing removal for L2 light probes / APV", ""), sliderVal, 0, 8);
if (sliderVal != newSliderVal)
{
sp.intValue = newSliderVal == 0 ? 0 : (9 - newSliderVal);
}
EditorGUILayout.PropertyField(so.FindProperty("autoRenderRefProbes"), new GUIContent("Always render reflection probes", "Automatically render reflection probes after every Render/Render Light Probes."));
EditorGUILayout.PropertyField(so.FindProperty("legacyFixPos3D"), new GUIContent("Legacy volume leak fixing", "Use pre-1.97 sample adjustment algorithm for 3D texture volumes."));
EditorGUILayout.PropertyField(so.FindProperty("optimizedLODs"), new GUIContent("Optimized LOD tracing", "Moves all the LOD-switching code to the GPU, instead of using the old compositing technique."));
EditorGUILayout.PropertyField(so.FindProperty("streamingMipmaps"), new GUIContent("Streaming mip-maps", "Enable 'Streaming mipmaps' option on lightmaps. Not the best way to stream lightmap data, due to leaking visible in mips."));
EditorGUILayout.PropertyField(so.FindProperty("streamingPriority"), new GUIContent("Streaming priority", "Sets the 'Streaming priority' value for lightmaps."));
if (toolsMenuSet < 0)
{
#if UNITY_2023_2_OR_NEWER
var buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
var namedBuildTarget = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);
var defines = PlayerSettings.GetScriptingDefineSymbols(namedBuildTarget);
#else
var platform = EditorUserBuildSettings.selectedBuildTargetGroup;
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(platform);
#endif
toolsMenuSet = defines.Contains("BAKERY_TOOLSMENU") ? 1 : 0;
}
bool toolsMenuSet1 = toolsMenuSet == 1;
bool toolsMenuSet2 = EditorGUILayout.Toggle("Put menu under Tools", toolsMenuSet1);
if (toolsMenuSet1 != toolsMenuSet2)
{
#if UNITY_2023_2_OR_NEWER
var buildTargetGroup = EditorUserBuildSettings.selectedBuildTargetGroup;
var namedBuildTarget = UnityEditor.Build.NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);
var defines = PlayerSettings.GetScriptingDefineSymbols(namedBuildTarget);
#else
var platform = EditorUserBuildSettings.selectedBuildTargetGroup;
var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(platform);
#endif
if (toolsMenuSet2)
{
if (defines.Length > 0) defines += ";";
defines += "BAKERY_TOOLSMENU";
}
else
{
defines = defines.Replace("BAKERY_TOOLSMENU;", "").Replace("BAKERY_TOOLSMENU", "");
}
#if UNITY_2023_2_OR_NEWER
PlayerSettings.SetScriptingDefineSymbols(namedBuildTarget, defines);
#else
PlayerSettings.SetScriptingDefineSymbolsForGroup(platform, defines);
#endif
toolsMenuSet = -1;
}
EditorGUIUtility.labelWidth = prev;
EditorGUILayout.Space();
EditorGUILayout.Space();
if (GUILayout.Button("Revert to defaults"))
{
if (EditorUtility.DisplayDialog("Bakery", "Revert Bskery project settings to default?", "Yes", "No"))
{
so.FindProperty("mipmapLightmaps").boolValue = false;
so.FindProperty("format8bit").intValue = 0;
so.FindProperty("texelPaddingForDefaultAtlasPacker").intValue = 3;
so.FindProperty("texelPaddingForXatlasAtlasPacker").intValue = 1;
so.FindProperty("alphaMetaPassResolutionMultiplier").intValue = 2;
so.FindProperty("volumeRenderMode").intValue = 1000;
so.FindProperty("deletePreviousLightmapsBeforeBake").boolValue = false;
so.FindProperty("logLevel").intValue = 3;
so.FindProperty("alternativeScaleInLightmap").boolValue = false;
so.FindProperty("alignToTextureBlocksWithXatlas").boolValue = true;
so.FindProperty("texelRoundingBehaviour").intValue = 0;
so.FindProperty("alternativeGroupPacking").boolValue = false;
so.FindProperty("generateSmoothPos").boolValue = true;
so.FindProperty("perTriangleSmoothPos").boolValue = true;
so.FindProperty("takeReceiveGIIntoAccount").boolValue = true;
so.FindProperty("removeRinging").boolValue = false;
so.FindProperty("autoRenderRefProbes").boolValue = false;
so.FindProperty("legacyFixPos3D").boolValue = false;
so.FindProperty("optimizedLODs").boolValue = true;
}
}
so.ApplyModifiedPropertiesWithoutUndo();
}
#if UNITY_2018_3_OR_NEWER
[SettingsProvider]
public static SettingsProvider CreateSettingsProvider()
{
var provider = new SettingsProvider("Project/BakeryGlobalSettings", SettingsScope.Project);
provider.label = "Bakery GPU Lightmapper";
provider.guiHandler = GUIHandler;
return provider;
}
#endif
}