Skip to content

Commit

Permalink
better inspector to show mode overrides, rename _AutoSurfaceMode to c…
Browse files Browse the repository at this point in the history
…learer _OverrideSurfaceMode
  • Loading branch information
hybridherbst committed Jan 17, 2024
1 parent c64426c commit 5edbe46
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Editor/Scripts/Internal/GLTFMaterialHelper.cs
Expand Up @@ -85,7 +85,8 @@ public static void ValidateMaterialKeywords(Material material)
// var needsSpecular = material.HasProperty(specularFactor) && material.GetFloat(specularFactor) > 0;
// material.SetKeyword("_SPECULAR", needsSpecular);
var isImplicitBlendMode = true;
const string blendModeProp = "_AutoSurfaceMode";

const string blendModeProp = "_OverrideSurfaceMode";
if (material.HasProperty(blendModeProp))
{
var blendMode = material.GetInt(blendModeProp);
Expand Down
22 changes: 22 additions & 0 deletions Editor/Scripts/ShaderGraph/InternalShaderGraph/PBRGraphGUI.cs
Expand Up @@ -529,9 +529,31 @@ private void DrawProperties(Material targetMaterial, MaterialProperty[] properti
{
propertyList.RemoveAll(x => x.name == "alphaCutoff");
}

// remove advanced properties that we want to draw a foldout for
var overrideSurfaceMode = propertyList.FirstOrDefault(x => x.name == "_OverrideSurfaceMode");
var normalMapFormatXYZ = propertyList.FirstOrDefault(x => x.name == "_NormalMapFormatXYZ");
if (overrideSurfaceMode != null) propertyList.Remove(overrideSurfaceMode);
if (normalMapFormatXYZ != null) propertyList.Remove(normalMapFormatXYZ);

// TODO we probably want full manual control, all this internal access is horrible...
// E.g. impossible to render inline texture properties...
ShaderGraphHelpers.DrawShaderGraphGUI(materialEditor, propertyList);

// draw a foldout with the advanced properties
const string key = nameof(PBRGraphGUI) + "_AdvancedFoldout";
var val = SessionState.GetBool(key, false);
var newVal = EditorGUILayout.Foldout(val, "Mode Overrides", true);
if (newVal != val) SessionState.SetBool(key, newVal);
if (newVal)
{
EditorGUI.indentLevel++;
if (overrideSurfaceMode != null) materialEditor.ShaderProperty(overrideSurfaceMode,
new GUIContent(overrideSurfaceMode.displayName, "When disabled, surface mode and queue are set by default based on material options. For example, transmissive objects will be set to \"transparent\". For some cases, explicit control over the surface mode helps with render order, e.g. nested transparency sorting."));
if (normalMapFormatXYZ != null) materialEditor.ShaderProperty(normalMapFormatXYZ,
new GUIContent(normalMapFormatXYZ.displayName, "When disabled, normal maps are assumed to be in the specified project format (XYZ or DXT5nm). Normal maps imported at runtime are always in XYZ, so this option is enabled for materials imported at runtime."));
EditorGUI.indentLevel--;
}
}

public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader)
Expand Down
27 changes: 11 additions & 16 deletions Runtime/Shaders/ShaderGraph/PBRGraph.shadergraph
Expand Up @@ -7596,7 +7596,7 @@
"m_Type": "UnityEditor.ShaderGraph.BooleanMaterialSlot",
"m_ObjectId": "2090fe25b14c4580b73042885a983527",
"m_Id": 0,
"m_DisplayName": "NormalMapFormatXYZ",
"m_DisplayName": "Override Normal Map is XYZ",
"m_SlotType": 1,
"m_Hidden": false,
"m_ShaderOutputName": "Out",
Expand Down Expand Up @@ -7640,11 +7640,11 @@
"m_Guid": {
"m_GuidSerialized": "8caf300e-d530-4793-835f-30b40abbc6f2"
},
"m_Name": "NormalMapFormatXYZ",
"m_Name": "Override Normal Map is XYZ",
"m_DefaultRefNameVersion": 1,
"m_RefNameGeneratedByDisplayName": "NormalMapFormatXYZ",
"m_DefaultReferenceName": "_NormalMapFormatXYZ",
"m_OverrideReferenceName": "",
"m_RefNameGeneratedByDisplayName": "Override Normal Map is XYZ",
"m_DefaultReferenceName": "_Override_Normal_Map_is_XYZ",
"m_OverrideReferenceName": "_NormalMapFormatXYZ",
"m_GeneratePropertyBlock": true,
"m_UseCustomSlotLabel": false,
"m_CustomSlotLabel": "",
Expand Down Expand Up @@ -12915,29 +12915,24 @@

{
"m_SGVersion": 1,
"m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty",
"m_Type": "UnityEditor.ShaderGraph.Internal.BooleanShaderProperty",
"m_ObjectId": "5959c998527d4aaf8a3653895a8d1279",
"m_Guid": {
"m_GuidSerialized": "dab1ea9d-9855-4409-ae49-b4a26815c9f9"
},
"m_Name": "Auto Surface and Queue",
"m_Name": "Override Surface Type and Queue",
"m_DefaultRefNameVersion": 1,
"m_RefNameGeneratedByDisplayName": "Auto Surface and Queue",
"m_DefaultReferenceName": "_Auto_Surface_and_Queue",
"m_OverrideReferenceName": "_AutoSurfaceMode",
"m_RefNameGeneratedByDisplayName": "Override Surface Type and Queue",
"m_DefaultReferenceName": "_Override_Surface_Type_and_Queue",
"m_OverrideReferenceName": "_OverrideSurfaceMode",
"m_GeneratePropertyBlock": true,
"m_UseCustomSlotLabel": false,
"m_CustomSlotLabel": "",
"m_Precision": 0,
"overrideHLSLDeclaration": false,
"hlslDeclarationOverride": 2,
"m_Hidden": false,
"m_Value": 0.0,
"m_FloatType": 2,
"m_RangeValues": {
"x": 0.0,
"y": 1.0
}
"m_Value": false
}

{
Expand Down

0 comments on commit 5edbe46

Please sign in to comment.