Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 53 additions & 6 deletions Editor/InsertShaderGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Material>().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();
}
}

/// <summary>
/// The opt-in Traced mode in a section of its own, its controls shown
/// only while it's on, as in HDRP's inspector.
/// </summary>
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<Material>().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";

/// <summary>
/// Presets own these controls in both pipelines. Edit the linked
/// preset through the Insert inspector, or unlink it there first.
/// </summary>
private static bool Owned(MaterialEditor materialEditor, string name) => materialEditor.targets.OfType<Material>().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";
}
}
9 changes: 9 additions & 0 deletions Runtime/UrpMaterialResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down