Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void UpgradePBRMasterNode(PBRMasterNode1 pbrMasterNode, out Dictionary<BlockFiel
lightingData.receiveSSRTransparent = false;
litData.materialType = pbrMasterNode.m_Model == PBRMasterNode1.Model.Specular ? HDLitData.MaterialType.SpecularColor : HDLitData.MaterialType.Standard;
litData.energyConservingSpecular = false;
litData.clearCoat = false;
target.customEditorGUI = pbrMasterNode.m_OverrideEnabled ? pbrMasterNode.m_ShaderGUIOverride : "";
systemData.TryChangeRenderingPass(systemData.renderingPass);
// Handle mapping of Normal block specifically
Expand Down Expand Up @@ -137,6 +138,7 @@ void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary<Blo
HDLitData.MaterialType materialType = (HDLitData.MaterialType)hdLitMasterNode.m_MaterialType;
lightingData.subsurfaceScattering = materialType == HDLitData.MaterialType.SubsurfaceScattering;

litData.clearCoat = UpgradeCoatMask(hdLitMasterNode);
litData.energyConservingSpecular = hdLitMasterNode.m_EnergyConservingSpecular;
litData.rayTracing = hdLitMasterNode.m_RayTracing;
litData.refractionModel = hdLitMasterNode.m_RefractionModel;
Expand Down Expand Up @@ -209,6 +211,19 @@ bool AdditionalSlotMaskTests(HDLitMasterNode1.SlotMask slotMask)
}
}

bool UpgradeCoatMask(HDLitMasterNode1 masterNode)
{
var coatMaskSlotId = HDLitMasterNode1.CoatMaskSlotId;

var node = masterNode as AbstractMaterialNode;
var coatMaskSlot = node.FindSlot<Vector1MaterialSlot>(coatMaskSlotId);
if(coatMaskSlot == null)
return false;

coatMaskSlot.owner = node;
return (coatMaskSlot.isConnected || coatMaskSlot.value > 0.0f);
}

// Set blockmap
blockMap = new Dictionary<BlockFieldDescriptor, int>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down