From 6967a48b0a3fe990730994116554480f7adf4115 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 21 Oct 2026 19:02:51 -0700 Subject: [PATCH] insert: Traced Mode section in the Insert Hybrid inspector Draws the controls of the shader's opt-in Traced mode from the engine's InsertTracedFields, shown only while the mode is on. Co-Authored-By: Claude Opus 5.5 --- Editor/HdrpMaterialTranslator.cs | 3 ++- Editor/Insert/InsertHybridGUI.cs | 36 ++++++++++++++++++++++++++++++++ Runtime/HdrpMaterialResolver.cs | 15 +++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/Editor/HdrpMaterialTranslator.cs b/Editor/HdrpMaterialTranslator.cs index a99828b7..4744e696 100644 --- a/Editor/HdrpMaterialTranslator.cs +++ b/Editor/HdrpMaterialTranslator.cs @@ -263,7 +263,8 @@ private static VpeInsertShaderProfile TranslateInsertShader(Material material, C break; case ShaderPropertyType.Texture: property.Kind = "texture"; - var optical = name is "_OpticalNormalMap" or "_OpticalResponseMap"; + // The Traced mode's maps are data too: HDR light, facet normals. + var optical = name is "_OpticalNormalMap" or "_OpticalResponseMap" || name.StartsWith("_Traced", StringComparison.Ordinal); var linear = optical || name is "_NormalMap" or "_CoverNormalMap"; property.Texture = ctx.CaptureSideChannelTextureRef(material, name, name == "_OpticalResponseMap" ? ResponseColorSpace(material.GetTexture(name)) diff --git a/Editor/Insert/InsertHybridGUI.cs b/Editor/Insert/InsertHybridGUI.cs index 9eb7385a..40a8b1de 100644 --- a/Editor/Insert/InsertHybridGUI.cs +++ b/Editor/Insert/InsertHybridGUI.cs @@ -47,6 +47,7 @@ public InsertHybridGUI() uiBlocks.Insert(index, new PlasticBlock()); uiBlocks.Insert(index + 1, new LampBlock()); uiBlocks.Insert(index + 2, new BakeBlock()); + uiBlocks.Insert(index + 3, new TracedModeBlock()); } /// @@ -710,4 +711,39 @@ private void Texture(GUIContent label, string name) } } } + + /// + /// The opt-in Traced mode: the body's glow from an offline render of the + /// insert instead of the optical response map, the bulb still refracted + /// live. Everything above stays in charge of colour and brightness. The + /// controls and their words are , shared + /// with URP. + /// + internal sealed class TracedModeBlock : InsertBlock + { + public TracedModeBlock() : base(ExpandableBit.User3, InsertTracedFields.Title) { } + + protected override void Draw() + { + Field(InsertTracedFields.Keyword, InsertTracedFields.KeywordLabel.text, InsertTracedFields.KeywordLabel.tooltip); + var on = materials.All(material => material.IsKeywordEnabled(InsertTracedFields.Keyword)); + if (!on) { + return; + } + EditorGUILayout.HelpBox(InsertTracedFields.Note, MessageType.None); + foreach (var section in InsertTracedFields.Sections) { + SubHeader(section.Title); + foreach (var entry in section.Entries) { + if (entry.IsTexture) { + var property = FindProperty(entry.Name); + if (property != null) { + materialEditor.TexturePropertySingleLine(entry.Label, property); + } + } else { + Field(entry.Name, entry.Label.text, entry.Label.tooltip); + } + } + } + } + } } diff --git a/Runtime/HdrpMaterialResolver.cs b/Runtime/HdrpMaterialResolver.cs index 34622006..3ab9cb28 100644 --- a/Runtime/HdrpMaterialResolver.cs +++ b/Runtime/HdrpMaterialResolver.cs @@ -178,9 +178,24 @@ private Material BuildInsertShaderMaterial(string name, VpeInsertShaderProfile p // The keywords come with the template: rebuilt from the restored values, so a cover // without refraction doesn't keep the template's. HDMaterial.ValidateMaterial(material); + InsertTracedKeyword(material); return material; } + /// + /// The insert's opt-in Traced mode travels as its toggle's value; nothing + /// at runtime turns that back into the keyword. + /// + private static void InsertTracedKeyword(Material material) + { + if (!material.HasProperty("_INSERT_TRACED")) { return; } + if (material.GetFloat("_INSERT_TRACED") > 0.5f) { + material.EnableKeyword("_INSERT_TRACED"); + } else { + material.DisableKeyword("_INSERT_TRACED"); + } + } + private Material BuildShaderGraphMaterial(VpeMaterialProfile profile, VpeShaderGraphProfile shaderGraph) { var templateName = shaderGraph?.TemplateName;