Skip to content

Commit

Permalink
feat: allow choice between implicit and explicit queue and surface ty…
Browse files Browse the repository at this point in the history
…pe control
  • Loading branch information
hybridherbst committed Sep 7, 2023
1 parent a60acbd commit 1c144da
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 23 deletions.
44 changes: 21 additions & 23 deletions Editor/Scripts/Internal/GLTFMaterialHelper.cs
Expand Up @@ -84,25 +84,23 @@ 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";
if (material.HasInt(blendModeProp))
{
var blendMode = material.GetInt(blendModeProp);
isImplicitBlendMode = blendMode == 0;
}

if (material.IsKeywordEnabled("_VOLUME_TRANSMISSION_ON"))
if (isImplicitBlendMode)
{
// // approximation when transmission is on but roughness == 0
// // (no opaque pass required)
// TODO does weird things with transparency but still rendering into the Opaque Texture for some reason
// if (material.HasProperty("roughnessFactor") && material.GetFloat("roughnessFactor") == 0)
// {
// // enforce transparent
// if (material.HasProperty("_QueueControl")) material.SetFloat("_QueueControl", 0);
// if (material.HasProperty("_BUILTIN_QueueControl")) material.SetFloat("_BUILTIN_QueueControl", 0);
// if (material.HasProperty("_BUILTIN_Surface")) material.SetFloat("_BUILTIN_Surface", 1);
// if (material.HasProperty("_Surface")) material.SetFloat("_Surface", 1);
// material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
// material.EnableKeyword("_BUILTIN_SURFACE_TYPE_TRANSPARENT");
// material.renderQueue = -1;
// }
// else
if (material.IsKeywordEnabled("_VOLUME_TRANSMISSION_ON"))
{
// We want to enforce opaque rendering if
// - Transmission is enabled
// - Roughness is > 0
// - The material isn't set to explicitly render as transparent

// enforce Opaque
if (material.HasProperty("_BUILTIN_Surface")) material.SetFloat("_BUILTIN_Surface", 0);
if (material.HasProperty("_Surface")) material.SetFloat("_Surface", 0);
Expand All @@ -117,14 +115,14 @@ public static void ValidateMaterialKeywords(Material material)
// so the change can be reverted if someone toggles transmission on and then off again.
material.renderQueue = 2999;
}
}
else
{
if (material.renderQueue == 2999)
else
{
if (material.HasProperty("_QueueControl")) material.SetFloat("_QueueControl", 0);
if (material.HasProperty("_BUILTIN_QueueControl")) material.SetFloat("_BUILTIN_QueueControl", 0);
material.renderQueue = -1;
if (material.renderQueue == 2999)
{
if (material.HasProperty("_QueueControl")) material.SetFloat("_QueueControl", 0);
if (material.HasProperty("_BUILTIN_QueueControl")) material.SetFloat("_BUILTIN_QueueControl", 0);
material.renderQueue = -1;
}
}
}

Expand Down
33 changes: 33 additions & 0 deletions Runtime/Shaders/ShaderGraph/PBRGraph.shadergraph
Expand Up @@ -221,6 +221,9 @@
},
{
"m_Id": "14ec0a08cca146a98862d31183f587f4"
},
{
"m_Id": "5959c998527d4aaf8a3653895a8d1279"
}
],
"m_Keywords": [
Expand Down Expand Up @@ -12836,6 +12839,33 @@
"m_Labels": []
}

{
"m_SGVersion": 1,
"m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty",
"m_ObjectId": "5959c998527d4aaf8a3653895a8d1279",
"m_Guid": {
"m_GuidSerialized": "dab1ea9d-9855-4409-ae49-b4a26815c9f9"
},
"m_Name": "Auto Surface and Queue",
"m_DefaultRefNameVersion": 1,
"m_RefNameGeneratedByDisplayName": "Auto Surface and Queue",
"m_DefaultReferenceName": "_Auto_Surface_and_Queue",
"m_OverrideReferenceName": "_AutoSurfaceMode",
"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_SGVersion": 0,
"m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot",
Expand Down Expand Up @@ -28892,6 +28922,9 @@
},
{
"m_Id": "14eb9f49890e4fdf8e6c058bfe728c2c"
},
{
"m_Id": "5959c998527d4aaf8a3653895a8d1279"
}
]
}
Expand Down

0 comments on commit 1c144da

Please sign in to comment.