diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitData.cs index c3e2497f874..798de0ea7f8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitData.cs @@ -66,5 +66,13 @@ public bool energyConservingSpecular get => m_EnergyConservingSpecular; set => m_EnergyConservingSpecular = value; } + + [SerializeField] + bool m_ClearCoat = false; + public bool clearCoat + { + get => m_ClearCoat; + set => m_ClearCoat = value; + } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs index 70352a6a493..d5ec80c88ee 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs @@ -49,6 +49,7 @@ void UpgradePBRMasterNode(PBRMasterNode1 pbrMasterNode, out Dictionary(coatMaskSlotId); + if(coatMaskSlot == null) + return false; + + coatMaskSlot.owner = node; + return (coatMaskSlot.isConnected || coatMaskSlot.value > 0.0f); + } + // Set blockmap blockMap = new Dictionary(); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs index 132a50d6c4a..32c94773331 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -84,7 +84,8 @@ public override void GetFields(ref TargetFieldContext context) // Misc context.AddField(HDFields.EnergyConservingSpecular, litData.energyConservingSpecular); - context.AddField(HDFields.CoatMask, context.blocks.Contains(HDBlockFields.SurfaceDescription.CoatMask) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatMask)); + context.AddField(HDFields.CoatMask, context.blocks.Contains(HDBlockFields.SurfaceDescription.CoatMask) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatMask) && litData.clearCoat); + context.AddField(HDFields.ClearCoat, litData.clearCoat); // Enable clear coat material feature context.AddField(HDFields.Tangent, context.blocks.Contains(HDBlockFields.SurfaceDescription.Tangent) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.Tangent)); context.AddField(HDFields.RayTracing, litData.rayTracing); } @@ -99,7 +100,7 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) AddDistortionBlocks(ref context); // Common - context.AddBlock(HDBlockFields.SurfaceDescription.CoatMask); + context.AddBlock(HDBlockFields.SurfaceDescription.CoatMask, litData.clearCoat); // Refraction context.AddBlock(HDBlockFields.SurfaceDescription.RefractionIndex, hasRefraction); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template index a4bd44baa9c..fd69ae98c17 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPass.template @@ -30,6 +30,7 @@ Pass $Material.Anisotropy: #define _MATERIAL_FEATURE_ANISOTROPY 1 $Material.Iridescence: #define _MATERIAL_FEATURE_IRIDESCENCE 1 $Material.SpecularColor: #define _MATERIAL_FEATURE_SPECULAR_COLOR 1 + $Material.ClearCoat: #define _MATERIAL_FEATURE_CLEAR_COAT $AmbientOcclusion: #define _AMBIENT_OCCLUSION 1 $SpecularOcclusionFromAO: #define _SPECULAR_OCCLUSION_FROM_AO 1 $SpecularOcclusionFromAOBentNormal: #define _SPECULAR_OCCLUSION_FROM_AO_BENT_NORMAL 1 @@ -207,7 +208,9 @@ Pass surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_SPECULAR_COLOR; #endif - $CoatMask: surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #ifdef _MATERIAL_FEATURE_CLEAR_COAT + surfaceData.materialFeatures |= MATERIALFEATUREFLAGS_LIT_CLEAR_COAT; + #endif #if defined (_MATERIAL_FEATURE_SPECULAR_COLOR) && defined (_ENERGY_CONSERVING_SPECULAR) // Require to have setup baseColor diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs index 560f746b117..02a5bee5051 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs @@ -17,6 +17,11 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph class LitSurfaceOptionPropertyBlock : SurfaceOptionPropertyBlock { HDLitData litData; + + class Styles + { + public static GUIContent enableClearCoat = new GUIContent("Clear Coat", "Enable Clear Coat"); + } public LitSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features features, HDLitData litData) : base(features) => this.litData = litData; @@ -34,6 +39,7 @@ protected override void CreatePropertyGUI() base.CreatePropertyGUI(); + AddProperty(Styles.enableClearCoat, () => litData.clearCoat, (newValue) => litData.clearCoat = newValue); AddProperty(transmissionEnableText, () => litData.sssTransmission, (newValue) => litData.sssTransmission = newValue); AddProperty(refractionModelText, () => litData.refractionModel, (newValue) => litData.refractionModel = newValue); AddProperty(energyConservingSpecularColorText, () => litData.energyConservingSpecular, (newValue) => litData.energyConservingSpecular = newValue); diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDFields.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDFields.cs index fae9db2cf7a..be0eb8f1caf 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDFields.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDFields.cs @@ -32,6 +32,7 @@ static class HDFields public static FieldDescriptor Transmission = new FieldDescriptor(kMaterial, "Transmission", "_MATERIAL_FEATURE_TRANSMISSION 1"); public static FieldDescriptor Translucent = new FieldDescriptor(kMaterial, "Translucent", "_MATERIAL_FEATURE_TRANSLUCENT 1"); public static FieldDescriptor Coat = new FieldDescriptor(kMaterial, "Coat", "_MATERIAL_FEATURE_COAT"); + public static FieldDescriptor ClearCoat = new FieldDescriptor(kMaterial, "ClearCoat", "_MATERIAL_FEATURE_CLEAR_COAT"); public static FieldDescriptor CoatNormal = new FieldDescriptor(kMaterial, "CoatNormal", "_MATERIAL_FEATURE_COAT_NORMALMAP"); public static FieldDescriptor DualSpecularLobe = new FieldDescriptor(kMaterial, "DualSpecularLobe", "_MATERIAL_FEATURE_DUAL_SPECULAR_LOBE"); public static FieldDescriptor Eye = new FieldDescriptor(kMaterial, "Eye", "_MATERIAL_FEATURE_EYE 1");