From e98969f89a2ea3a312b0441231bac4187d9f2fae Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 21 Oct 2026 19:02:51 -0700 Subject: [PATCH] insert: Traced Mode foldout in the URP insert inspector The generic property list leaves the Traced controls out; a Traced Mode foldout draws them from the engine's InsertTracedFields, in the same sections as HDRP, shown only while the mode is on. Co-Authored-By: Claude Opus 5.5 --- Editor/InsertShaderGUI.cs | 59 ++++++++++++++++++++++++++++++---- Runtime/UrpMaterialResolver.cs | 9 ++++++ 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/Editor/InsertShaderGUI.cs b/Editor/InsertShaderGUI.cs index 6542ec3..00cd15e 100644 --- a/Editor/InsertShaderGUI.cs +++ b/Editor/InsertShaderGUI.cs @@ -23,21 +23,68 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro using (new EditorGUI.DisabledScope(locked)) { foreach (var property in properties) { if ((property.propertyFlags & (ShaderPropertyFlags.HideInInspector | ShaderPropertyFlags.PerRendererData)) != 0) { continue; } - // Presets own these controls in both pipelines. Edit the linked - // preset through the Insert inspector, or unlink it there first. - var owned = materialEditor.targets.OfType().Any(material => - InsertMaterialPresets.LinkedPreset(material)?.Find(property.name) != null - || InsertColorPresets.LinkedPreset(material) != null && IsColorProperty(property.name)); - using (new EditorGUI.DisabledScope(owned)) { + if (InsertTracedFields.Owns(property.name)) { continue; } + using (new EditorGUI.DisabledScope(Owned(materialEditor, property.name))) { materialEditor.ShaderProperty(property, property.displayName); } } + DrawTraced(materialEditor, properties); materialEditor.RenderQueueField(); materialEditor.EnableInstancingField(); materialEditor.DoubleSidedGIField(); } } + /// + /// The opt-in Traced mode in a section of its own, its controls shown + /// only while it's on, as in HDRP's inspector. + /// + private static void DrawTraced(MaterialEditor materialEditor, MaterialProperty[] properties) + { + var keyword = FindProperty(InsertTracedFields.Keyword, properties, false); + if (keyword == null) { + return; + } + // A plain foldout in the header's style: a foldout header group throws when the + // material is drawn inside another one. + var open = EditorGUILayout.Foldout(SessionState.GetBool(TracedFoldoutKey, true), InsertTracedFields.Title, true, EditorStyles.foldoutHeader); + SessionState.SetBool(TracedFoldoutKey, open); + if (open) { + materialEditor.ShaderProperty(keyword, InsertTracedFields.KeywordLabel); + if (materialEditor.targets.OfType().All(material => material.IsKeywordEnabled(InsertTracedFields.Keyword))) { + EditorGUILayout.HelpBox(InsertTracedFields.Note, MessageType.None); + foreach (var section in InsertTracedFields.Sections) { + EditorGUILayout.Space(4f); + EditorGUILayout.LabelField(section.Title, EditorStyles.boldLabel); + foreach (var entry in section.Entries) { + var property = FindProperty(entry.Name, properties, false); + if (property == null) { + continue; + } + using (new EditorGUI.DisabledScope(Owned(materialEditor, entry.Name))) { + if (entry.IsTexture) { + materialEditor.TexturePropertySingleLine(entry.Label, property); + } else { + materialEditor.ShaderProperty(property, entry.Label); + } + } + } + } + } + } + EditorGUILayout.Space(6f); + } + + private const string TracedFoldoutKey = "VisualPinball.Urp.InsertShaderGUI.Traced"; + + /// + /// Presets own these controls in both pipelines. Edit the linked + /// preset through the Insert inspector, or unlink it there first. + /// + private static bool Owned(MaterialEditor materialEditor, string name) => materialEditor.targets.OfType().Any(material => + InsertMaterialPresets.LinkedPreset(material)?.Find(name) != null + || InsertColorPresets.LinkedPreset(material) != null && IsColorProperty(name)); + private static bool IsColorProperty(string name) => name is "_BaseColor" or "_InsertCavityColor" or "_EmissiveColor" or "_InsertLuminosity" or "_HazeColor" or "_CoverTint"; } } diff --git a/Runtime/UrpMaterialResolver.cs b/Runtime/UrpMaterialResolver.cs index 71af50d..c183dd3 100644 --- a/Runtime/UrpMaterialResolver.cs +++ b/Runtime/UrpMaterialResolver.cs @@ -208,6 +208,15 @@ private static Material BuildInsertShader(string name, VpeInsertShaderProfile pr if (material.HasProperty("_InsertUrpEmissionScale")) { material.SetFloat("_InsertUrpEmissionScale", UrpPhysicalUnits.EmissiveScale); } + // The insert's opt-in Traced mode travels as its toggle's value; nothing + // at runtime turns that back into the keyword. + if (material.HasProperty("_INSERT_TRACED")) { + if (material.GetFloat("_INSERT_TRACED") > 0.5f) { + material.EnableKeyword("_INSERT_TRACED"); + } else { + material.DisableKeyword("_INSERT_TRACED"); + } + } return material; }