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
3 changes: 2 additions & 1 deletion Editor/HdrpMaterialTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
36 changes: 36 additions & 0 deletions Editor/Insert/InsertHybridGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/// <summary>
Expand Down Expand Up @@ -710,4 +711,39 @@ private void Texture(GUIContent label, string name)
}
}
}

/// <summary>
/// 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 <see cref="InsertTracedFields"/>, shared
/// with URP.
/// </summary>
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);
}
}
}
}
}
}
15 changes: 15 additions & 0 deletions Runtime/HdrpMaterialResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
/// The insert's opt-in Traced mode travels as its toggle's value; nothing
/// at runtime turns that back into the keyword.
/// </summary>
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;
Expand Down