From 60a327c8edcc97e84c2e2e93086c0b5194ed0d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 20 May 2020 14:22:01 +0200 Subject: [PATCH 01/11] Moved sub-target upgrade code to migration files and refactored the HD blocks # Conflicts: # TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/9x_Other/9701_CustomPass_DrawRenderers/9701_UnlitRT.mat --- .../ShaderGraph/DecalSubTarget.Migration.cs | 70 ++++ .../DecalSubTarget.Migration.cs.meta | 11 + .../Decal/ShaderGraph/DecalSubTarget.cs | 60 +-- .../Eye/ShaderGraph/EyeSubTarget.Migration.cs | 127 +++++++ .../EyeSubTarget.Migration.cs.meta | 11 + .../Material/Eye/ShaderGraph/EyeSubTarget.cs | 146 +------- .../ShaderGraph/FabricSubTarget.Migration.cs | 130 +++++++ .../FabricSubTarget.Migration.cs.meta | 11 + .../Fabric/ShaderGraph/FabricSubTarget.cs | 151 +------- .../Hair/ShaderGraph/HairSettingsView.cs | 12 +- .../ShaderGraph/HairSubTarget.Migration.cs | 146 ++++++++ .../HairSubTarget.Migration.cs.meta | 11 + .../Hair/ShaderGraph/HairSubTarget.cs | 192 +--------- .../Material/Lit/ShaderGraph/HDLitData.cs | 18 - .../Lit/ShaderGraph/HDLitSettingsView.cs | 12 +- .../ShaderGraph/HDLitSubTarget.Migration.cs | 271 ++++++++++++++ .../HDLitSubTarget.Migration.cs.meta | 11 + .../Lit/ShaderGraph/HDLitSubTarget.cs | 348 +----------------- .../Material/ShaderGraph/HDSubTarget.cs | 5 +- .../Material/ShaderGraph/LightingSubTarget.cs | 43 ++- .../Material/ShaderGraph/SurfaceSubTarget.cs | 31 +- .../StackLitSubTarget.Migration.cs | 240 ++++++++++++ .../StackLitSubTarget.Migration.cs.meta | 11 + .../StackLit/ShaderGraph/StackLitSubTarget.cs | 269 +------------- .../ShaderGraph/HDUnlitSubTarget.Migration.cs | 108 ++++++ .../HDUnlitSubTarget.Migration.cs.meta | 11 + .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 122 +----- .../ShaderGraph/TargetData/BuiltinData.cs | 16 + .../ShaderGraph/TargetData/LightingData.cs | 16 - 29 files changed, 1343 insertions(+), 1267 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.Migration.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.Migration.cs.meta create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs.meta create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs.meta create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.Migration.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.Migration.cs.meta create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs.meta create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs.meta create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs.meta diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.Migration.cs new file mode 100644 index 00000000000..b7699a48739 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.Migration.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEditor.ShaderGraph.Internal; +using UnityEditor.Graphing; +using UnityEditor.ShaderGraph.Legacy; +using UnityEditor.Rendering.HighDefinition.ShaderGraph.Legacy; +using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; +using static UnityEditor.Rendering.HighDefinition.HDShaderUtils; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + sealed partial class DecalSubTarget : HDSubTarget, ILegacyTarget, IRequiresData + { + public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) + { + blockMap = null; + if(!(masterNode is DecalMasterNode1 decalMasterNode)) + return false; + + // Set data + systemData.surfaceType = (SurfaceType)decalMasterNode.m_SurfaceType; + systemData.dotsInstancing = decalMasterNode.m_DOTSInstancing; + decalData.affectsMetal = decalMasterNode.m_AffectsMetal; + decalData.affectsAO = decalMasterNode.m_AffectsAO; + decalData.affectsSmoothness = decalMasterNode.m_AffectsSmoothness; + decalData.affectsAlbedo = decalMasterNode.m_AffectsAlbedo; + decalData.affectsNormal = decalMasterNode.m_AffectsNormal; + decalData.affectsEmission = decalMasterNode.m_AffectsEmission; + decalData.drawOrder = decalMasterNode.m_DrawOrder; + target.customEditorGUI = decalMasterNode.m_OverrideEnabled ? decalMasterNode.m_ShaderGUIOverride : ""; + + // Convert SlotMask to BlockMap entries + var blockMapLookup = new Dictionary() + { + { DecalMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position }, + { DecalMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal }, + { DecalMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent }, + { DecalMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor }, + { DecalMasterNode1.SlotMask.AlphaAlbedo, BlockFields.SurfaceDescription.Alpha }, + { DecalMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS }, + { DecalMasterNode1.SlotMask.AlphaNormal, HDBlockFields.SurfaceDescription.NormalAlpha }, + { DecalMasterNode1.SlotMask.Metallic, BlockFields.SurfaceDescription.Metallic }, + { DecalMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion }, + { DecalMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness }, + { DecalMasterNode1.SlotMask.AlphaMAOS, HDBlockFields.SurfaceDescription.MAOSAlpha }, + { DecalMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission }, + }; + + // Set blockmap + blockMap = new Dictionary(); + foreach(DecalMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(DecalMasterNode1.SlotMask))) + { + if(decalMasterNode.MaterialTypeUsesSlotMask(slotMask)) + { + if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor)) + continue; + + var slotId = Mathf.Log((int)slotMask, 2); + blockMap.Add(blockFieldDescriptor, (int)slotId); + } + } + + return true; + } + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.Migration.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.Migration.cs.meta new file mode 100644 index 00000000000..aa12b350414 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.Migration.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f1fccb4c5ef1c0c41a8c38dc63bdf983 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs index f85234c6c44..d10fe5c1170 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs @@ -13,7 +13,7 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { - sealed class DecalSubTarget : HDSubTarget, ILegacyTarget, IRequiresData + sealed partial class DecalSubTarget : HDSubTarget, ILegacyTarget, IRequiresData { static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Decal/ShaderGraph/DecalPass.template"; @@ -48,7 +48,7 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - // Material + // Decal properties context.AddField(HDFields.AffectsAlbedo, decalData.affectsAlbedo); context.AddField(HDFields.AffectsNormal, decalData.affectsNormal); context.AddField(HDFields.AffectsEmission, decalData.affectsEmission); @@ -106,62 +106,6 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera collector.AddShaderProperty(decalMeshDepthBias); } - public override void ProcessPreviewMaterial(Material material) - { - } - - public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) - { - blockMap = null; - if(!(masterNode is DecalMasterNode1 decalMasterNode)) - return false; - - // Set data - systemData.surfaceType = (SurfaceType)decalMasterNode.m_SurfaceType; - systemData.dotsInstancing = decalMasterNode.m_DOTSInstancing; - decalData.affectsMetal = decalMasterNode.m_AffectsMetal; - decalData.affectsAO = decalMasterNode.m_AffectsAO; - decalData.affectsSmoothness = decalMasterNode.m_AffectsSmoothness; - decalData.affectsAlbedo = decalMasterNode.m_AffectsAlbedo; - decalData.affectsNormal = decalMasterNode.m_AffectsNormal; - decalData.affectsEmission = decalMasterNode.m_AffectsEmission; - decalData.drawOrder = decalMasterNode.m_DrawOrder; - target.customEditorGUI = decalMasterNode.m_OverrideEnabled ? decalMasterNode.m_ShaderGUIOverride : ""; - - // Convert SlotMask to BlockMap entries - var blockMapLookup = new Dictionary() - { - { DecalMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position }, - { DecalMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal }, - { DecalMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent }, - { DecalMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor }, - { DecalMasterNode1.SlotMask.AlphaAlbedo, BlockFields.SurfaceDescription.Alpha }, - { DecalMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS }, - { DecalMasterNode1.SlotMask.AlphaNormal, HDBlockFields.SurfaceDescription.NormalAlpha }, - { DecalMasterNode1.SlotMask.Metallic, BlockFields.SurfaceDescription.Metallic }, - { DecalMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion }, - { DecalMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness }, - { DecalMasterNode1.SlotMask.AlphaMAOS, HDBlockFields.SurfaceDescription.MAOSAlpha }, - { DecalMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission }, - }; - - // Set blockmap - blockMap = new Dictionary(); - foreach(DecalMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(DecalMasterNode1.SlotMask))) - { - if(decalMasterNode.MaterialTypeUsesSlotMask(slotMask)) - { - if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor)) - continue; - - var slotId = Mathf.Log((int)slotMask, 2); - blockMap.Add(blockFieldDescriptor, (int)slotId); - } - } - - return true; - } - #region SubShaders static class SubShaders { diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs new file mode 100644 index 00000000000..c3e7a09fc60 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEditor.ShaderGraph.Internal; +using UnityEditor.Graphing; +using UnityEditor.ShaderGraph.Legacy; +using UnityEditor.Rendering.HighDefinition.ShaderGraph.Legacy; +using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; +using static UnityEditor.Rendering.HighDefinition.HDShaderUtils; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + sealed partial class EyeSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData + { + public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) + { + blockMap = null; + if(!(masterNode is EyeMasterNode1 eyeMasterNode)) + return false; + + // Set data + systemData.surfaceType = (SurfaceType)eyeMasterNode.m_SurfaceType; + systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)eyeMasterNode.m_AlphaMode); + systemData.alphaTest = eyeMasterNode.m_AlphaTest; + systemData.alphaTestDepthPrepass = eyeMasterNode.m_AlphaTestDepthPrepass; + systemData.alphaTestDepthPostpass = eyeMasterNode.m_AlphaTestDepthPostpass; + systemData.sortPriority = eyeMasterNode.m_SortPriority; + systemData.doubleSidedMode = eyeMasterNode.m_DoubleSidedMode; + systemData.zWrite = eyeMasterNode.m_ZWrite; + systemData.transparentCullMode = eyeMasterNode.m_transparentCullMode; + systemData.zTest = eyeMasterNode.m_ZTest; + systemData.supportLodCrossFade = eyeMasterNode.m_SupportLodCrossFade; + systemData.dotsInstancing = eyeMasterNode.m_DOTSInstancing; + systemData.materialNeedsUpdateHash = eyeMasterNode.m_MaterialNeedsUpdateHash; + + builtinData.transparencyFog = eyeMasterNode.m_TransparencyFog; + builtinData.addPrecomputedVelocity = eyeMasterNode.m_AddPrecomputedVelocity; + builtinData.depthOffset = eyeMasterNode.m_depthOffset; + builtinData.alphaToMask = eyeMasterNode.m_AlphaToMask; + + lightingData.blendPreserveSpecular = eyeMasterNode.m_BlendPreserveSpecular; + lightingData.receiveDecals = eyeMasterNode.m_ReceiveDecals; + lightingData.receiveSSR = eyeMasterNode.m_ReceivesSSR; + lightingData.specularOcclusionMode = eyeMasterNode.m_SpecularOcclusionMode; + lightingData.overrideBakedGI = eyeMasterNode.m_overrideBakedGI; + lightingData.subsurfaceScattering = eyeMasterNode.m_SubsurfaceScattering; + + eyeData.materialType = (EyeData.MaterialType)eyeMasterNode.m_MaterialType; + target.customEditorGUI = eyeMasterNode.m_OverrideEnabled ? eyeMasterNode.m_ShaderGUIOverride : ""; + + // Convert SlotMask to BlockMap entries + var blockMapLookup = new Dictionary() + { + { EyeMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position }, + { EyeMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal }, + { EyeMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent }, + { EyeMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor }, + { EyeMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion }, + { EyeMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS }, + { EyeMasterNode1.SlotMask.IrisNormal, HDBlockFields.SurfaceDescription.IrisNormal }, + { EyeMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal }, + { EyeMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness }, + { EyeMasterNode1.SlotMask.IOR, HDBlockFields.SurfaceDescription.IOR }, + { EyeMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion }, + { EyeMasterNode1.SlotMask.Mask, HDBlockFields.SurfaceDescription.Mask }, + { EyeMasterNode1.SlotMask.DiffusionProfile, HDBlockFields.SurfaceDescription.DiffusionProfileHash }, + { EyeMasterNode1.SlotMask.SubsurfaceMask, HDBlockFields.SurfaceDescription.SubsurfaceMask }, + { EyeMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission }, + { EyeMasterNode1.SlotMask.Alpha, BlockFields.SurfaceDescription.Alpha }, + { EyeMasterNode1.SlotMask.AlphaClipThreshold, BlockFields.SurfaceDescription.AlphaClipThreshold }, + }; + + // Legacy master node slots have additional slot conditions, test them here + bool AdditionalSlotMaskTests(EyeMasterNode1.SlotMask slotMask) + { + switch(slotMask) + { + case EyeMasterNode1.SlotMask.SpecularOcclusion: + return lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom; + case EyeMasterNode1.SlotMask.DiffusionProfile: + return lightingData.subsurfaceScattering; + case EyeMasterNode1.SlotMask.SubsurfaceMask: + return lightingData.subsurfaceScattering; + case EyeMasterNode1.SlotMask.AlphaClipThreshold: + return systemData.alphaTest; + default: + return true; + } + } + + // Set blockmap + blockMap = new Dictionary(); + foreach(EyeMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(EyeMasterNode1.SlotMask))) + { + if(eyeMasterNode.MaterialTypeUsesSlotMask(slotMask)) + { + if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor)) + continue; + + if(!AdditionalSlotMaskTests(slotMask)) + continue; + + var slotId = Mathf.Log((int)slotMask, 2); + blockMap.Add(blockFieldDescriptor, (int)slotId); + } + } + + // Override Baked GI + if(lightingData.overrideBakedGI) + { + blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, EyeMasterNode1.LightingSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, EyeMasterNode1.BackLightingSlotId); + } + + // Depth Offset + if(builtinData.depthOffset) + { + blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, EyeMasterNode1.DepthOffsetSlotId); + } + + return true; + } + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs.meta new file mode 100644 index 00000000000..b49e04e9f1d --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c43943c04106ed4418f28341b8bc7388 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs index a81e6277870..3e447273d1b 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs @@ -13,7 +13,7 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { - sealed class EyeSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData + sealed partial class EyeSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData { static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Eye/ShaderGraph/EyePass.template"; protected override string customInspector => "Rendering.HighDefinition.EyeGUI"; @@ -43,49 +43,32 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - base.GetFields(ref context); + AddSystemDataFields(ref context); + AddSpecularOcclusionFields(ref context); + AddLitMiscFields(ref context); + AddSurfaceMiscFields(ref context); - // Structs + // Eye specific properties context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(EyeSubTarget.EyePasses.MotionVectors)); - - // Material context.AddField(HDFields.Eye, eyeData.materialType == EyeData.MaterialType.Eye); context.AddField(HDFields.EyeCinematic, eyeData.materialType == EyeData.MaterialType.EyeCinematic); context.AddField(HDFields.SubsurfaceScattering, lightingData.subsurfaceScattering && systemData.surfaceType != SurfaceType.Transparent); - - AddSpecularOcclusionFields(ref context); - - // Misc - AddLitMiscFields(ref context); - AddSurfaceMiscFields(ref context); context.AddField(HDFields.DoAlphaTest, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold)); } public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - // Vertex - context.AddBlock(BlockFields.VertexDescription.Position); - context.AddBlock(BlockFields.VertexDescription.Normal); - context.AddBlock(BlockFields.VertexDescription.Tangent); - - // Eye - context.AddBlock(BlockFields.SurfaceDescription.BaseColor); - context.AddBlock(HDBlockFields.SurfaceDescription.SpecularOcclusion, lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom); + AddVertexBlocks(ref context); + AddSurfaceBlocks(ref context); + + // Eye specific blocks context.AddBlock(BlockFields.SurfaceDescription.NormalTS); context.AddBlock(HDBlockFields.SurfaceDescription.IrisNormal); context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); - context.AddBlock(BlockFields.SurfaceDescription.Smoothness); context.AddBlock(HDBlockFields.SurfaceDescription.IOR); - context.AddBlock(BlockFields.SurfaceDescription.Occlusion); context.AddBlock(HDBlockFields.SurfaceDescription.Mask); context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, lightingData.subsurfaceScattering); context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, lightingData.subsurfaceScattering); - context.AddBlock(BlockFields.SurfaceDescription.Emission); - context.AddBlock(BlockFields.SurfaceDescription.Alpha); - context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, systemData.alphaTest); - context.AddBlock(HDBlockFields.SurfaceDescription.BakedGI, lightingData.overrideBakedGI); - context.AddBlock(HDBlockFields.SurfaceDescription.BakedBackGI, lightingData.overrideBakedGI); - context.AddBlock(HDBlockFields.SurfaceDescription.DepthOffset, builtinData.depthOffset); } public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) @@ -158,115 +141,6 @@ public override void ProcessPreviewMaterial(Material material) EyeGUI.SetupMaterialKeywordsAndPass(material); } - public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) - { - blockMap = null; - if(!(masterNode is EyeMasterNode1 eyeMasterNode)) - return false; - - // Set data - systemData.surfaceType = (SurfaceType)eyeMasterNode.m_SurfaceType; - systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)eyeMasterNode.m_AlphaMode); - systemData.alphaTest = eyeMasterNode.m_AlphaTest; - systemData.alphaTestDepthPrepass = eyeMasterNode.m_AlphaTestDepthPrepass; - systemData.alphaTestDepthPostpass = eyeMasterNode.m_AlphaTestDepthPostpass; - systemData.sortPriority = eyeMasterNode.m_SortPriority; - systemData.doubleSidedMode = eyeMasterNode.m_DoubleSidedMode; - systemData.zWrite = eyeMasterNode.m_ZWrite; - systemData.transparentCullMode = eyeMasterNode.m_transparentCullMode; - systemData.zTest = eyeMasterNode.m_ZTest; - systemData.supportLodCrossFade = eyeMasterNode.m_SupportLodCrossFade; - systemData.dotsInstancing = eyeMasterNode.m_DOTSInstancing; - systemData.materialNeedsUpdateHash = eyeMasterNode.m_MaterialNeedsUpdateHash; - - builtinData.transparencyFog = eyeMasterNode.m_TransparencyFog; - builtinData.addPrecomputedVelocity = eyeMasterNode.m_AddPrecomputedVelocity; - builtinData.depthOffset = eyeMasterNode.m_depthOffset; - builtinData.alphaToMask = eyeMasterNode.m_AlphaToMask; - - lightingData.blendPreserveSpecular = eyeMasterNode.m_BlendPreserveSpecular; - lightingData.receiveDecals = eyeMasterNode.m_ReceiveDecals; - lightingData.receiveSSR = eyeMasterNode.m_ReceivesSSR; - lightingData.specularOcclusionMode = eyeMasterNode.m_SpecularOcclusionMode; - lightingData.overrideBakedGI = eyeMasterNode.m_overrideBakedGI; - lightingData.subsurfaceScattering = eyeMasterNode.m_SubsurfaceScattering; - - eyeData.materialType = (EyeData.MaterialType)eyeMasterNode.m_MaterialType; - target.customEditorGUI = eyeMasterNode.m_OverrideEnabled ? eyeMasterNode.m_ShaderGUIOverride : ""; - - // Convert SlotMask to BlockMap entries - var blockMapLookup = new Dictionary() - { - { EyeMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position }, - { EyeMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal }, - { EyeMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent }, - { EyeMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor }, - { EyeMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion }, - { EyeMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS }, - { EyeMasterNode1.SlotMask.IrisNormal, HDBlockFields.SurfaceDescription.IrisNormal }, - { EyeMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal }, - { EyeMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness }, - { EyeMasterNode1.SlotMask.IOR, HDBlockFields.SurfaceDescription.IOR }, - { EyeMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion }, - { EyeMasterNode1.SlotMask.Mask, HDBlockFields.SurfaceDescription.Mask }, - { EyeMasterNode1.SlotMask.DiffusionProfile, HDBlockFields.SurfaceDescription.DiffusionProfileHash }, - { EyeMasterNode1.SlotMask.SubsurfaceMask, HDBlockFields.SurfaceDescription.SubsurfaceMask }, - { EyeMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission }, - { EyeMasterNode1.SlotMask.Alpha, BlockFields.SurfaceDescription.Alpha }, - { EyeMasterNode1.SlotMask.AlphaClipThreshold, BlockFields.SurfaceDescription.AlphaClipThreshold }, - }; - - // Legacy master node slots have additional slot conditions, test them here - bool AdditionalSlotMaskTests(EyeMasterNode1.SlotMask slotMask) - { - switch(slotMask) - { - case EyeMasterNode1.SlotMask.SpecularOcclusion: - return lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom; - case EyeMasterNode1.SlotMask.DiffusionProfile: - return lightingData.subsurfaceScattering; - case EyeMasterNode1.SlotMask.SubsurfaceMask: - return lightingData.subsurfaceScattering; - case EyeMasterNode1.SlotMask.AlphaClipThreshold: - return systemData.alphaTest; - default: - return true; - } - } - - // Set blockmap - blockMap = new Dictionary(); - foreach(EyeMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(EyeMasterNode1.SlotMask))) - { - if(eyeMasterNode.MaterialTypeUsesSlotMask(slotMask)) - { - if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor)) - continue; - - if(!AdditionalSlotMaskTests(slotMask)) - continue; - - var slotId = Mathf.Log((int)slotMask, 2); - blockMap.Add(blockFieldDescriptor, (int)slotId); - } - } - - // Override Baked GI - if(lightingData.overrideBakedGI) - { - blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, EyeMasterNode1.LightingSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, EyeMasterNode1.BackLightingSlotId); - } - - // Depth Offset - if(builtinData.depthOffset) - { - blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, EyeMasterNode1.DepthOffsetSlotId); - } - - return true; - } - #region SubShaders static class SubShaders { diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs new file mode 100644 index 00000000000..c926b9f1e7c --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEditor.ShaderGraph.Internal; +using UnityEditor.Graphing; +using UnityEditor.ShaderGraph.Legacy; +using UnityEditor.Rendering.HighDefinition.ShaderGraph.Legacy; +using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; +using static UnityEditor.Rendering.HighDefinition.HDShaderUtils; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + sealed partial class FabricSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData + { + public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) + { + blockMap = null; + if(!(masterNode is FabricMasterNode1 fabricMasterNode)) + return false; + + // Set data + systemData.surfaceType = (SurfaceType)fabricMasterNode.m_SurfaceType; + systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)fabricMasterNode.m_AlphaMode); + systemData.alphaTest = fabricMasterNode.m_AlphaTest; + systemData.sortPriority = fabricMasterNode.m_SortPriority; + systemData.doubleSidedMode = fabricMasterNode.m_DoubleSidedMode; + systemData.zWrite = fabricMasterNode.m_ZWrite; + systemData.transparentCullMode = fabricMasterNode.m_transparentCullMode; + systemData.zTest = fabricMasterNode.m_ZTest; + systemData.supportLodCrossFade = fabricMasterNode.m_SupportLodCrossFade; + systemData.dotsInstancing = fabricMasterNode.m_DOTSInstancing; + systemData.materialNeedsUpdateHash = fabricMasterNode.m_MaterialNeedsUpdateHash; + + builtinData.transparencyFog = fabricMasterNode.m_TransparencyFog; + builtinData.addPrecomputedVelocity = fabricMasterNode.m_AddPrecomputedVelocity; + builtinData.depthOffset = fabricMasterNode.m_depthOffset; + builtinData.alphaToMask = fabricMasterNode.m_AlphaToMask; + + lightingData.blendPreserveSpecular = fabricMasterNode.m_BlendPreserveSpecular; + lightingData.receiveDecals = fabricMasterNode.m_ReceiveDecals; + lightingData.receiveSSR = fabricMasterNode.m_ReceivesSSR; + lightingData.energyConservingSpecular = fabricMasterNode.m_EnergyConservingSpecular; + lightingData.specularOcclusionMode = fabricMasterNode.m_SpecularOcclusionMode; + lightingData.overrideBakedGI = fabricMasterNode.m_overrideBakedGI; + lightingData.transmission = fabricMasterNode.m_Transmission; + lightingData.subsurfaceScattering = fabricMasterNode.m_SubsurfaceScattering; + + fabricData.materialType = (FabricData.MaterialType)fabricMasterNode.m_MaterialType; + target.customEditorGUI = fabricMasterNode.m_OverrideEnabled ? fabricMasterNode.m_ShaderGUIOverride : ""; + + // Convert SlotMask to BlockMap entries + var blockMapLookup = new Dictionary() + { + { FabricMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position }, + { FabricMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal }, + { FabricMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent }, + { FabricMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor }, + { FabricMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion }, + { FabricMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS }, + { FabricMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal }, + { FabricMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness }, + { FabricMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion }, + { FabricMasterNode1.SlotMask.Specular, BlockFields.SurfaceDescription.Specular }, + { FabricMasterNode1.SlotMask.DiffusionProfile, HDBlockFields.SurfaceDescription.DiffusionProfileHash }, + { FabricMasterNode1.SlotMask.SubsurfaceMask, HDBlockFields.SurfaceDescription.SubsurfaceMask }, + { FabricMasterNode1.SlotMask.Thickness, HDBlockFields.SurfaceDescription.Thickness }, + { FabricMasterNode1.SlotMask.Tangent, HDBlockFields.SurfaceDescription.Tangent }, + { FabricMasterNode1.SlotMask.Anisotropy, HDBlockFields.SurfaceDescription.Anisotropy }, + { FabricMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission }, + { FabricMasterNode1.SlotMask.Alpha, BlockFields.SurfaceDescription.Alpha }, + { FabricMasterNode1.SlotMask.AlphaClipThreshold, BlockFields.SurfaceDescription.AlphaClipThreshold }, + }; + + // Legacy master node slots have additional slot conditions, test them here + bool AdditionalSlotMaskTests(FabricMasterNode1.SlotMask slotMask) + { + switch(slotMask) + { + case FabricMasterNode1.SlotMask.SpecularOcclusion: + return lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom; + case FabricMasterNode1.SlotMask.DiffusionProfile: + return lightingData.subsurfaceScattering || lightingData.transmission; + case FabricMasterNode1.SlotMask.SubsurfaceMask: + return lightingData.subsurfaceScattering; + case FabricMasterNode1.SlotMask.Thickness: + return lightingData.transmission; + case FabricMasterNode1.SlotMask.AlphaClipThreshold: + return systemData.alphaTest; + default: + return true; + } + } + + // Set blockmap + blockMap = new Dictionary(); + foreach(FabricMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(FabricMasterNode1.SlotMask))) + { + if(fabricMasterNode.MaterialTypeUsesSlotMask(slotMask)) + { + if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor)) + continue; + + if(!AdditionalSlotMaskTests(slotMask)) + continue; + + var slotId = Mathf.Log((int)slotMask, 2); + blockMap.Add(blockFieldDescriptor, (int)slotId); + } + } + + // Override Baked GI + if(lightingData.overrideBakedGI) + { + blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, FabricMasterNode1.LightingSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, FabricMasterNode1.BackLightingSlotId); + } + + // Depth Offset + if(builtinData.depthOffset) + { + blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, FabricMasterNode1.DepthOffsetSlotId); + } + + return true; + } + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs.meta new file mode 100644 index 00000000000..6d38ba71c47 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3cf12c31390c5ca4aa5be1436b34f4d1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs index b0fab46ed63..c8550e44d1b 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs @@ -13,7 +13,7 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { - sealed class FabricSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData + sealed partial class FabricSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData { static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Fabric/ShaderGraph/FabricPass.template"; @@ -45,52 +45,33 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - base.GetFields(ref context); + AddSystemDataFields(ref context); + AddSpecularOcclusionFields(ref context); + AddLitMiscFields(ref context); + AddSurfaceMiscFields(ref context); - // Structs + // Fabric specific properties context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(FabricSubTarget.FabricPasses.MotionVectors)); - - // Material context.AddField(HDFields.CottonWool, fabricData.materialType == FabricData.MaterialType.CottonWool); context.AddField(HDFields.Silk, fabricData.materialType == FabricData.MaterialType.Silk); context.AddField(HDFields.SubsurfaceScattering, lightingData.subsurfaceScattering && systemData.surfaceType != SurfaceType.Transparent); context.AddField(HDFields.Transmission, lightingData.transmission); - - // Specular Occlusion - AddSpecularOcclusionFields(ref context); - - // Misc - AddLitMiscFields(ref context); - AddSurfaceMiscFields(ref context); - context.AddField(Fields.AlphaTest, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold)); context.AddField(HDFields.DoAlphaTest, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold)); context.AddField(HDFields.EnergyConservingSpecular, lightingData.energyConservingSpecular); } public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - // Vertex - context.AddBlock(BlockFields.VertexDescription.Position); - context.AddBlock(BlockFields.VertexDescription.Normal); - context.AddBlock(BlockFields.VertexDescription.Tangent); - - // Fabric - context.AddBlock(BlockFields.SurfaceDescription.BaseColor); - context.AddBlock(HDBlockFields.SurfaceDescription.SpecularOcclusion, lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom); + AddVertexBlocks(ref context); + AddSurfaceBlocks(ref context); + + // Fabric specific blocks context.AddBlock(BlockFields.SurfaceDescription.NormalTS); context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); - context.AddBlock(BlockFields.SurfaceDescription.Smoothness); - context.AddBlock(BlockFields.SurfaceDescription.Occlusion); context.AddBlock(BlockFields.SurfaceDescription.Specular); context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, lightingData.subsurfaceScattering || lightingData.transmission); context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, lightingData.subsurfaceScattering); context.AddBlock(HDBlockFields.SurfaceDescription.Thickness, lightingData.transmission); - context.AddBlock(BlockFields.SurfaceDescription.Emission); - context.AddBlock(BlockFields.SurfaceDescription.Alpha); - context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, systemData.alphaTest); - context.AddBlock(HDBlockFields.SurfaceDescription.BakedGI, lightingData.overrideBakedGI); - context.AddBlock(HDBlockFields.SurfaceDescription.BakedBackGI, lightingData.overrideBakedGI); - context.AddBlock(HDBlockFields.SurfaceDescription.DepthOffset, builtinData.depthOffset); // Fabric Silk if(fabricData.materialType == FabricData.MaterialType.Silk) @@ -169,118 +150,6 @@ public override void ProcessPreviewMaterial(Material material) FabricGUI.SetupMaterialKeywordsAndPass(material); } - public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) - { - blockMap = null; - if(!(masterNode is FabricMasterNode1 fabricMasterNode)) - return false; - - // Set data - systemData.surfaceType = (SurfaceType)fabricMasterNode.m_SurfaceType; - systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)fabricMasterNode.m_AlphaMode); - systemData.alphaTest = fabricMasterNode.m_AlphaTest; - systemData.sortPriority = fabricMasterNode.m_SortPriority; - systemData.doubleSidedMode = fabricMasterNode.m_DoubleSidedMode; - systemData.zWrite = fabricMasterNode.m_ZWrite; - systemData.transparentCullMode = fabricMasterNode.m_transparentCullMode; - systemData.zTest = fabricMasterNode.m_ZTest; - systemData.supportLodCrossFade = fabricMasterNode.m_SupportLodCrossFade; - systemData.dotsInstancing = fabricMasterNode.m_DOTSInstancing; - systemData.materialNeedsUpdateHash = fabricMasterNode.m_MaterialNeedsUpdateHash; - - builtinData.transparencyFog = fabricMasterNode.m_TransparencyFog; - builtinData.addPrecomputedVelocity = fabricMasterNode.m_AddPrecomputedVelocity; - builtinData.depthOffset = fabricMasterNode.m_depthOffset; - builtinData.alphaToMask = fabricMasterNode.m_AlphaToMask; - - lightingData.blendPreserveSpecular = fabricMasterNode.m_BlendPreserveSpecular; - lightingData.receiveDecals = fabricMasterNode.m_ReceiveDecals; - lightingData.receiveSSR = fabricMasterNode.m_ReceivesSSR; - lightingData.energyConservingSpecular = fabricMasterNode.m_EnergyConservingSpecular; - lightingData.specularOcclusionMode = fabricMasterNode.m_SpecularOcclusionMode; - lightingData.overrideBakedGI = fabricMasterNode.m_overrideBakedGI; - lightingData.transmission = fabricMasterNode.m_Transmission; - lightingData.subsurfaceScattering = fabricMasterNode.m_SubsurfaceScattering; - - fabricData.materialType = (FabricData.MaterialType)fabricMasterNode.m_MaterialType; - target.customEditorGUI = fabricMasterNode.m_OverrideEnabled ? fabricMasterNode.m_ShaderGUIOverride : ""; - - // Convert SlotMask to BlockMap entries - var blockMapLookup = new Dictionary() - { - { FabricMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position }, - { FabricMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal }, - { FabricMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent }, - { FabricMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor }, - { FabricMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion }, - { FabricMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS }, - { FabricMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal }, - { FabricMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness }, - { FabricMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion }, - { FabricMasterNode1.SlotMask.Specular, BlockFields.SurfaceDescription.Specular }, - { FabricMasterNode1.SlotMask.DiffusionProfile, HDBlockFields.SurfaceDescription.DiffusionProfileHash }, - { FabricMasterNode1.SlotMask.SubsurfaceMask, HDBlockFields.SurfaceDescription.SubsurfaceMask }, - { FabricMasterNode1.SlotMask.Thickness, HDBlockFields.SurfaceDescription.Thickness }, - { FabricMasterNode1.SlotMask.Tangent, HDBlockFields.SurfaceDescription.Tangent }, - { FabricMasterNode1.SlotMask.Anisotropy, HDBlockFields.SurfaceDescription.Anisotropy }, - { FabricMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission }, - { FabricMasterNode1.SlotMask.Alpha, BlockFields.SurfaceDescription.Alpha }, - { FabricMasterNode1.SlotMask.AlphaClipThreshold, BlockFields.SurfaceDescription.AlphaClipThreshold }, - }; - - // Legacy master node slots have additional slot conditions, test them here - bool AdditionalSlotMaskTests(FabricMasterNode1.SlotMask slotMask) - { - switch(slotMask) - { - case FabricMasterNode1.SlotMask.SpecularOcclusion: - return lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom; - case FabricMasterNode1.SlotMask.DiffusionProfile: - return lightingData.subsurfaceScattering || lightingData.transmission; - case FabricMasterNode1.SlotMask.SubsurfaceMask: - return lightingData.subsurfaceScattering; - case FabricMasterNode1.SlotMask.Thickness: - return lightingData.transmission; - case FabricMasterNode1.SlotMask.AlphaClipThreshold: - return systemData.alphaTest; - default: - return true; - } - } - - // Set blockmap - blockMap = new Dictionary(); - foreach(FabricMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(FabricMasterNode1.SlotMask))) - { - if(fabricMasterNode.MaterialTypeUsesSlotMask(slotMask)) - { - if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor)) - continue; - - if(!AdditionalSlotMaskTests(slotMask)) - continue; - - var slotId = Mathf.Log((int)slotMask, 2); - blockMap.Add(blockFieldDescriptor, (int)slotId); - } - } - - // Override Baked GI - if(lightingData.overrideBakedGI) - { - blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, FabricMasterNode1.LightingSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, FabricMasterNode1.BackLightingSlotId); - } - - // Depth Offset - if(builtinData.depthOffset) - { - blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, FabricMasterNode1.DepthOffsetSlotId); - } - - return true; - } - #region SubShaders static class SubShaders { diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs index 90f000415de..1f692d87d2a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs @@ -40,13 +40,13 @@ public void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChan systemData.alphaTest = evt.newValue; onChange(); }); - context.AddProperty("Use Shadow Threshold", 1, new Toggle() { value = lightingData.alphaTestShadow }, systemData.alphaTest, (evt) => + context.AddProperty("Use Shadow Threshold", 1, new Toggle() { value = builtinData.alphaTestShadow }, systemData.alphaTest, (evt) => { - if (Equals(lightingData.alphaTestShadow, evt.newValue)) + if (Equals(builtinData.alphaTestShadow, evt.newValue)) return; registerUndo("Use Shadow Threshold"); - lightingData.alphaTestShadow = evt.newValue; + builtinData.alphaTestShadow = evt.newValue; onChange(); }); context.AddProperty("Alpha to Mask", 1, new Toggle() { value = builtinData.alphaToMask }, systemData.alphaTest, (evt) => @@ -229,13 +229,13 @@ void DoRenderStateArea(ref TargetPropertyGUIContext context, SystemData systemDa }); - context.AddProperty("Back Then Front Rendering", indentLevel + 1, new Toggle() { value = lightingData.backThenFrontRendering }, systemData.surfaceType == SurfaceType.Transparent, (evt) => + context.AddProperty("Back Then Front Rendering", indentLevel + 1, new Toggle() { value = builtinData.backThenFrontRendering }, systemData.surfaceType == SurfaceType.Transparent, (evt) => { - if (Equals(lightingData.backThenFrontRendering, evt.newValue)) + if (Equals(builtinData.backThenFrontRendering, evt.newValue)) return; registerUndo("Back Then Front Rendering"); - lightingData.backThenFrontRendering = evt.newValue; + builtinData.backThenFrontRendering = evt.newValue; onChange(); }); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.Migration.cs new file mode 100644 index 00000000000..6fb353b4447 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.Migration.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEditor.ShaderGraph.Internal; +using UnityEditor.Graphing; +using UnityEditor.ShaderGraph.Legacy; +using UnityEditor.Rendering.HighDefinition.ShaderGraph.Legacy; +using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; +using static UnityEditor.Rendering.HighDefinition.HDShaderUtils; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + sealed partial class HairSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData + { + public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) + { + blockMap = null; + if(!(masterNode is HairMasterNode1 hairMasterNode)) + return false; + + // Set data + systemData.surfaceType = (SurfaceType)hairMasterNode.m_SurfaceType; + systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)hairMasterNode.m_AlphaMode); + systemData.alphaTest = hairMasterNode.m_AlphaTest; + systemData.alphaTestDepthPrepass = hairMasterNode.m_AlphaTestDepthPrepass; + systemData.alphaTestDepthPostpass = hairMasterNode.m_AlphaTestDepthPostpass; + systemData.sortPriority = hairMasterNode.m_SortPriority; + systemData.doubleSidedMode = hairMasterNode.m_DoubleSidedMode; + systemData.zWrite = hairMasterNode.m_ZWrite; + systemData.transparentCullMode = hairMasterNode.m_transparentCullMode; + systemData.zTest = hairMasterNode.m_ZTest; + systemData.supportLodCrossFade = hairMasterNode.m_SupportLodCrossFade; + systemData.dotsInstancing = hairMasterNode.m_DOTSInstancing; + systemData.materialNeedsUpdateHash = hairMasterNode.m_MaterialNeedsUpdateHash; + + builtinData.transparencyFog = hairMasterNode.m_TransparencyFog; + builtinData.transparentWritesMotionVec = hairMasterNode.m_TransparentWritesMotionVec; + builtinData.addPrecomputedVelocity = hairMasterNode.m_AddPrecomputedVelocity; + builtinData.depthOffset = hairMasterNode.m_depthOffset; + builtinData.alphaToMask = hairMasterNode.m_AlphaToMask; + + builtinData.alphaTestShadow = hairMasterNode.m_AlphaTestShadow; + builtinData.backThenFrontRendering = hairMasterNode.m_BackThenFrontRendering; + lightingData.blendPreserveSpecular = hairMasterNode.m_BlendPreserveSpecular; + lightingData.receiveDecals = hairMasterNode.m_ReceiveDecals; + lightingData.receiveSSR = hairMasterNode.m_ReceivesSSR; + lightingData.specularAA = hairMasterNode.m_SpecularAA; + lightingData.specularOcclusionMode = hairMasterNode.m_SpecularOcclusionMode; + lightingData.overrideBakedGI = hairMasterNode.m_overrideBakedGI; + + hairData.materialType = (HairData.MaterialType)hairMasterNode.m_MaterialType; + hairData.useLightFacingNormal = hairMasterNode.m_UseLightFacingNormal; + target.customEditorGUI = hairMasterNode.m_OverrideEnabled ? hairMasterNode.m_ShaderGUIOverride : ""; + + // Convert SlotMask to BlockMap entries + var blockMapLookup = new Dictionary() + { + { HairMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position }, + { HairMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal }, + { HairMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent }, + { HairMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor }, + { HairMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion }, + { HairMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS }, + { HairMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal }, + { HairMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness }, + { HairMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion }, + { HairMasterNode1.SlotMask.Transmittance, HDBlockFields.SurfaceDescription.Transmittance }, + { HairMasterNode1.SlotMask.RimTransmissionIntensity, HDBlockFields.SurfaceDescription.RimTransmissionIntensity }, + { HairMasterNode1.SlotMask.HairStrandDirection, HDBlockFields.SurfaceDescription.HairStrandDirection }, + { HairMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission }, + { HairMasterNode1.SlotMask.Alpha, BlockFields.SurfaceDescription.Alpha }, + { HairMasterNode1.SlotMask.AlphaClipThreshold, BlockFields.SurfaceDescription.AlphaClipThreshold }, + { HairMasterNode1.SlotMask.AlphaClipThresholdDepthPrepass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass }, + { HairMasterNode1.SlotMask.AlphaClipThresholdDepthPostpass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass }, + { HairMasterNode1.SlotMask.AlphaClipThresholdShadow, HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow }, + { HairMasterNode1.SlotMask.SpecularTint, HDBlockFields.SurfaceDescription.SpecularTint }, + { HairMasterNode1.SlotMask.SpecularShift, HDBlockFields.SurfaceDescription.SpecularShift }, + { HairMasterNode1.SlotMask.SecondarySpecularTint, HDBlockFields.SurfaceDescription.SecondarySpecularTint }, + { HairMasterNode1.SlotMask.SecondarySmoothness, HDBlockFields.SurfaceDescription.SecondarySmoothness }, + { HairMasterNode1.SlotMask.SecondarySpecularShift, HDBlockFields.SurfaceDescription.SecondarySpecularShift }, + }; + + // Legacy master node slots have additional slot conditions, test them here + bool AdditionalSlotMaskTests(HairMasterNode1.SlotMask slotMask) + { + switch(slotMask) + { + case HairMasterNode1.SlotMask.SpecularOcclusion: + return lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom; + case HairMasterNode1.SlotMask.AlphaClipThreshold: + return systemData.alphaTest; + case HairMasterNode1.SlotMask.AlphaClipThresholdDepthPrepass: + return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPrepass; + case HairMasterNode1.SlotMask.AlphaClipThresholdDepthPostpass: + return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPostpass; + case HairMasterNode1.SlotMask.AlphaClipThresholdShadow: + return systemData.alphaTest && builtinData.alphaTestShadow; + default: + return true; + } + } + + // Set blockmap + blockMap = new Dictionary(); + foreach(HairMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(HairMasterNode1.SlotMask))) + { + if(hairMasterNode.MaterialTypeUsesSlotMask(slotMask)) + { + if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor)) + continue; + + if(!AdditionalSlotMaskTests(slotMask)) + continue; + + var slotId = Mathf.Log((int)slotMask, 2); + blockMap.Add(blockFieldDescriptor, (int)slotId); + } + } + + // Specular AA + if(lightingData.specularAA) + { + blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, HairMasterNode1.SpecularAAScreenSpaceVarianceSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAThreshold, HairMasterNode1.SpecularAAThresholdSlotId); + } + + // Override Baked GI + if(lightingData.overrideBakedGI) + { + blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, HairMasterNode1.LightingSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, HairMasterNode1.BackLightingSlotId); + } + + // Depth Offset + if(builtinData.depthOffset) + { + blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, HairMasterNode1.DepthOffsetSlotId); + } + + return true; + } + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.Migration.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.Migration.cs.meta new file mode 100644 index 00000000000..5f7c9779bbd --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.Migration.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 50ca841de81d7c148973ed8862e90b2e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs index 539d4117328..f7a09d0e13e 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs @@ -13,7 +13,7 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { - sealed class HairSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData + sealed partial class HairSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData { static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Hair/ShaderGraph/HairPass.template"; protected override string customInspector => "Rendering.HighDefinition.HairGUI"; @@ -44,76 +44,46 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - base.GetFields(ref context); + AddSystemDataFields(ref context); + AddSpecularOcclusionFields(ref context); + AddLitMiscFields(ref context); + AddSurfaceMiscFields(ref context); - // Structs + // Hair specific properties: context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(HairSubTarget.HairPasses.MotionVectors)); - - // Material context.AddField(HDFields.KajiyaKay, hairData.materialType == HairData.MaterialType.KajiyaKay); + context.AddField(HDFields.HairStrandDirection, context.blocks.Contains(HDBlockFields.SurfaceDescription.HairStrandDirection) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.HairStrandDirection)); + context.AddField(HDFields.RimTransmissionIntensity, context.blocks.Contains(HDBlockFields.SurfaceDescription.RimTransmissionIntensity) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.RimTransmissionIntensity)); + context.AddField(HDFields.UseLightFacingNormal, hairData.useLightFacingNormal); + context.AddField(HDFields.Transmittance, context.blocks.Contains(HDBlockFields.SurfaceDescription.Transmittance) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.Transmittance)); - // Specular Occlusion - AddSpecularOcclusionFields(ref context); - - // AlphaTest - // We always generate the keyword ALPHATEST_ON - context.AddField(Fields.AlphaTest, systemData.alphaTest && (context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold) || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow) || - context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass) || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass))); // All the DoAlphaXXX field drive the generation of which code to use for alpha test in the template // Do alpha test only if we aren't using the TestShadow one context.AddField(HDFields.DoAlphaTest, systemData.alphaTest && (context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold) && - !(lightingData.alphaTestShadow && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow)))); - context.AddField(HDFields.DoAlphaTestPrepass, systemData.alphaTest && systemData.alphaTestDepthPrepass && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass)); - context.AddField(HDFields.DoAlphaTestPostpass, systemData.alphaTest && systemData.alphaTestDepthPostpass && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass)); + !(builtinData.alphaTestShadow && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow)))); // Misc - AddLitMiscFields(ref context); - AddSurfaceMiscFields(ref context); - context.AddField(HDFields.SpecularAA, lightingData.specularAA && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAThreshold) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance)); - context.AddField(HDFields.HairStrandDirection, context.blocks.Contains(HDBlockFields.SurfaceDescription.HairStrandDirection) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.HairStrandDirection)); - context.AddField(HDFields.Transmittance, context.blocks.Contains(HDBlockFields.SurfaceDescription.Transmittance) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.Transmittance)); - context.AddField(HDFields.RimTransmissionIntensity, context.blocks.Contains(HDBlockFields.SurfaceDescription.RimTransmissionIntensity) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.RimTransmissionIntensity)); - context.AddField(HDFields.UseLightFacingNormal, hairData.useLightFacingNormal); - context.AddField(HDFields.TransparentDepthPrePass, systemData.surfaceType != SurfaceType.Opaque && systemData.alphaTestDepthPrepass); - context.AddField(HDFields.TransparentDepthPostPass, systemData.surfaceType != SurfaceType.Opaque && systemData.alphaTestDepthPrepass); } public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - // Vertex - context.AddBlock(BlockFields.VertexDescription.Position); - context.AddBlock(BlockFields.VertexDescription.Normal); - context.AddBlock(BlockFields.VertexDescription.Tangent); - - // Hair - context.AddBlock(BlockFields.SurfaceDescription.BaseColor); - context.AddBlock(HDBlockFields.SurfaceDescription.SpecularOcclusion, lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom); + AddVertexBlocks(ref context); + AddSurfaceBlocks(ref context); + + // Hair specific blocks context.AddBlock(BlockFields.SurfaceDescription.NormalTS); context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); - context.AddBlock(BlockFields.SurfaceDescription.Smoothness); - context.AddBlock(BlockFields.SurfaceDescription.Occlusion); context.AddBlock(HDBlockFields.SurfaceDescription.Transmittance); context.AddBlock(HDBlockFields.SurfaceDescription.RimTransmissionIntensity); context.AddBlock(HDBlockFields.SurfaceDescription.HairStrandDirection); - context.AddBlock(BlockFields.SurfaceDescription.Emission); - context.AddBlock(BlockFields.SurfaceDescription.Alpha); - context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, systemData.alphaTest); - context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPrepass); - context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPostpass); - context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, systemData.alphaTest && lightingData.alphaTestShadow); - context.AddBlock(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, lightingData.specularAA); - context.AddBlock(HDBlockFields.SurfaceDescription.SpecularAAThreshold, lightingData.specularAA); context.AddBlock(HDBlockFields.SurfaceDescription.SpecularTint); context.AddBlock(HDBlockFields.SurfaceDescription.SpecularShift); context.AddBlock(HDBlockFields.SurfaceDescription.SecondarySpecularTint); context.AddBlock(HDBlockFields.SurfaceDescription.SecondarySmoothness); context.AddBlock(HDBlockFields.SurfaceDescription.SecondarySpecularShift); - context.AddBlock(HDBlockFields.SurfaceDescription.BakedGI, lightingData.overrideBakedGI); - context.AddBlock(HDBlockFields.SurfaceDescription.BakedBackGI, lightingData.overrideBakedGI); - context.AddBlock(HDBlockFields.SurfaceDescription.DepthOffset, builtinData.depthOffset); } public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) @@ -158,10 +128,10 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera systemData.zWrite, systemData.transparentCullMode, systemData.zTest, - lightingData.backThenFrontRendering, + builtinData.backThenFrontRendering, builtinData.transparencyFog ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, lightingData.alphaTestShadow); + HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, builtinData.alphaTestShadow); HDSubShaderUtilities.AddDoubleSidedProperty(collector, systemData.doubleSidedMode); } @@ -185,134 +155,6 @@ public override void ProcessPreviewMaterial(Material material) HairGUI.SetupMaterialKeywordsAndPass(material); } - public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) - { - blockMap = null; - if(!(masterNode is HairMasterNode1 hairMasterNode)) - return false; - - // Set data - systemData.surfaceType = (SurfaceType)hairMasterNode.m_SurfaceType; - systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)hairMasterNode.m_AlphaMode); - systemData.alphaTest = hairMasterNode.m_AlphaTest; - systemData.alphaTestDepthPrepass = hairMasterNode.m_AlphaTestDepthPrepass; - systemData.alphaTestDepthPostpass = hairMasterNode.m_AlphaTestDepthPostpass; - systemData.sortPriority = hairMasterNode.m_SortPriority; - systemData.doubleSidedMode = hairMasterNode.m_DoubleSidedMode; - systemData.zWrite = hairMasterNode.m_ZWrite; - systemData.transparentCullMode = hairMasterNode.m_transparentCullMode; - systemData.zTest = hairMasterNode.m_ZTest; - systemData.supportLodCrossFade = hairMasterNode.m_SupportLodCrossFade; - systemData.dotsInstancing = hairMasterNode.m_DOTSInstancing; - systemData.materialNeedsUpdateHash = hairMasterNode.m_MaterialNeedsUpdateHash; - - builtinData.transparencyFog = hairMasterNode.m_TransparencyFog; - builtinData.transparentWritesMotionVec = hairMasterNode.m_TransparentWritesMotionVec; - builtinData.addPrecomputedVelocity = hairMasterNode.m_AddPrecomputedVelocity; - builtinData.depthOffset = hairMasterNode.m_depthOffset; - builtinData.alphaToMask = hairMasterNode.m_AlphaToMask; - - lightingData.alphaTestShadow = hairMasterNode.m_AlphaTestShadow; - lightingData.backThenFrontRendering = hairMasterNode.m_BackThenFrontRendering; - lightingData.blendPreserveSpecular = hairMasterNode.m_BlendPreserveSpecular; - lightingData.receiveDecals = hairMasterNode.m_ReceiveDecals; - lightingData.receiveSSR = hairMasterNode.m_ReceivesSSR; - lightingData.specularAA = hairMasterNode.m_SpecularAA; - lightingData.specularOcclusionMode = hairMasterNode.m_SpecularOcclusionMode; - lightingData.overrideBakedGI = hairMasterNode.m_overrideBakedGI; - - hairData.materialType = (HairData.MaterialType)hairMasterNode.m_MaterialType; - hairData.useLightFacingNormal = hairMasterNode.m_UseLightFacingNormal; - target.customEditorGUI = hairMasterNode.m_OverrideEnabled ? hairMasterNode.m_ShaderGUIOverride : ""; - - // Convert SlotMask to BlockMap entries - var blockMapLookup = new Dictionary() - { - { HairMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position }, - { HairMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal }, - { HairMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent }, - { HairMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor }, - { HairMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion }, - { HairMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS }, - { HairMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal }, - { HairMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness }, - { HairMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion }, - { HairMasterNode1.SlotMask.Transmittance, HDBlockFields.SurfaceDescription.Transmittance }, - { HairMasterNode1.SlotMask.RimTransmissionIntensity, HDBlockFields.SurfaceDescription.RimTransmissionIntensity }, - { HairMasterNode1.SlotMask.HairStrandDirection, HDBlockFields.SurfaceDescription.HairStrandDirection }, - { HairMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission }, - { HairMasterNode1.SlotMask.Alpha, BlockFields.SurfaceDescription.Alpha }, - { HairMasterNode1.SlotMask.AlphaClipThreshold, BlockFields.SurfaceDescription.AlphaClipThreshold }, - { HairMasterNode1.SlotMask.AlphaClipThresholdDepthPrepass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass }, - { HairMasterNode1.SlotMask.AlphaClipThresholdDepthPostpass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass }, - { HairMasterNode1.SlotMask.AlphaClipThresholdShadow, HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow }, - { HairMasterNode1.SlotMask.SpecularTint, HDBlockFields.SurfaceDescription.SpecularTint }, - { HairMasterNode1.SlotMask.SpecularShift, HDBlockFields.SurfaceDescription.SpecularShift }, - { HairMasterNode1.SlotMask.SecondarySpecularTint, HDBlockFields.SurfaceDescription.SecondarySpecularTint }, - { HairMasterNode1.SlotMask.SecondarySmoothness, HDBlockFields.SurfaceDescription.SecondarySmoothness }, - { HairMasterNode1.SlotMask.SecondarySpecularShift, HDBlockFields.SurfaceDescription.SecondarySpecularShift }, - }; - - // Legacy master node slots have additional slot conditions, test them here - bool AdditionalSlotMaskTests(HairMasterNode1.SlotMask slotMask) - { - switch(slotMask) - { - case HairMasterNode1.SlotMask.SpecularOcclusion: - return lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom; - case HairMasterNode1.SlotMask.AlphaClipThreshold: - return systemData.alphaTest; - case HairMasterNode1.SlotMask.AlphaClipThresholdDepthPrepass: - return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPrepass; - case HairMasterNode1.SlotMask.AlphaClipThresholdDepthPostpass: - return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPostpass; - case HairMasterNode1.SlotMask.AlphaClipThresholdShadow: - return systemData.alphaTest && lightingData.alphaTestShadow; - default: - return true; - } - } - - // Set blockmap - blockMap = new Dictionary(); - foreach(HairMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(HairMasterNode1.SlotMask))) - { - if(hairMasterNode.MaterialTypeUsesSlotMask(slotMask)) - { - if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor)) - continue; - - if(!AdditionalSlotMaskTests(slotMask)) - continue; - - var slotId = Mathf.Log((int)slotMask, 2); - blockMap.Add(blockFieldDescriptor, (int)slotId); - } - } - - // Specular AA - if(lightingData.specularAA) - { - blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, HairMasterNode1.SpecularAAScreenSpaceVarianceSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAThreshold, HairMasterNode1.SpecularAAThresholdSlotId); - } - - // Override Baked GI - if(lightingData.overrideBakedGI) - { - blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, HairMasterNode1.LightingSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, HairMasterNode1.BackLightingSlotId); - } - - // Depth Offset - if(builtinData.depthOffset) - { - blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, HairMasterNode1.DepthOffsetSlotId); - } - - return true; - } - #region SubShaders static class SubShaders { 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 064035ef45a..d5774952c9a 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 @@ -32,16 +32,6 @@ public MaterialType materialType set => m_MaterialType = value; } - [SerializeField, Obsolete("Kept for data migration")] - bool m_DrawBeforeRefraction; - #pragma warning disable CS0618 // Type or member is obsolete - public bool drawBeforeRefraction - { - get => m_DrawBeforeRefraction; - set => m_DrawBeforeRefraction = value; - } - #pragma warning restore CS0618 // Type or member is obsolete - [SerializeField] ScreenSpaceRefraction.RefractionModel m_RefractionModel; public ScreenSpaceRefraction.RefractionModel refractionModel @@ -60,14 +50,6 @@ public bool sssTransmission set => m_SSSTransmission = value; } - [SerializeField] - bool m_ReceivesSSRTransparent = true; - public bool receiveSSRTransparent - { - get => m_ReceivesSSRTransparent; - set => m_ReceivesSSRTransparent = value; - } - // TODO: This seems to have been replaced by a Port? // [SerializeField] // int m_DiffusionProfile; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs index c8987aa2e4b..145694a50c5 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs @@ -63,13 +63,13 @@ public void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChan systemData.alphaTest = evt.newValue; onChange(); }); - context.AddProperty("Use Shadow Threshold", 1, new Toggle() { value = lightingData.alphaTestShadow }, systemData.alphaTest, (evt) => + context.AddProperty("Use Shadow Threshold", 1, new Toggle() { value = builtinData.alphaTestShadow }, systemData.alphaTest, (evt) => { - if (Equals(lightingData.alphaTestShadow, evt.newValue)) + if (Equals(builtinData.alphaTestShadow, evt.newValue)) return; registerUndo("Use Shadow Threshold"); - lightingData.alphaTestShadow = evt.newValue; + builtinData.alphaTestShadow = evt.newValue; onChange(); }); context.AddProperty("Alpha to Mask", 1, new Toggle() { value = builtinData.alphaToMask }, systemData.alphaTest, (evt) => @@ -305,13 +305,13 @@ void DoRenderStateArea(ref TargetPropertyGUIContext context, int indentLevel, Ac }); - context.AddProperty("Back Then Front Rendering", indentLevel + 1, new Toggle() { value = lightingData.backThenFrontRendering }, systemData.surfaceType == SurfaceType.Transparent, (evt) => + context.AddProperty("Back Then Front Rendering", indentLevel + 1, new Toggle() { value = builtinData.backThenFrontRendering }, systemData.surfaceType == SurfaceType.Transparent, (evt) => { - if (Equals(lightingData.backThenFrontRendering, evt.newValue)) + if (Equals(builtinData.backThenFrontRendering, evt.newValue)) return; registerUndo("Back Then Front Rendering"); - lightingData.backThenFrontRendering = evt.newValue; + builtinData.backThenFrontRendering = evt.newValue; onChange(); }); 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 new file mode 100644 index 00000000000..ff595097c48 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs @@ -0,0 +1,271 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEditor.ShaderGraph.Internal; +using UnityEditor.Graphing; +using UnityEditor.ShaderGraph.Legacy; +using UnityEditor.Rendering.HighDefinition.ShaderGraph.Legacy; +using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; +using static UnityEditor.Rendering.HighDefinition.HDShaderUtils; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + sealed partial class HDLitSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData + { + public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) + { + blockMap = null; + switch(masterNode) + { + case PBRMasterNode1 pbrMasterNode: + UpgradePBRMasterNode(pbrMasterNode, out blockMap); + return true; + case HDLitMasterNode1 hdLitMasterNode: + UpgradeHDLitMasterNode(hdLitMasterNode, out blockMap); + return true; + default: + return false; + } + } + + void UpgradePBRMasterNode(PBRMasterNode1 pbrMasterNode, out Dictionary blockMap) + { + // Set data + systemData.surfaceType = (SurfaceType)pbrMasterNode.m_SurfaceType; + systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)pbrMasterNode.m_AlphaMode); + systemData.doubleSidedMode = pbrMasterNode.m_TwoSided ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled; + systemData.alphaTest = HDSubShaderUtilities.UpgradeLegacyAlphaClip(pbrMasterNode); + systemData.dotsInstancing = pbrMasterNode.m_DOTSInstancing; + builtinData.addPrecomputedVelocity = false; + lightingData.normalDropOffSpace = pbrMasterNode.m_NormalDropOffSpace; + litData.materialType = pbrMasterNode.m_Model == PBRMasterNode1.Model.Specular ? HDLitData.MaterialType.SpecularColor : HDLitData.MaterialType.Standard; + target.customEditorGUI = pbrMasterNode.m_OverrideEnabled ? pbrMasterNode.m_ShaderGUIOverride : ""; + + // Handle mapping of Normal block specifically + BlockFieldDescriptor normalBlock; + switch(lightingData.normalDropOffSpace) + { + case NormalDropOffSpace.Object: + normalBlock = BlockFields.SurfaceDescription.NormalOS; + break; + case NormalDropOffSpace.World: + normalBlock = BlockFields.SurfaceDescription.NormalWS; + break; + default: + normalBlock = BlockFields.SurfaceDescription.NormalTS; + break; + } + + // PBRMasterNode adds/removes Metallic/Specular based on settings + BlockFieldDescriptor specularMetallicBlock; + int specularMetallicId; + if(litData.materialType == HDLitData.MaterialType.SpecularColor) + { + specularMetallicBlock = BlockFields.SurfaceDescription.Specular; + specularMetallicId = 3; + } + else + { + specularMetallicBlock = BlockFields.SurfaceDescription.Metallic; + specularMetallicId = 2; + } + + // Set blockmap + blockMap = new Dictionary() + { + { BlockFields.VertexDescription.Position, 9 }, + { BlockFields.VertexDescription.Normal, 10 }, + { BlockFields.VertexDescription.Tangent, 11 }, + { BlockFields.SurfaceDescription.BaseColor, 0 }, + { normalBlock, 1 }, + { specularMetallicBlock, specularMetallicId }, + { BlockFields.SurfaceDescription.Emission, 4 }, + { BlockFields.SurfaceDescription.Smoothness, 5 }, + { BlockFields.SurfaceDescription.Occlusion, 6 }, + { BlockFields.SurfaceDescription.Alpha, 7 }, + { BlockFields.SurfaceDescription.AlphaClipThreshold, 8 }, + }; + } + + void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary blockMap) + { + // Set data + systemData.surfaceType = (SurfaceType)hdLitMasterNode.m_SurfaceType; + systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)hdLitMasterNode.m_AlphaMode); + systemData.renderingPass = hdLitMasterNode.m_RenderingPass; + systemData.alphaTest = hdLitMasterNode.m_AlphaTest; + systemData.alphaTestDepthPrepass = hdLitMasterNode.m_AlphaTestDepthPrepass; + systemData.alphaTestDepthPostpass = hdLitMasterNode.m_AlphaTestDepthPostpass; + systemData.sortPriority = hdLitMasterNode.m_SortPriority; + systemData.doubleSidedMode = hdLitMasterNode.m_DoubleSidedMode; + systemData.zWrite = hdLitMasterNode.m_ZWrite; + systemData.transparentCullMode = hdLitMasterNode.m_transparentCullMode; + systemData.zTest = hdLitMasterNode.m_ZTest; + systemData.supportLodCrossFade = hdLitMasterNode.m_SupportLodCrossFade; + systemData.dotsInstancing = hdLitMasterNode.m_DOTSInstancing; + systemData.materialNeedsUpdateHash = hdLitMasterNode.m_MaterialNeedsUpdateHash; + + builtinData.transparencyFog = hdLitMasterNode.m_TransparencyFog; + builtinData.distortion = hdLitMasterNode.m_Distortion; + builtinData.distortionMode = hdLitMasterNode.m_DistortionMode; + builtinData.distortionDepthTest = hdLitMasterNode.m_DistortionDepthTest; + builtinData.transparentWritesMotionVec = hdLitMasterNode.m_TransparentWritesMotionVec; + builtinData.addPrecomputedVelocity = hdLitMasterNode.m_AddPrecomputedVelocity; + builtinData.depthOffset = hdLitMasterNode.m_depthOffset; + builtinData.alphaToMask = hdLitMasterNode.m_AlphaToMask; + + builtinData.alphaTestShadow = hdLitMasterNode.m_AlphaTestShadow; + builtinData.backThenFrontRendering = hdLitMasterNode.m_BackThenFrontRendering; + lightingData.normalDropOffSpace = hdLitMasterNode.m_NormalDropOffSpace; + lightingData.blendPreserveSpecular = hdLitMasterNode.m_BlendPreserveSpecular; + lightingData.receiveDecals = hdLitMasterNode.m_ReceiveDecals; + lightingData.receiveSSR = hdLitMasterNode.m_ReceivesSSR; + lightingData.energyConservingSpecular = hdLitMasterNode.m_EnergyConservingSpecular; + lightingData.specularAA = hdLitMasterNode.m_SpecularAA; + lightingData.specularOcclusionMode = hdLitMasterNode.m_SpecularOcclusionMode; + lightingData.overrideBakedGI = hdLitMasterNode.m_overrideBakedGI; + lightingData.receiveSSRTransparent = hdLitMasterNode.m_ReceivesSSRTransparent; + + litData.rayTracing = hdLitMasterNode.m_RayTracing; + litData.refractionModel = hdLitMasterNode.m_RefractionModel; + litData.materialType = (HDLitData.MaterialType)hdLitMasterNode.m_MaterialType; + litData.sssTransmission = hdLitMasterNode.m_SSSTransmission; + + target.customEditorGUI = hdLitMasterNode.m_OverrideEnabled ? hdLitMasterNode.m_ShaderGUIOverride : ""; + + // Handle mapping of Normal block specifically + BlockFieldDescriptor normalBlock; + switch(lightingData.normalDropOffSpace) + { + case NormalDropOffSpace.Object: + normalBlock = BlockFields.SurfaceDescription.NormalOS; + break; + case NormalDropOffSpace.World: + normalBlock = BlockFields.SurfaceDescription.NormalWS; + break; + default: + normalBlock = BlockFields.SurfaceDescription.NormalTS; + break; + } + + // Convert SlotMask to BlockMap entries + var blockMapLookup = new Dictionary() + { + { HDLitMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor }, + { HDLitMasterNode1.SlotMask.Normal, normalBlock }, + { HDLitMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal }, + { HDLitMasterNode1.SlotMask.Tangent, HDBlockFields.SurfaceDescription.Tangent }, + { HDLitMasterNode1.SlotMask.Anisotropy, HDBlockFields.SurfaceDescription.Anisotropy }, + { HDLitMasterNode1.SlotMask.SubsurfaceMask, HDBlockFields.SurfaceDescription.SubsurfaceMask }, + { HDLitMasterNode1.SlotMask.Thickness, HDBlockFields.SurfaceDescription.Thickness }, + { HDLitMasterNode1.SlotMask.DiffusionProfile, HDBlockFields.SurfaceDescription.DiffusionProfileHash }, + { HDLitMasterNode1.SlotMask.IridescenceMask, HDBlockFields.SurfaceDescription.IridescenceMask }, + { HDLitMasterNode1.SlotMask.IridescenceLayerThickness, HDBlockFields.SurfaceDescription.IridescenceThickness }, + { HDLitMasterNode1.SlotMask.Specular, BlockFields.SurfaceDescription.Specular }, + { HDLitMasterNode1.SlotMask.CoatMask, HDBlockFields.SurfaceDescription.CoatMask }, + { HDLitMasterNode1.SlotMask.Metallic, BlockFields.SurfaceDescription.Metallic }, + { HDLitMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness }, + { HDLitMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion }, + { HDLitMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion }, + { HDLitMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission }, + { HDLitMasterNode1.SlotMask.Alpha, BlockFields.SurfaceDescription.Alpha }, + { HDLitMasterNode1.SlotMask.AlphaThreshold, BlockFields.SurfaceDescription.AlphaClipThreshold }, + { HDLitMasterNode1.SlotMask.AlphaThresholdDepthPrepass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass }, + { HDLitMasterNode1.SlotMask.AlphaThresholdDepthPostpass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass }, + { HDLitMasterNode1.SlotMask.AlphaThresholdShadow, HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow }, + }; + + // Legacy master node slots have additional slot conditions, test them here + bool AdditionalSlotMaskTests(HDLitMasterNode1.SlotMask slotMask) + { + switch(slotMask) + { + case HDLitMasterNode1.SlotMask.Thickness: + return litData.sssTransmission || litData.materialType == HDLitData.MaterialType.Translucent; + case HDLitMasterNode1.SlotMask.SpecularOcclusion: + return lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom; + case HDLitMasterNode1.SlotMask.AlphaThreshold: + return systemData.alphaTest; + case HDLitMasterNode1.SlotMask.AlphaThresholdDepthPrepass: + return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPrepass; + case HDLitMasterNode1.SlotMask.AlphaThresholdDepthPostpass: + return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPostpass; + case HDLitMasterNode1.SlotMask.AlphaThresholdShadow: + return systemData.alphaTest && builtinData.alphaTestShadow; + default: + return true; + } + } + + // Set blockmap + blockMap = new Dictionary(); + + // First handle vertex blocks. We ran out of SlotMask bits for VertexNormal and VertexTangent + // so do all Vertex blocks here to maintain correct block order (Position is not in blockMapLookup) + blockMap.Add(BlockFields.VertexDescription.Position, HDLitMasterNode1.PositionSlotId); + blockMap.Add(BlockFields.VertexDescription.Normal, HDLitMasterNode1.VertexNormalSlotID); + blockMap.Add(BlockFields.VertexDescription.Tangent, HDLitMasterNode1.VertexTangentSlotID); + + // Now handle the SlotMask cases + foreach(HDLitMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(HDLitMasterNode1.SlotMask))) + { + if(hdLitMasterNode.MaterialTypeUsesSlotMask(slotMask)) + { + if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor)) + continue; + + if(!AdditionalSlotMaskTests(slotMask)) + continue; + + var slotId = Mathf.Log((int)slotMask, 2); + blockMap.Add(blockFieldDescriptor, (int)slotId); + } + } + + // Specular AA + if(lightingData.specularAA) + { + blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, HDLitMasterNode1.SpecularAAScreenSpaceVarianceSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAThreshold, HDLitMasterNode1.SpecularAAThresholdSlotId); + } + + // Refraction + bool hasRefraction = (systemData.surfaceType == SurfaceType.Transparent && systemData.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction && litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None); + if(hasRefraction) + { + if(!blockMap.TryGetValue(HDBlockFields.SurfaceDescription.Thickness, out _)) + { + blockMap.Add(HDBlockFields.SurfaceDescription.Thickness, HDLitMasterNode1.ThicknessSlotId); + } + + blockMap.Add(HDBlockFields.SurfaceDescription.RefractionIndex, HDLitMasterNode1.RefractionIndexSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.RefractionColor, HDLitMasterNode1.RefractionColorSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.RefractionDistance, HDLitMasterNode1.RefractionDistanceSlotId); + } + + // Distortion + bool hasDistortion = (systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); + if(hasDistortion) + { + blockMap.Add(HDBlockFields.SurfaceDescription.Distortion, HDLitMasterNode1.DistortionSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.DistortionBlur, HDLitMasterNode1.DistortionBlurSlotId); + } + + // Override Baked GI + if(lightingData.overrideBakedGI) + { + blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, HDLitMasterNode1.LightingSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, HDLitMasterNode1.BackLightingSlotId); + } + + // Depth Offset (Removed from SlotMask because of missing bits) + if(builtinData.depthOffset) + { + blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, HDLitMasterNode1.DepthOffsetSlotId); + } + } + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs.meta new file mode 100644 index 00000000000..075b8762b92 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0bb123874ee52c147a73bc9d779f600e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: 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 705eb1c7542..fac997d96a3 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 @@ -13,7 +13,7 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { - sealed class HDLitSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData + sealed partial class HDLitSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData { static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; @@ -22,36 +22,6 @@ sealed class HDLitSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData "Rendering.HighDefinition.HDLitGUI"; protected override string subTargetAssetGuid => "caab952c840878340810cca27417971c"; // HDLitSubTarget.cs protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; - protected override string renderQueue - { - get - { - if(systemData.renderingPass == HDRenderQueue.RenderQueueType.Unknown) - { - switch(systemData.surfaceType) - { - case SurfaceType.Opaque: - systemData.renderingPass = HDRenderQueue.RenderQueueType.Opaque; - break; - case SurfaceType.Transparent: - #pragma warning disable CS0618 // Type or member is obsolete - if (litData.drawBeforeRefraction) - { - litData.drawBeforeRefraction = false; - #pragma warning restore CS0618 // Type or member is obsolete - systemData.renderingPass = HDRenderQueue.RenderQueueType.PreRefraction; - } - else - { - systemData.renderingPass = HDRenderQueue.RenderQueueType.Transparent; - } - break; - } - } - int queue = HDRenderQueue.ChangeType(systemData.renderingPass, systemData.sortPriority, systemData.alphaTest); - return HDRenderQueue.GetShaderTagValue(queue); - } - } HDLitData m_LitData; @@ -76,15 +46,16 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - base.GetFields(ref context); - + AddSystemDataFields(ref context); AddDistortionFields(ref context); AddNormalDropOffFields(ref context); AddSpecularOcclusionFields(ref context); + AddSurfaceMiscFields(ref context); + AddLitMiscFields(ref context); bool hasRefraction = (systemData.surfaceType == SurfaceType.Transparent && systemData.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction && litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None); - // Structs + // Lit specific properties context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(HDLitSubTarget.LitPasses.MotionVectors)); context.AddField(HDFields.DotsProperties, context.hasDotsProperties); @@ -111,13 +82,10 @@ public override void GetFields(ref TargetFieldContext context) // All the DoAlphaXXX field drive the generation of which code to use for alpha test in the template // Do alpha test only if we aren't using the TestShadow one context.AddField(HDFields.DoAlphaTest, systemData.alphaTest && (context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold) && - !(lightingData.alphaTestShadow && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow)))); + !(builtinData.alphaTestShadow && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow)))); // Misc - AddSurfaceMiscFields(ref context); - AddLitMiscFields(ref context); - context.AddField(HDFields.DisableSSRTransparent, !litData.receiveSSRTransparent); context.AddField(HDFields.EnergyConservingSpecular, lightingData.energyConservingSpecular); context.AddField(HDFields.CoatMask, context.blocks.Contains(HDBlockFields.SurfaceDescription.CoatMask) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatMask)); context.AddField(HDFields.Tangent, context.blocks.Contains(HDBlockFields.SurfaceDescription.Tangent) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.Tangent)); @@ -130,47 +98,19 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) bool hasDistortion = (systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); // Vertex - context.AddBlock(BlockFields.VertexDescription.Position); - context.AddBlock(BlockFields.VertexDescription.Normal); - context.AddBlock(BlockFields.VertexDescription.Tangent); + AddVertexBlocks(ref context); + AddSurfaceBlocks(ref context); + AddDistortionBlocks(ref context); + AddNormalBlocks(ref context); // Common - context.AddBlock(BlockFields.SurfaceDescription.BaseColor); - context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); context.AddBlock(HDBlockFields.SurfaceDescription.CoatMask); - context.AddBlock(BlockFields.SurfaceDescription.Emission); - context.AddBlock(BlockFields.SurfaceDescription.Smoothness); - context.AddBlock(BlockFields.SurfaceDescription.Occlusion); - context.AddBlock(BlockFields.SurfaceDescription.Alpha); - - // Alpha Test - context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, systemData.alphaTest); - context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPrepass); - context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPostpass); - context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, systemData.alphaTest && lightingData.alphaTestShadow); - - // Specular AA - context.AddBlock(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, lightingData.specularAA); - context.AddBlock(HDBlockFields.SurfaceDescription.SpecularAAThreshold, lightingData.specularAA); // Refraction context.AddBlock(HDBlockFields.SurfaceDescription.RefractionIndex, hasRefraction); context.AddBlock(HDBlockFields.SurfaceDescription.RefractionColor, hasRefraction); context.AddBlock(HDBlockFields.SurfaceDescription.RefractionDistance, hasRefraction); - // Distortion - context.AddBlock(HDBlockFields.SurfaceDescription.Distortion, hasDistortion); - context.AddBlock(HDBlockFields.SurfaceDescription.DistortionBlur, hasDistortion); - - // Baked GI - context.AddBlock(HDBlockFields.SurfaceDescription.BakedGI, lightingData.overrideBakedGI); - context.AddBlock(HDBlockFields.SurfaceDescription.BakedBackGI, lightingData.overrideBakedGI); - - // Normal - context.AddBlock(BlockFields.SurfaceDescription.NormalOS, lightingData.normalDropOffSpace == NormalDropOffSpace.Object); - context.AddBlock(BlockFields.SurfaceDescription.NormalTS, lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent); - context.AddBlock(BlockFields.SurfaceDescription.NormalWS, lightingData.normalDropOffSpace == NormalDropOffSpace.World); - // Material context.AddBlock(HDBlockFields.SurfaceDescription.Tangent, litData.materialType == HDLitData.MaterialType.Anisotropy); context.AddBlock(HDBlockFields.SurfaceDescription.Anisotropy, litData.materialType == HDLitData.MaterialType.Anisotropy); @@ -184,10 +124,6 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(BlockFields.SurfaceDescription.Metallic, litData.materialType == HDLitData.MaterialType.Standard || litData.materialType == HDLitData.MaterialType.Anisotropy || litData.materialType == HDLitData.MaterialType.Iridescence); - - // Misc - context.AddBlock(HDBlockFields.SurfaceDescription.SpecularOcclusion, lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom); - context.AddBlock(HDBlockFields.SurfaceDescription.DepthOffset, builtinData.depthOffset); } public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) @@ -241,10 +177,10 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera systemData.zWrite, systemData.transparentCullMode, systemData.zTest, - lightingData.backThenFrontRendering, + builtinData.backThenFrontRendering, builtinData.transparencyFog ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, lightingData.alphaTestShadow); + HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, builtinData.alphaTestShadow); HDSubShaderUtilities.AddDoubleSidedProperty(collector, systemData.doubleSidedMode); HDSubShaderUtilities.AddRayTracingProperty(collector, litData.rayTracing); } @@ -269,266 +205,16 @@ public override void ProcessPreviewMaterial(Material material) protected override int ComputeMaterialNeedsUpdateHash() { + bool subsurfaceScattering = litData.materialType == HDLitData.MaterialType.SubsurfaceScattering; int hash = base.ComputeMaterialNeedsUpdateHash(); - // Be careful to not use a shift index used by the base function! - hash |= (litData.receiveSSRTransparent ? 0 : 1) << 4; - // TODO: should materialType also change lightingData.subsurfaceScattering ? - // If yes, we don't need this line - hash |= (litData.materialType == HDLitData.MaterialType.SubsurfaceScattering ? 0 : 1) << 5; - return hash; - } - - public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) - { - blockMap = null; - switch(masterNode) - { - case PBRMasterNode1 pbrMasterNode: - UpgradePBRMasterNode(pbrMasterNode, out blockMap); - return true; - case HDLitMasterNode1 hdLitMasterNode: - UpgradeHDLitMasterNode(hdLitMasterNode, out blockMap); - return true; - default: - return false; - } - } - - void UpgradePBRMasterNode(PBRMasterNode1 pbrMasterNode, out Dictionary blockMap) - { - // Set data - systemData.surfaceType = (SurfaceType)pbrMasterNode.m_SurfaceType; - systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)pbrMasterNode.m_AlphaMode); - systemData.doubleSidedMode = pbrMasterNode.m_TwoSided ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled; - systemData.alphaTest = HDSubShaderUtilities.UpgradeLegacyAlphaClip(pbrMasterNode); - systemData.dotsInstancing = pbrMasterNode.m_DOTSInstancing; - builtinData.addPrecomputedVelocity = false; - lightingData.normalDropOffSpace = pbrMasterNode.m_NormalDropOffSpace; - litData.materialType = pbrMasterNode.m_Model == PBRMasterNode1.Model.Specular ? HDLitData.MaterialType.SpecularColor : HDLitData.MaterialType.Standard; - target.customEditorGUI = pbrMasterNode.m_OverrideEnabled ? pbrMasterNode.m_ShaderGUIOverride : ""; - - // Handle mapping of Normal block specifically - BlockFieldDescriptor normalBlock; - switch(lightingData.normalDropOffSpace) - { - case NormalDropOffSpace.Object: - normalBlock = BlockFields.SurfaceDescription.NormalOS; - break; - case NormalDropOffSpace.World: - normalBlock = BlockFields.SurfaceDescription.NormalWS; - break; - default: - normalBlock = BlockFields.SurfaceDescription.NormalTS; - break; - } - - // PBRMasterNode adds/removes Metallic/Specular based on settings - BlockFieldDescriptor specularMetallicBlock; - int specularMetallicId; - if(litData.materialType == HDLitData.MaterialType.SpecularColor) - { - specularMetallicBlock = BlockFields.SurfaceDescription.Specular; - specularMetallicId = 3; - } - else - { - specularMetallicBlock = BlockFields.SurfaceDescription.Metallic; - specularMetallicId = 2; - } - - // Set blockmap - blockMap = new Dictionary() - { - { BlockFields.VertexDescription.Position, 9 }, - { BlockFields.VertexDescription.Normal, 10 }, - { BlockFields.VertexDescription.Tangent, 11 }, - { BlockFields.SurfaceDescription.BaseColor, 0 }, - { normalBlock, 1 }, - { specularMetallicBlock, specularMetallicId }, - { BlockFields.SurfaceDescription.Emission, 4 }, - { BlockFields.SurfaceDescription.Smoothness, 5 }, - { BlockFields.SurfaceDescription.Occlusion, 6 }, - { BlockFields.SurfaceDescription.Alpha, 7 }, - { BlockFields.SurfaceDescription.AlphaClipThreshold, 8 }, - }; - } - void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary blockMap) - { - // Set data - systemData.surfaceType = (SurfaceType)hdLitMasterNode.m_SurfaceType; - systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)hdLitMasterNode.m_AlphaMode); - systemData.renderingPass = hdLitMasterNode.m_RenderingPass; - systemData.alphaTest = hdLitMasterNode.m_AlphaTest; - systemData.alphaTestDepthPrepass = hdLitMasterNode.m_AlphaTestDepthPrepass; - systemData.alphaTestDepthPostpass = hdLitMasterNode.m_AlphaTestDepthPostpass; - systemData.sortPriority = hdLitMasterNode.m_SortPriority; - systemData.doubleSidedMode = hdLitMasterNode.m_DoubleSidedMode; - systemData.zWrite = hdLitMasterNode.m_ZWrite; - systemData.transparentCullMode = hdLitMasterNode.m_transparentCullMode; - systemData.zTest = hdLitMasterNode.m_ZTest; - systemData.supportLodCrossFade = hdLitMasterNode.m_SupportLodCrossFade; - systemData.dotsInstancing = hdLitMasterNode.m_DOTSInstancing; - systemData.materialNeedsUpdateHash = hdLitMasterNode.m_MaterialNeedsUpdateHash; - - builtinData.transparencyFog = hdLitMasterNode.m_TransparencyFog; - builtinData.distortion = hdLitMasterNode.m_Distortion; - builtinData.distortionMode = hdLitMasterNode.m_DistortionMode; - builtinData.distortionDepthTest = hdLitMasterNode.m_DistortionDepthTest; - builtinData.transparentWritesMotionVec = hdLitMasterNode.m_TransparentWritesMotionVec; - builtinData.addPrecomputedVelocity = hdLitMasterNode.m_AddPrecomputedVelocity; - builtinData.depthOffset = hdLitMasterNode.m_depthOffset; - builtinData.alphaToMask = hdLitMasterNode.m_AlphaToMask; - - lightingData.alphaTestShadow = hdLitMasterNode.m_AlphaTestShadow; - lightingData.backThenFrontRendering = hdLitMasterNode.m_BackThenFrontRendering; - lightingData.normalDropOffSpace = hdLitMasterNode.m_NormalDropOffSpace; - lightingData.blendPreserveSpecular = hdLitMasterNode.m_BlendPreserveSpecular; - lightingData.receiveDecals = hdLitMasterNode.m_ReceiveDecals; - lightingData.receiveSSR = hdLitMasterNode.m_ReceivesSSR; - lightingData.energyConservingSpecular = hdLitMasterNode.m_EnergyConservingSpecular; - lightingData.specularAA = hdLitMasterNode.m_SpecularAA; - lightingData.specularOcclusionMode = hdLitMasterNode.m_SpecularOcclusionMode; - lightingData.overrideBakedGI = hdLitMasterNode.m_overrideBakedGI; - - litData.rayTracing = hdLitMasterNode.m_RayTracing; - litData.refractionModel = hdLitMasterNode.m_RefractionModel; - litData.materialType = (HDLitData.MaterialType)hdLitMasterNode.m_MaterialType; - litData.sssTransmission = hdLitMasterNode.m_SSSTransmission; - litData.receiveSSRTransparent = hdLitMasterNode.m_ReceivesSSRTransparent; - - target.customEditorGUI = hdLitMasterNode.m_OverrideEnabled ? hdLitMasterNode.m_ShaderGUIOverride : ""; - - // Handle mapping of Normal block specifically - BlockFieldDescriptor normalBlock; - switch(lightingData.normalDropOffSpace) + unchecked { - case NormalDropOffSpace.Object: - normalBlock = BlockFields.SurfaceDescription.NormalOS; - break; - case NormalDropOffSpace.World: - normalBlock = BlockFields.SurfaceDescription.NormalWS; - break; - default: - normalBlock = BlockFields.SurfaceDescription.NormalTS; - break; + hash = hash * 23 + lightingData.receiveSSRTransparent.GetHashCode(); + hash = hash * 23 + subsurfaceScattering.GetHashCode(); } - // Convert SlotMask to BlockMap entries - var blockMapLookup = new Dictionary() - { - { HDLitMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor }, - { HDLitMasterNode1.SlotMask.Normal, normalBlock }, - { HDLitMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal }, - { HDLitMasterNode1.SlotMask.Tangent, HDBlockFields.SurfaceDescription.Tangent }, - { HDLitMasterNode1.SlotMask.Anisotropy, HDBlockFields.SurfaceDescription.Anisotropy }, - { HDLitMasterNode1.SlotMask.SubsurfaceMask, HDBlockFields.SurfaceDescription.SubsurfaceMask }, - { HDLitMasterNode1.SlotMask.Thickness, HDBlockFields.SurfaceDescription.Thickness }, - { HDLitMasterNode1.SlotMask.DiffusionProfile, HDBlockFields.SurfaceDescription.DiffusionProfileHash }, - { HDLitMasterNode1.SlotMask.IridescenceMask, HDBlockFields.SurfaceDescription.IridescenceMask }, - { HDLitMasterNode1.SlotMask.IridescenceLayerThickness, HDBlockFields.SurfaceDescription.IridescenceThickness }, - { HDLitMasterNode1.SlotMask.Specular, BlockFields.SurfaceDescription.Specular }, - { HDLitMasterNode1.SlotMask.CoatMask, HDBlockFields.SurfaceDescription.CoatMask }, - { HDLitMasterNode1.SlotMask.Metallic, BlockFields.SurfaceDescription.Metallic }, - { HDLitMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness }, - { HDLitMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion }, - { HDLitMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion }, - { HDLitMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission }, - { HDLitMasterNode1.SlotMask.Alpha, BlockFields.SurfaceDescription.Alpha }, - { HDLitMasterNode1.SlotMask.AlphaThreshold, BlockFields.SurfaceDescription.AlphaClipThreshold }, - { HDLitMasterNode1.SlotMask.AlphaThresholdDepthPrepass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass }, - { HDLitMasterNode1.SlotMask.AlphaThresholdDepthPostpass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass }, - { HDLitMasterNode1.SlotMask.AlphaThresholdShadow, HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow }, - }; - - // Legacy master node slots have additional slot conditions, test them here - bool AdditionalSlotMaskTests(HDLitMasterNode1.SlotMask slotMask) - { - switch(slotMask) - { - case HDLitMasterNode1.SlotMask.Thickness: - return litData.sssTransmission || litData.materialType == HDLitData.MaterialType.Translucent; - case HDLitMasterNode1.SlotMask.SpecularOcclusion: - return lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom; - case HDLitMasterNode1.SlotMask.AlphaThreshold: - return systemData.alphaTest; - case HDLitMasterNode1.SlotMask.AlphaThresholdDepthPrepass: - return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPrepass; - case HDLitMasterNode1.SlotMask.AlphaThresholdDepthPostpass: - return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPostpass; - case HDLitMasterNode1.SlotMask.AlphaThresholdShadow: - return systemData.alphaTest && lightingData.alphaTestShadow; - default: - return true; - } - } - - // Set blockmap - blockMap = new Dictionary(); - - // First handle vertex blocks. We ran out of SlotMask bits for VertexNormal and VertexTangent - // so do all Vertex blocks here to maintain correct block order (Position is not in blockMapLookup) - blockMap.Add(BlockFields.VertexDescription.Position, HDLitMasterNode1.PositionSlotId); - blockMap.Add(BlockFields.VertexDescription.Normal, HDLitMasterNode1.VertexNormalSlotID); - blockMap.Add(BlockFields.VertexDescription.Tangent, HDLitMasterNode1.VertexTangentSlotID); - - // Now handle the SlotMask cases - foreach(HDLitMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(HDLitMasterNode1.SlotMask))) - { - if(hdLitMasterNode.MaterialTypeUsesSlotMask(slotMask)) - { - if(!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor)) - continue; - - if(!AdditionalSlotMaskTests(slotMask)) - continue; - - var slotId = Mathf.Log((int)slotMask, 2); - blockMap.Add(blockFieldDescriptor, (int)slotId); - } - } - - // Specular AA - if(lightingData.specularAA) - { - blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, HDLitMasterNode1.SpecularAAScreenSpaceVarianceSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAThreshold, HDLitMasterNode1.SpecularAAThresholdSlotId); - } - - // Refraction - bool hasRefraction = (systemData.surfaceType == SurfaceType.Transparent && systemData.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction && litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None); - if(hasRefraction) - { - if(!blockMap.TryGetValue(HDBlockFields.SurfaceDescription.Thickness, out _)) - { - blockMap.Add(HDBlockFields.SurfaceDescription.Thickness, HDLitMasterNode1.ThicknessSlotId); - } - - blockMap.Add(HDBlockFields.SurfaceDescription.RefractionIndex, HDLitMasterNode1.RefractionIndexSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.RefractionColor, HDLitMasterNode1.RefractionColorSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.RefractionDistance, HDLitMasterNode1.RefractionDistanceSlotId); - } - - // Distortion - bool hasDistortion = (systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); - if(hasDistortion) - { - blockMap.Add(HDBlockFields.SurfaceDescription.Distortion, HDLitMasterNode1.DistortionSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.DistortionBlur, HDLitMasterNode1.DistortionBlurSlotId); - } - - // Override Baked GI - if(lightingData.overrideBakedGI) - { - blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, HDLitMasterNode1.LightingSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, HDLitMasterNode1.BackLightingSlotId); - } - - // Depth Offset (Removed from SlotMask because of missing bits) - if(builtinData.depthOffset) - { - blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, HDLitMasterNode1.DepthOffsetSlotId); - } + return hash; } #region SubShaders diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs index 5fb6abef6dd..7dbb8176dfe 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs @@ -35,7 +35,7 @@ public SystemData systemData protected virtual int ComputeMaterialNeedsUpdateHash() { // Alpha test is currently the only property in system data to trigger the material upgrade script. - int hash = (systemData.alphaTest ? 0 : 1) << 0; + int hash = systemData.alphaTest.GetHashCode(); return hash; } @@ -75,7 +75,7 @@ public sealed override void Setup(ref TargetSetupContext context) protected abstract IEnumerable EnumerateSubShaders(); // System data specific fields: - public override void GetFields(ref TargetFieldContext context) + protected void AddSystemDataFields(ref TargetFieldContext context) { // Features context.AddField(Fields.LodCrossFade, systemData.supportLodCrossFade); @@ -102,7 +102,6 @@ public override void GetFields(ref TargetFieldContext context) || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass) || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass))); - // TODO: we probably need to remove these for some master nodes (eye, stacklit, ) context.AddField(HDFields.DoAlphaTestPrepass, systemData.alphaTest && systemData.alphaTestDepthPrepass && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass)); context.AddField(HDFields.DoAlphaTestPostpass, systemData.alphaTest && systemData.alphaTestDepthPostpass diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs index 311d916f1aa..8182af733af 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs @@ -44,10 +44,15 @@ public LightingData lightingData protected override int ComputeMaterialNeedsUpdateHash() { int hash = base.ComputeMaterialNeedsUpdateHash(); - // Be careful to not use a shift index used by the base function! - hash |= (lightingData.alphaTestShadow ? 0 : 1) << 1; - hash |= (lightingData.receiveSSR ? 0 : 1) << 2; - hash |= (lightingData.subsurfaceScattering ? 0 : 1) << 3; + + unchecked + { + hash = hash * 23 + builtinData.alphaTestShadow.GetHashCode(); + hash = hash * 23 + lightingData.receiveSSR.GetHashCode(); + hash = hash * 23 + lightingData.receiveSSRTransparent.GetHashCode(); + hash = hash * 23 + lightingData.subsurfaceScattering.GetHashCode(); + } + return hash; } @@ -56,6 +61,7 @@ protected void AddLitMiscFields(ref TargetFieldContext context) context.AddField(HDFields.BlendPreserveSpecular, systemData.surfaceType != SurfaceType.Opaque && lightingData.blendPreserveSpecular); context.AddField(HDFields.DisableDecals, !lightingData.receiveDecals); context.AddField(HDFields.DisableSSR, !lightingData.receiveSSR); + context.AddField(HDFields.DisableSSRTransparent, !lightingData.receiveSSRTransparent); context.AddField(HDFields.SpecularAA, lightingData.specularAA && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAThreshold) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance)); @@ -64,8 +70,8 @@ protected void AddLitMiscFields(ref TargetFieldContext context) context.AddField(HDFields.LightingGI, context.blocks.Contains(HDBlockFields.SurfaceDescription.BakedGI) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.BakedGI)); context.AddField(HDFields.BackLightingGI, context.blocks.Contains(HDBlockFields.SurfaceDescription.BakedBackGI) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.BakedBackGI)); - context.AddField(HDFields.TransparentBackFace, systemData.surfaceType != SurfaceType.Opaque && lightingData.backThenFrontRendering); - context.AddField(HDFields.DoAlphaTestShadow, systemData.alphaTest && lightingData.alphaTestShadow && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow)); + context.AddField(HDFields.TransparentBackFace, systemData.surfaceType != SurfaceType.Opaque && builtinData.backThenFrontRendering); + context.AddField(HDFields.DoAlphaTestShadow, systemData.alphaTest && builtinData.alphaTestShadow && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow)); } protected void AddNormalDropOffFields(ref TargetFieldContext context) @@ -81,5 +87,30 @@ protected void AddSpecularOcclusionFields(ref TargetFieldContext context) context.AddField(HDFields.SpecularOcclusionFromAOBentNormal, lightingData.specularOcclusionMode == SpecularOcclusionMode.FromAOAndBentNormal); context.AddField(HDFields.SpecularOcclusionCustom, lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom); } + + protected void AddLightingBlocks(ref TargetActiveBlockContext context) + { + context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); + context.AddBlock(BlockFields.SurfaceDescription.Smoothness); + context.AddBlock(BlockFields.SurfaceDescription.Occlusion); + + // Specular AA + context.AddBlock(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, lightingData.specularAA); + context.AddBlock(HDBlockFields.SurfaceDescription.SpecularAAThreshold, lightingData.specularAA); + + // Baked GI + context.AddBlock(HDBlockFields.SurfaceDescription.BakedGI, lightingData.overrideBakedGI); + context.AddBlock(HDBlockFields.SurfaceDescription.BakedBackGI, lightingData.overrideBakedGI); + + // Misc + context.AddBlock(HDBlockFields.SurfaceDescription.SpecularOcclusion, lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom); + } + + protected void AddNormalBlocks(ref TargetActiveBlockContext context) + { + context.AddBlock(BlockFields.SurfaceDescription.NormalOS, lightingData.normalDropOffSpace == NormalDropOffSpace.Object); + context.AddBlock(BlockFields.SurfaceDescription.NormalTS, lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent); + context.AddBlock(BlockFields.SurfaceDescription.NormalWS, lightingData.normalDropOffSpace == NormalDropOffSpace.World); + } } } \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs index 01d71067f5b..d334a6266d1 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs @@ -45,7 +45,6 @@ protected void AddDistortionFields(ref TargetFieldContext context) context.AddField(HDFields.TransparentDistortion, systemData.surfaceType != SurfaceType.Opaque && builtinData.distortion); } - /// Add fields protected void AddSurfaceMiscFields(ref TargetFieldContext context) { context.AddField(Fields.AlphaToMask, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold) && builtinData.alphaToMask); @@ -54,5 +53,35 @@ protected void AddSurfaceMiscFields(ref TargetFieldContext context) context.AddField(HDFields.TransparentWritesMotionVec, systemData.surfaceType != SurfaceType.Opaque && builtinData.transparentWritesMotionVec); context.AddField(HDFields.DepthOffset, builtinData.depthOffset && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.DepthOffset)); } + + /// Add vertex inputs for standard surface shader + protected void AddVertexBlocks(ref TargetActiveBlockContext context) + { + context.AddBlock(BlockFields.VertexDescription.Position); + context.AddBlock(BlockFields.VertexDescription.Normal); + context.AddBlock(BlockFields.VertexDescription.Tangent); + } + + protected void AddDistortionBlocks(ref TargetActiveBlockContext context) + { + context.AddBlock(HDBlockFields.SurfaceDescription.Distortion, systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); + context.AddBlock(HDBlockFields.SurfaceDescription.DistortionBlur, systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); + } + + protected void AddSurfaceBlocks(ref TargetActiveBlockContext context) + { + context.AddBlock(BlockFields.SurfaceDescription.BaseColor); + context.AddBlock(BlockFields.SurfaceDescription.Emission); + context.AddBlock(BlockFields.SurfaceDescription.Alpha); + context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, systemData.alphaTest); + + // Alpha Test + context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPrepass); + context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPostpass); + context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, systemData.alphaTest && builtinData.alphaTestShadow); + + // Misc + context.AddBlock(HDBlockFields.SurfaceDescription.DepthOffset, builtinData.depthOffset); + } } } \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs new file mode 100644 index 00000000000..a65e2593509 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs @@ -0,0 +1,240 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEditor.ShaderGraph.Internal; +using UnityEditor.Graphing; +using UnityEditor.ShaderGraph.Legacy; +using UnityEditor.Rendering.HighDefinition.ShaderGraph.Legacy; +using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; +using static UnityEditor.Rendering.HighDefinition.HDShaderUtils; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + sealed partial class StackLitSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData + { + public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) + { + blockMap = null; + if(!(masterNode is StackLitMasterNode1 stackLitMasterNode)) + return false; + + // Set data + systemData.surfaceType = (SurfaceType)stackLitMasterNode.m_SurfaceType; + systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)stackLitMasterNode.m_AlphaMode); + systemData.alphaTest = stackLitMasterNode.m_AlphaTest; + systemData.sortPriority = stackLitMasterNode.m_SortPriority; + systemData.doubleSidedMode = stackLitMasterNode.m_DoubleSidedMode; + systemData.zWrite = stackLitMasterNode.m_ZWrite; + systemData.transparentCullMode = stackLitMasterNode.m_transparentCullMode; + systemData.zTest = stackLitMasterNode.m_ZTest; + systemData.supportLodCrossFade = stackLitMasterNode.m_SupportLodCrossFade; + systemData.dotsInstancing = stackLitMasterNode.m_DOTSInstancing; + systemData.materialNeedsUpdateHash = stackLitMasterNode.m_MaterialNeedsUpdateHash; + + builtinData.transparencyFog = stackLitMasterNode.m_TransparencyFog; + builtinData.distortion = stackLitMasterNode.m_Distortion; + builtinData.distortionMode = stackLitMasterNode.m_DistortionMode; + builtinData.distortionDepthTest = stackLitMasterNode.m_DistortionDepthTest; + builtinData.addPrecomputedVelocity = stackLitMasterNode.m_AddPrecomputedVelocity; + builtinData.depthOffset = stackLitMasterNode.m_depthOffset; + builtinData.alphaToMask = stackLitMasterNode.m_AlphaToMask; + + lightingData.normalDropOffSpace = stackLitMasterNode.m_NormalDropOffSpace; + lightingData.blendPreserveSpecular = stackLitMasterNode.m_BlendPreserveSpecular; + lightingData.receiveDecals = stackLitMasterNode.m_ReceiveDecals; + lightingData.receiveSSR = stackLitMasterNode.m_ReceiveSSR; + lightingData.energyConservingSpecular = stackLitMasterNode.m_EnergyConservingSpecular; + lightingData.subsurfaceScattering = stackLitMasterNode.m_SubsurfaceScattering; + lightingData.transmission = stackLitMasterNode.m_Transmission; + lightingData.overrideBakedGI = stackLitMasterNode.m_overrideBakedGI; + + stackLitData.baseParametrization = stackLitMasterNode.m_BaseParametrization; + stackLitData.dualSpecularLobeParametrization = stackLitMasterNode.m_DualSpecularLobeParametrization; + stackLitData.anisotropy = stackLitMasterNode.m_Anisotropy; + stackLitData.coat = stackLitMasterNode.m_Coat; + stackLitData.coatNormal = stackLitMasterNode.m_CoatNormal; + stackLitData.dualSpecularLobe = stackLitMasterNode.m_DualSpecularLobe; + stackLitData.capHazinessWrtMetallic = stackLitMasterNode.m_CapHazinessWrtMetallic; + stackLitData.iridescence = stackLitMasterNode.m_Iridescence; + stackLitData.geometricSpecularAA = stackLitMasterNode.m_GeometricSpecularAA; + stackLitData.screenSpaceSpecularOcclusionBaseMode = (StackLitData.SpecularOcclusionBaseMode)stackLitMasterNode.m_ScreenSpaceSpecularOcclusionBaseMode; + stackLitData.dataBasedSpecularOcclusionBaseMode = (StackLitData.SpecularOcclusionBaseMode)stackLitMasterNode.m_DataBasedSpecularOcclusionBaseMode; + stackLitData.screenSpaceSpecularOcclusionAOConeSize = (StackLitData.SpecularOcclusionAOConeSize)stackLitMasterNode.m_ScreenSpaceSpecularOcclusionAOConeSize; + stackLitData.screenSpaceSpecularOcclusionAOConeDir = (StackLitData.SpecularOcclusionAOConeDir)stackLitMasterNode.m_ScreenSpaceSpecularOcclusionAOConeDir; + stackLitData.dataBasedSpecularOcclusionAOConeSize = (StackLitData.SpecularOcclusionAOConeSize)stackLitMasterNode.m_DataBasedSpecularOcclusionAOConeSize; + stackLitData.specularOcclusionConeFixupMethod = (StackLitData.SpecularOcclusionConeFixupMethod)stackLitMasterNode.m_SpecularOcclusionConeFixupMethod; + stackLitData.anisotropyForAreaLights = stackLitMasterNode.m_AnisotropyForAreaLights; + stackLitData.recomputeStackPerLight = stackLitMasterNode.m_RecomputeStackPerLight; + stackLitData.honorPerLightMinRoughness = stackLitMasterNode.m_HonorPerLightMinRoughness; + stackLitData.shadeBaseUsingRefractedAngles = stackLitMasterNode.m_ShadeBaseUsingRefractedAngles; + stackLitData.debug = stackLitMasterNode.m_Debug; + stackLitData.devMode = stackLitMasterNode.m_DevMode; + + target.customEditorGUI = stackLitMasterNode.m_OverrideEnabled ? stackLitMasterNode.m_ShaderGUIOverride : ""; + + // Set blockmap + blockMap = new Dictionary(); + blockMap.Add(BlockFields.VertexDescription.Position, StackLitMasterNode1.PositionSlotId); + blockMap.Add(BlockFields.VertexDescription.Normal, StackLitMasterNode1.VertexNormalSlotId); + blockMap.Add(BlockFields.VertexDescription.Tangent, StackLitMasterNode1.VertexTangentSlotId); + + // Handle mapping of Normal block specifically + BlockFieldDescriptor normalBlock; + switch(lightingData.normalDropOffSpace) + { + case NormalDropOffSpace.Object: + normalBlock = BlockFields.SurfaceDescription.NormalOS; + break; + case NormalDropOffSpace.World: + normalBlock = BlockFields.SurfaceDescription.NormalWS; + break; + default: + normalBlock = BlockFields.SurfaceDescription.NormalTS; + break; + } + blockMap.Add(normalBlock, StackLitMasterNode1.NormalSlotId); + + blockMap.Add(HDBlockFields.SurfaceDescription.BentNormal, StackLitMasterNode1.BentNormalSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.Tangent, StackLitMasterNode1.TangentSlotId); + blockMap.Add(BlockFields.SurfaceDescription.BaseColor, StackLitMasterNode1.BaseColorSlotId); + + if (stackLitData.baseParametrization == StackLit.BaseParametrization.BaseMetallic) + { + blockMap.Add(BlockFields.SurfaceDescription.Metallic, StackLitMasterNode1.MetallicSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.DielectricIor, StackLitMasterNode1.DielectricIorSlotId); + } + else if (stackLitData.baseParametrization == StackLit.BaseParametrization.SpecularColor) + { + blockMap.Add(BlockFields.SurfaceDescription.Specular, StackLitMasterNode1.SpecularColorSlotId); + } + + blockMap.Add(BlockFields.SurfaceDescription.Smoothness, StackLitMasterNode1.SmoothnessASlotId); + + if (stackLitData.anisotropy) + { + blockMap.Add(HDBlockFields.SurfaceDescription.Anisotropy, StackLitMasterNode1.AnisotropyASlotId); + } + + blockMap.Add(BlockFields.SurfaceDescription.Occlusion, StackLitMasterNode1.AmbientOcclusionSlotId); + + if (stackLitData.dataBasedSpecularOcclusionBaseMode == StackLitData.SpecularOcclusionBaseMode.Custom) + { + blockMap.Add(HDBlockFields.SurfaceDescription.SpecularOcclusion, StackLitMasterNode1.SpecularOcclusionSlotId); + } + + if (SpecularOcclusionUsesBentNormal(stackLitData) && stackLitData.specularOcclusionConeFixupMethod != StackLitData.SpecularOcclusionConeFixupMethod.Off) + { + blockMap.Add(HDBlockFields.SurfaceDescription.SOFixupVisibilityRatioThreshold, StackLitMasterNode1.SOFixupVisibilityRatioThresholdSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.SOFixupStrengthFactor, StackLitMasterNode1.SOFixupStrengthFactorSlotId); + + if (SpecularOcclusionConeFixupMethodModifiesRoughness(stackLitData.specularOcclusionConeFixupMethod)) + { + blockMap.Add(HDBlockFields.SurfaceDescription.SOFixupMaxAddedRoughness, StackLitMasterNode1.SOFixupMaxAddedRoughnessSlotId); + } + } + + if (stackLitData.coat) + { + blockMap.Add(HDBlockFields.SurfaceDescription.CoatSmoothness, StackLitMasterNode1.CoatSmoothnessSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.CoatIor, StackLitMasterNode1.CoatIorSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.CoatThickness, StackLitMasterNode1.CoatThicknessSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.CoatExtinction, StackLitMasterNode1.CoatExtinctionSlotId); + + if (stackLitData.coatNormal) + { + blockMap.Add(HDBlockFields.SurfaceDescription.CoatNormal, StackLitMasterNode1.CoatNormalSlotId); + } + + blockMap.Add(HDBlockFields.SurfaceDescription.CoatMask, StackLitMasterNode1.CoatMaskSlotId); + } + + if (stackLitData.dualSpecularLobe) + { + if (stackLitData.dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.Direct) + { + blockMap.Add(HDBlockFields.SurfaceDescription.SmoothnessB, StackLitMasterNode1.SmoothnessBSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.LobeMix, StackLitMasterNode1.LobeMixSlotId); + } + else if (stackLitData.dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss) + { + blockMap.Add(HDBlockFields.SurfaceDescription.Haziness, StackLitMasterNode1.HazinessSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.HazeExtent, StackLitMasterNode1.HazeExtentSlotId); + + if (stackLitData.capHazinessWrtMetallic && stackLitData.baseParametrization == StackLit.BaseParametrization.BaseMetallic) // the later should be an assert really + { + blockMap.Add(HDBlockFields.SurfaceDescription.HazyGlossMaxDielectricF0, StackLitMasterNode1.HazyGlossMaxDielectricF0SlotId); + } + } + + if (stackLitData.anisotropy) + { + blockMap.Add(HDBlockFields.SurfaceDescription.AnisotropyB, StackLitMasterNode1.AnisotropyBSlotId); + } + } + + if (stackLitData.iridescence) + { + blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceMask, StackLitMasterNode1.IridescenceMaskSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceThickness, StackLitMasterNode1.IridescenceThicknessSlotId); + + if (stackLitData.coat) + { + blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIR, StackLitMasterNode1.IridescenceCoatFixupTIRSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIRClamp, StackLitMasterNode1.IridescenceCoatFixupTIRClampSlotId); + } + } + + if (lightingData.subsurfaceScattering) + { + blockMap.Add(HDBlockFields.SurfaceDescription.SubsurfaceMask, StackLitMasterNode1.SubsurfaceMaskSlotId); + } + + if (lightingData.transmission) + { + blockMap.Add(HDBlockFields.SurfaceDescription.Thickness, StackLitMasterNode1.ThicknessSlotId); + } + + if (lightingData.subsurfaceScattering || lightingData.transmission) + { + blockMap.Add(HDBlockFields.SurfaceDescription.DiffusionProfileHash, StackLitMasterNode1.DiffusionProfileHashSlotId); + } + + blockMap.Add(BlockFields.SurfaceDescription.Alpha, StackLitMasterNode1.AlphaSlotId); + + if (systemData.alphaTest) + { + blockMap.Add(BlockFields.SurfaceDescription.AlphaClipThreshold, StackLitMasterNode1.AlphaClipThresholdSlotId); + } + + blockMap.Add(BlockFields.SurfaceDescription.Emission, StackLitMasterNode1.EmissionSlotId); + + if (systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion) + { + blockMap.Add(HDBlockFields.SurfaceDescription.Distortion, StackLitMasterNode1.DistortionSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.DistortionBlur, StackLitMasterNode1.DistortionBlurSlotId); + } + + if (stackLitData.geometricSpecularAA) + { + blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, StackLitMasterNode1.SpecularAAScreenSpaceVarianceSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAThreshold, StackLitMasterNode1.SpecularAAThresholdSlotId); + } + + if (lightingData.overrideBakedGI) + { + blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, StackLitMasterNode1.LightingSlotId); + blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, StackLitMasterNode1.BackLightingSlotId); + } + + if (builtinData.depthOffset) + { + blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, StackLitMasterNode1.DepthOffsetSlotId); + } + + return true; + } + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs.meta new file mode 100644 index 00000000000..99f267d60c2 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fc78ab5e3cde02647aab936f10d6f44a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs index c29d683137b..42d03908cfe 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs @@ -16,7 +16,7 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph //TODO: // clamp in shader code the ranged() properties // or let inputs (eg mask?) follow invalid values ? Lit does that (let them free running). - sealed class StackLitSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData + sealed partial class StackLitSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData { const string kAssetGuid = "5f7ba34a143e67647b202a662748dae3"; static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/StackLit/ShaderGraph/StackLitPass.template"; @@ -158,9 +158,13 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - base.GetFields(ref context); + AddSystemDataFields(ref context); + AddNormalDropOffFields(ref context); + AddDistortionFields(ref context); + AddLitMiscFields(ref context); + AddSurfaceMiscFields(ref context); - // Structs + // StackLit specific properties context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(StackLitSubTarget.StackLitPasses.MotionVectors)); // Material @@ -178,12 +182,6 @@ public override void GetFields(ref TargetFieldContext context) context.AddField(HDFields.Transmission, lightingData.transmission); context.AddField(HDFields.DualSpecularLobe, stackLitData.dualSpecularLobe); - // Normal Drop Off Space - AddNormalDropOffFields(ref context); - - // Distortion - AddDistortionFields(ref context); - // Base Parametrization // Even though we can just always transfer the present (check with $SurfaceDescription.*) fields like specularcolor // and metallic, we still need to know the baseParametrization in the template to translate into the @@ -195,8 +193,6 @@ public override void GetFields(ref TargetFieldContext context) stackLitData.dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss); // Misc - AddLitMiscFields(ref context); - AddSurfaceMiscFields(ref context); context.AddField(HDFields.DoAlphaTest, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold)); context.AddField(HDFields.EnergyConservingSpecular, lightingData.energyConservingSpecular); context.AddField(HDFields.Tangent, context.blocks.Contains(HDBlockFields.SurfaceDescription.Tangent) && @@ -292,29 +288,20 @@ public override void GetFields(ref TargetFieldContext context) public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - // Vertex - context.AddBlock(BlockFields.VertexDescription.Position); - context.AddBlock(BlockFields.VertexDescription.Normal); - context.AddBlock(BlockFields.VertexDescription.Tangent); + AddVertexBlocks(ref context); + AddSurfaceBlocks(ref context); + AddNormalBlocks(ref context); + AddDistortionBlocks(ref context); // Common - context.AddBlock(BlockFields.SurfaceDescription.BaseColor); context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); context.AddBlock(HDBlockFields.SurfaceDescription.Tangent); context.AddBlock(BlockFields.SurfaceDescription.Smoothness); context.AddBlock(BlockFields.SurfaceDescription.Occlusion); - context.AddBlock(BlockFields.SurfaceDescription.Emission); context.AddBlock(HDBlockFields.SurfaceDescription.Anisotropy, stackLitData.anisotropy); context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, lightingData.subsurfaceScattering); context.AddBlock(HDBlockFields.SurfaceDescription.Thickness, lightingData.transmission); context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, lightingData.subsurfaceScattering || lightingData.transmission); - context.AddBlock(BlockFields.SurfaceDescription.Alpha); - context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, systemData.alphaTest); - - // Normal - context.AddBlock(BlockFields.SurfaceDescription.NormalOS, lightingData.normalDropOffSpace == NormalDropOffSpace.Object); - context.AddBlock(BlockFields.SurfaceDescription.NormalTS, lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent); - context.AddBlock(BlockFields.SurfaceDescription.NormalWS, lightingData.normalDropOffSpace == NormalDropOffSpace.World); // Base Metallic context.AddBlock(BlockFields.SurfaceDescription.Metallic, stackLitData.baseParametrization == StackLit.BaseParametrization.BaseMetallic); @@ -358,21 +345,9 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIR, stackLitData.iridescence && stackLitData.coat); context.AddBlock(HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIRClamp, stackLitData.iridescence && stackLitData.coat); - // Distortion - var hasDistortion = systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion; - context.AddBlock(HDBlockFields.SurfaceDescription.Distortion, hasDistortion); - context.AddBlock(HDBlockFields.SurfaceDescription.DistortionBlur, hasDistortion); - // Specular AA context.AddBlock(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, stackLitData.geometricSpecularAA); context.AddBlock(HDBlockFields.SurfaceDescription.SpecularAAThreshold, stackLitData.geometricSpecularAA); - - // Baked GI - context.AddBlock(HDBlockFields.SurfaceDescription.BakedGI, lightingData.overrideBakedGI); - context.AddBlock(HDBlockFields.SurfaceDescription.BakedBackGI, lightingData.overrideBakedGI); - - // Misc - context.AddBlock(HDBlockFields.SurfaceDescription.DepthOffset, builtinData.depthOffset); } public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) @@ -510,228 +485,6 @@ public static bool SpecularOcclusionConeFixupMethodModifiesRoughness(StackLitDat || soConeFixupMethod == StackLitData.SpecularOcclusionConeFixupMethod.BoostAndTilt); } - public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) - { - blockMap = null; - if(!(masterNode is StackLitMasterNode1 stackLitMasterNode)) - return false; - - // Set data - systemData.surfaceType = (SurfaceType)stackLitMasterNode.m_SurfaceType; - systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)stackLitMasterNode.m_AlphaMode); - systemData.alphaTest = stackLitMasterNode.m_AlphaTest; - systemData.sortPriority = stackLitMasterNode.m_SortPriority; - systemData.doubleSidedMode = stackLitMasterNode.m_DoubleSidedMode; - systemData.zWrite = stackLitMasterNode.m_ZWrite; - systemData.transparentCullMode = stackLitMasterNode.m_transparentCullMode; - systemData.zTest = stackLitMasterNode.m_ZTest; - systemData.supportLodCrossFade = stackLitMasterNode.m_SupportLodCrossFade; - systemData.dotsInstancing = stackLitMasterNode.m_DOTSInstancing; - systemData.materialNeedsUpdateHash = stackLitMasterNode.m_MaterialNeedsUpdateHash; - - builtinData.transparencyFog = stackLitMasterNode.m_TransparencyFog; - builtinData.distortion = stackLitMasterNode.m_Distortion; - builtinData.distortionMode = stackLitMasterNode.m_DistortionMode; - builtinData.distortionDepthTest = stackLitMasterNode.m_DistortionDepthTest; - builtinData.addPrecomputedVelocity = stackLitMasterNode.m_AddPrecomputedVelocity; - builtinData.depthOffset = stackLitMasterNode.m_depthOffset; - builtinData.alphaToMask = stackLitMasterNode.m_AlphaToMask; - - lightingData.normalDropOffSpace = stackLitMasterNode.m_NormalDropOffSpace; - lightingData.blendPreserveSpecular = stackLitMasterNode.m_BlendPreserveSpecular; - lightingData.receiveDecals = stackLitMasterNode.m_ReceiveDecals; - lightingData.receiveSSR = stackLitMasterNode.m_ReceiveSSR; - lightingData.energyConservingSpecular = stackLitMasterNode.m_EnergyConservingSpecular; - lightingData.subsurfaceScattering = stackLitMasterNode.m_SubsurfaceScattering; - lightingData.transmission = stackLitMasterNode.m_Transmission; - lightingData.overrideBakedGI = stackLitMasterNode.m_overrideBakedGI; - - stackLitData.baseParametrization = stackLitMasterNode.m_BaseParametrization; - stackLitData.dualSpecularLobeParametrization = stackLitMasterNode.m_DualSpecularLobeParametrization; - stackLitData.anisotropy = stackLitMasterNode.m_Anisotropy; - stackLitData.coat = stackLitMasterNode.m_Coat; - stackLitData.coatNormal = stackLitMasterNode.m_CoatNormal; - stackLitData.dualSpecularLobe = stackLitMasterNode.m_DualSpecularLobe; - stackLitData.capHazinessWrtMetallic = stackLitMasterNode.m_CapHazinessWrtMetallic; - stackLitData.iridescence = stackLitMasterNode.m_Iridescence; - stackLitData.geometricSpecularAA = stackLitMasterNode.m_GeometricSpecularAA; - stackLitData.screenSpaceSpecularOcclusionBaseMode = (StackLitData.SpecularOcclusionBaseMode)stackLitMasterNode.m_ScreenSpaceSpecularOcclusionBaseMode; - stackLitData.dataBasedSpecularOcclusionBaseMode = (StackLitData.SpecularOcclusionBaseMode)stackLitMasterNode.m_DataBasedSpecularOcclusionBaseMode; - stackLitData.screenSpaceSpecularOcclusionAOConeSize = (StackLitData.SpecularOcclusionAOConeSize)stackLitMasterNode.m_ScreenSpaceSpecularOcclusionAOConeSize; - stackLitData.screenSpaceSpecularOcclusionAOConeDir = (StackLitData.SpecularOcclusionAOConeDir)stackLitMasterNode.m_ScreenSpaceSpecularOcclusionAOConeDir; - stackLitData.dataBasedSpecularOcclusionAOConeSize = (StackLitData.SpecularOcclusionAOConeSize)stackLitMasterNode.m_DataBasedSpecularOcclusionAOConeSize; - stackLitData.specularOcclusionConeFixupMethod = (StackLitData.SpecularOcclusionConeFixupMethod)stackLitMasterNode.m_SpecularOcclusionConeFixupMethod; - stackLitData.anisotropyForAreaLights = stackLitMasterNode.m_AnisotropyForAreaLights; - stackLitData.recomputeStackPerLight = stackLitMasterNode.m_RecomputeStackPerLight; - stackLitData.honorPerLightMinRoughness = stackLitMasterNode.m_HonorPerLightMinRoughness; - stackLitData.shadeBaseUsingRefractedAngles = stackLitMasterNode.m_ShadeBaseUsingRefractedAngles; - stackLitData.debug = stackLitMasterNode.m_Debug; - stackLitData.devMode = stackLitMasterNode.m_DevMode; - - target.customEditorGUI = stackLitMasterNode.m_OverrideEnabled ? stackLitMasterNode.m_ShaderGUIOverride : ""; - - // Set blockmap - blockMap = new Dictionary(); - blockMap.Add(BlockFields.VertexDescription.Position, StackLitMasterNode1.PositionSlotId); - blockMap.Add(BlockFields.VertexDescription.Normal, StackLitMasterNode1.VertexNormalSlotId); - blockMap.Add(BlockFields.VertexDescription.Tangent, StackLitMasterNode1.VertexTangentSlotId); - - // Handle mapping of Normal block specifically - BlockFieldDescriptor normalBlock; - switch(lightingData.normalDropOffSpace) - { - case NormalDropOffSpace.Object: - normalBlock = BlockFields.SurfaceDescription.NormalOS; - break; - case NormalDropOffSpace.World: - normalBlock = BlockFields.SurfaceDescription.NormalWS; - break; - default: - normalBlock = BlockFields.SurfaceDescription.NormalTS; - break; - } - blockMap.Add(normalBlock, StackLitMasterNode1.NormalSlotId); - - blockMap.Add(HDBlockFields.SurfaceDescription.BentNormal, StackLitMasterNode1.BentNormalSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.Tangent, StackLitMasterNode1.TangentSlotId); - blockMap.Add(BlockFields.SurfaceDescription.BaseColor, StackLitMasterNode1.BaseColorSlotId); - - if (stackLitData.baseParametrization == StackLit.BaseParametrization.BaseMetallic) - { - blockMap.Add(BlockFields.SurfaceDescription.Metallic, StackLitMasterNode1.MetallicSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.DielectricIor, StackLitMasterNode1.DielectricIorSlotId); - } - else if (stackLitData.baseParametrization == StackLit.BaseParametrization.SpecularColor) - { - blockMap.Add(BlockFields.SurfaceDescription.Specular, StackLitMasterNode1.SpecularColorSlotId); - } - - blockMap.Add(BlockFields.SurfaceDescription.Smoothness, StackLitMasterNode1.SmoothnessASlotId); - - if (stackLitData.anisotropy) - { - blockMap.Add(HDBlockFields.SurfaceDescription.Anisotropy, StackLitMasterNode1.AnisotropyASlotId); - } - - blockMap.Add(BlockFields.SurfaceDescription.Occlusion, StackLitMasterNode1.AmbientOcclusionSlotId); - - if (stackLitData.dataBasedSpecularOcclusionBaseMode == StackLitData.SpecularOcclusionBaseMode.Custom) - { - blockMap.Add(HDBlockFields.SurfaceDescription.SpecularOcclusion, StackLitMasterNode1.SpecularOcclusionSlotId); - } - - if (SpecularOcclusionUsesBentNormal(stackLitData) && stackLitData.specularOcclusionConeFixupMethod != StackLitData.SpecularOcclusionConeFixupMethod.Off) - { - blockMap.Add(HDBlockFields.SurfaceDescription.SOFixupVisibilityRatioThreshold, StackLitMasterNode1.SOFixupVisibilityRatioThresholdSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.SOFixupStrengthFactor, StackLitMasterNode1.SOFixupStrengthFactorSlotId); - - if (SpecularOcclusionConeFixupMethodModifiesRoughness(stackLitData.specularOcclusionConeFixupMethod)) - { - blockMap.Add(HDBlockFields.SurfaceDescription.SOFixupMaxAddedRoughness, StackLitMasterNode1.SOFixupMaxAddedRoughnessSlotId); - } - } - - if (stackLitData.coat) - { - blockMap.Add(HDBlockFields.SurfaceDescription.CoatSmoothness, StackLitMasterNode1.CoatSmoothnessSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.CoatIor, StackLitMasterNode1.CoatIorSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.CoatThickness, StackLitMasterNode1.CoatThicknessSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.CoatExtinction, StackLitMasterNode1.CoatExtinctionSlotId); - - if (stackLitData.coatNormal) - { - blockMap.Add(HDBlockFields.SurfaceDescription.CoatNormal, StackLitMasterNode1.CoatNormalSlotId); - } - - blockMap.Add(HDBlockFields.SurfaceDescription.CoatMask, StackLitMasterNode1.CoatMaskSlotId); - } - - if (stackLitData.dualSpecularLobe) - { - if (stackLitData.dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.Direct) - { - blockMap.Add(HDBlockFields.SurfaceDescription.SmoothnessB, StackLitMasterNode1.SmoothnessBSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.LobeMix, StackLitMasterNode1.LobeMixSlotId); - } - else if (stackLitData.dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss) - { - blockMap.Add(HDBlockFields.SurfaceDescription.Haziness, StackLitMasterNode1.HazinessSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.HazeExtent, StackLitMasterNode1.HazeExtentSlotId); - - if (stackLitData.capHazinessWrtMetallic && stackLitData.baseParametrization == StackLit.BaseParametrization.BaseMetallic) // the later should be an assert really - { - blockMap.Add(HDBlockFields.SurfaceDescription.HazyGlossMaxDielectricF0, StackLitMasterNode1.HazyGlossMaxDielectricF0SlotId); - } - } - - if (stackLitData.anisotropy) - { - blockMap.Add(HDBlockFields.SurfaceDescription.AnisotropyB, StackLitMasterNode1.AnisotropyBSlotId); - } - } - - if (stackLitData.iridescence) - { - blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceMask, StackLitMasterNode1.IridescenceMaskSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceThickness, StackLitMasterNode1.IridescenceThicknessSlotId); - - if (stackLitData.coat) - { - blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIR, StackLitMasterNode1.IridescenceCoatFixupTIRSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIRClamp, StackLitMasterNode1.IridescenceCoatFixupTIRClampSlotId); - } - } - - if (lightingData.subsurfaceScattering) - { - blockMap.Add(HDBlockFields.SurfaceDescription.SubsurfaceMask, StackLitMasterNode1.SubsurfaceMaskSlotId); - } - - if (lightingData.transmission) - { - blockMap.Add(HDBlockFields.SurfaceDescription.Thickness, StackLitMasterNode1.ThicknessSlotId); - } - - if (lightingData.subsurfaceScattering || lightingData.transmission) - { - blockMap.Add(HDBlockFields.SurfaceDescription.DiffusionProfileHash, StackLitMasterNode1.DiffusionProfileHashSlotId); - } - - blockMap.Add(BlockFields.SurfaceDescription.Alpha, StackLitMasterNode1.AlphaSlotId); - - if (systemData.alphaTest) - { - blockMap.Add(BlockFields.SurfaceDescription.AlphaClipThreshold, StackLitMasterNode1.AlphaClipThresholdSlotId); - } - - blockMap.Add(BlockFields.SurfaceDescription.Emission, StackLitMasterNode1.EmissionSlotId); - - if (systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion) - { - blockMap.Add(HDBlockFields.SurfaceDescription.Distortion, StackLitMasterNode1.DistortionSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.DistortionBlur, StackLitMasterNode1.DistortionBlurSlotId); - } - - if (stackLitData.geometricSpecularAA) - { - blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, StackLitMasterNode1.SpecularAAScreenSpaceVarianceSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAThreshold, StackLitMasterNode1.SpecularAAThresholdSlotId); - } - - if (lightingData.overrideBakedGI) - { - blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, StackLitMasterNode1.LightingSlotId); - blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, StackLitMasterNode1.BackLightingSlotId); - } - - if (builtinData.depthOffset) - { - blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, StackLitMasterNode1.DepthOffsetSlotId); - } - - return true; - } - #region SubShaders static class SubShaders { diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs new file mode 100644 index 00000000000..a88c6f67f9e --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEditor.ShaderGraph.Internal; +using UnityEditor.Graphing; +using UnityEditor.ShaderGraph.Legacy; +using UnityEditor.Rendering.HighDefinition.ShaderGraph.Legacy; +using static UnityEngine.Rendering.HighDefinition.HDMaterialProperties; +using static UnityEditor.Rendering.HighDefinition.HDShaderUtils; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + sealed partial class HDUnlitSubTarget : SurfaceSubTarget, ILegacyTarget, IRequiresData + { + public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) + { + blockMap = null; + switch(masterNode) + { + case UnlitMasterNode1 unlitMasterNode: + UpgradeUnlitMasterNode(unlitMasterNode, out blockMap); + return true; + case HDUnlitMasterNode1 hdUnlitMasterNode: + UpgradeHDUnlitMasterNode(hdUnlitMasterNode, out blockMap); + return true; + default: + return false; + } + } + + void UpgradeUnlitMasterNode(UnlitMasterNode1 unlitMasterNode, out Dictionary blockMap) + { + // Set data + systemData.surfaceType = (SurfaceType)unlitMasterNode.m_SurfaceType; + systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)unlitMasterNode.m_AlphaMode); + systemData.doubleSidedMode = unlitMasterNode.m_TwoSided ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled; + systemData.alphaTest = HDSubShaderUtilities.UpgradeLegacyAlphaClip(unlitMasterNode); + systemData.dotsInstancing = unlitMasterNode.m_DOTSInstancing; + systemData.zWrite = false; + builtinData.addPrecomputedVelocity = unlitMasterNode.m_AddPrecomputedVelocity; + target.customEditorGUI = unlitMasterNode.m_OverrideEnabled ? unlitMasterNode.m_ShaderGUIOverride : ""; + + // Set blockmap + blockMap = new Dictionary() + { + { BlockFields.VertexDescription.Position, 9 }, + { BlockFields.VertexDescription.Normal, 10 }, + { BlockFields.VertexDescription.Tangent, 11 }, + { BlockFields.SurfaceDescription.BaseColor, 0 }, + { BlockFields.SurfaceDescription.Alpha, 7 }, + { BlockFields.SurfaceDescription.AlphaClipThreshold, 8 }, + }; + } + + void UpgradeHDUnlitMasterNode(HDUnlitMasterNode1 hdUnlitMasterNode, out Dictionary blockMap) + { + // Set data + systemData.surfaceType = (SurfaceType)hdUnlitMasterNode.m_SurfaceType; + systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)hdUnlitMasterNode.m_AlphaMode); + systemData.renderingPass = hdUnlitMasterNode.m_RenderingPass; + systemData.alphaTest = hdUnlitMasterNode.m_AlphaTest; + systemData.sortPriority = hdUnlitMasterNode.m_SortPriority; + systemData.doubleSidedMode = hdUnlitMasterNode.m_DoubleSided ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled; + systemData.zWrite = hdUnlitMasterNode.m_ZWrite; + systemData.transparentCullMode = hdUnlitMasterNode.m_transparentCullMode; + systemData.zTest = hdUnlitMasterNode.m_ZTest; + systemData.dotsInstancing = hdUnlitMasterNode.m_DOTSInstancing; + + builtinData.transparencyFog = hdUnlitMasterNode.m_TransparencyFog; + builtinData.distortion = hdUnlitMasterNode.m_Distortion; + builtinData.distortionMode = hdUnlitMasterNode.m_DistortionMode; + builtinData.distortionDepthTest = hdUnlitMasterNode.m_DistortionDepthTest; + builtinData.alphaToMask = hdUnlitMasterNode.m_AlphaToMask; + builtinData.addPrecomputedVelocity = hdUnlitMasterNode.m_AddPrecomputedVelocity; + + unlitData.enableShadowMatte = hdUnlitMasterNode.m_EnableShadowMatte; + target.customEditorGUI = hdUnlitMasterNode.m_OverrideEnabled ? hdUnlitMasterNode.m_ShaderGUIOverride : ""; + + // Set blockmap + blockMap = new Dictionary() + { + { BlockFields.VertexDescription.Position, 9 }, + { BlockFields.VertexDescription.Normal, 13 }, + { BlockFields.VertexDescription.Tangent, 14 }, + { BlockFields.SurfaceDescription.BaseColor, 0 }, + { BlockFields.SurfaceDescription.Alpha, 7 }, + { BlockFields.SurfaceDescription.AlphaClipThreshold, 8 }, + { BlockFields.SurfaceDescription.Emission, 12 }, + }; + + // Distortion + if(systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion) + { + blockMap.Add(HDBlockFields.SurfaceDescription.Distortion, 10); + blockMap.Add(HDBlockFields.SurfaceDescription.DistortionBlur, 11); + } + + // Shadow Matte + if(unlitData.enableShadowMatte) + { + blockMap.Add(HDBlockFields.SurfaceDescription.ShadowTint, 15); + } + } + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs.meta new file mode 100644 index 00000000000..bd0d178a115 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.Migration.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e482c35cd40244042ba665e0ec08a4b9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs index 2338f469989..48e3e508389 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs @@ -13,7 +13,7 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { - sealed class HDUnlitSubTarget : SurfaceSubTarget, ILegacyTarget, IRequiresData + sealed partial class HDUnlitSubTarget : SurfaceSubTarget, ILegacyTarget, IRequiresData { // Templates // TODO: Why do the raytracing passes use the template for the pipeline agnostic Unlit master node? @@ -49,34 +49,22 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - // Unlit - context.AddField(HDFields.EnableShadowMatte, unlitData.enableShadowMatte); - - // Alpha - context.AddField(Fields.AlphaTest, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold)); - context.AddField(HDFields.DoAlphaTest, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold)); - AddDistortionFields(ref context); AddSurfaceMiscFields(ref context); + + // Unlit specific properties + context.AddField(HDFields.EnableShadowMatte, unlitData.enableShadowMatte); + context.AddField(HDFields.DoAlphaTest, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold)); } public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - // Vertex - context.AddBlock(BlockFields.VertexDescription.Position); - context.AddBlock(BlockFields.VertexDescription.Normal); - context.AddBlock(BlockFields.VertexDescription.Tangent); - - // Unlit - context.AddBlock(BlockFields.SurfaceDescription.BaseColor); - context.AddBlock(BlockFields.SurfaceDescription.Emission); - context.AddBlock(BlockFields.SurfaceDescription.Alpha); - context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, systemData.alphaTest); - context.AddBlock(HDBlockFields.SurfaceDescription.ShadowTint, unlitData.enableShadowMatte); + AddVertexBlocks(ref context); + AddDistortionBlocks(ref context); + AddSurfaceBlocks(ref context); - // Distortion - context.AddBlock(HDBlockFields.SurfaceDescription.Distortion, systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); - context.AddBlock(HDBlockFields.SurfaceDescription.DistortionBlur, systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); + // Unlit specific blocks + context.AddBlock(HDBlockFields.SurfaceDescription.ShadowTint, unlitData.enableShadowMatte); } public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) @@ -168,96 +156,6 @@ public override void ProcessPreviewMaterial(Material material) HDUnlitGUI.SetupMaterialKeywordsAndPass(material); } - public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) - { - blockMap = null; - switch(masterNode) - { - case UnlitMasterNode1 unlitMasterNode: - UpgradeUnlitMasterNode(unlitMasterNode, out blockMap); - return true; - case HDUnlitMasterNode1 hdUnlitMasterNode: - UpgradeHDUnlitMasterNode(hdUnlitMasterNode, out blockMap); - return true; - default: - return false; - } - } - - void UpgradeUnlitMasterNode(UnlitMasterNode1 unlitMasterNode, out Dictionary blockMap) - { - // Set data - systemData.surfaceType = (SurfaceType)unlitMasterNode.m_SurfaceType; - systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)unlitMasterNode.m_AlphaMode); - systemData.doubleSidedMode = unlitMasterNode.m_TwoSided ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled; - systemData.alphaTest = HDSubShaderUtilities.UpgradeLegacyAlphaClip(unlitMasterNode); - systemData.dotsInstancing = unlitMasterNode.m_DOTSInstancing; - systemData.zWrite = false; - builtinData.addPrecomputedVelocity = unlitMasterNode.m_AddPrecomputedVelocity; - target.customEditorGUI = unlitMasterNode.m_OverrideEnabled ? unlitMasterNode.m_ShaderGUIOverride : ""; - - // Set blockmap - blockMap = new Dictionary() - { - { BlockFields.VertexDescription.Position, 9 }, - { BlockFields.VertexDescription.Normal, 10 }, - { BlockFields.VertexDescription.Tangent, 11 }, - { BlockFields.SurfaceDescription.BaseColor, 0 }, - { BlockFields.SurfaceDescription.Alpha, 7 }, - { BlockFields.SurfaceDescription.AlphaClipThreshold, 8 }, - }; - } - - void UpgradeHDUnlitMasterNode(HDUnlitMasterNode1 hdUnlitMasterNode, out Dictionary blockMap) - { - // Set data - systemData.surfaceType = (SurfaceType)hdUnlitMasterNode.m_SurfaceType; - systemData.blendMode = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)hdUnlitMasterNode.m_AlphaMode); - systemData.renderingPass = hdUnlitMasterNode.m_RenderingPass; - systemData.alphaTest = hdUnlitMasterNode.m_AlphaTest; - systemData.sortPriority = hdUnlitMasterNode.m_SortPriority; - systemData.doubleSidedMode = hdUnlitMasterNode.m_DoubleSided ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled; - systemData.zWrite = hdUnlitMasterNode.m_ZWrite; - systemData.transparentCullMode = hdUnlitMasterNode.m_transparentCullMode; - systemData.zTest = hdUnlitMasterNode.m_ZTest; - systemData.dotsInstancing = hdUnlitMasterNode.m_DOTSInstancing; - - builtinData.transparencyFog = hdUnlitMasterNode.m_TransparencyFog; - builtinData.distortion = hdUnlitMasterNode.m_Distortion; - builtinData.distortionMode = hdUnlitMasterNode.m_DistortionMode; - builtinData.distortionDepthTest = hdUnlitMasterNode.m_DistortionDepthTest; - builtinData.alphaToMask = hdUnlitMasterNode.m_AlphaToMask; - builtinData.addPrecomputedVelocity = hdUnlitMasterNode.m_AddPrecomputedVelocity; - - unlitData.enableShadowMatte = hdUnlitMasterNode.m_EnableShadowMatte; - target.customEditorGUI = hdUnlitMasterNode.m_OverrideEnabled ? hdUnlitMasterNode.m_ShaderGUIOverride : ""; - - // Set blockmap - blockMap = new Dictionary() - { - { BlockFields.VertexDescription.Position, 9 }, - { BlockFields.VertexDescription.Normal, 13 }, - { BlockFields.VertexDescription.Tangent, 14 }, - { BlockFields.SurfaceDescription.BaseColor, 0 }, - { BlockFields.SurfaceDescription.Alpha, 7 }, - { BlockFields.SurfaceDescription.AlphaClipThreshold, 8 }, - { BlockFields.SurfaceDescription.Emission, 12 }, - }; - - // Distortion - if(systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion) - { - blockMap.Add(HDBlockFields.SurfaceDescription.Distortion, 10); - blockMap.Add(HDBlockFields.SurfaceDescription.DistortionBlur, 11); - } - - // Shadow Matte - if(unlitData.enableShadowMatte) - { - blockMap.Add(HDBlockFields.SurfaceDescription.ShadowTint, 15); - } - } - #region SubShaders static class SubShaders { diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/BuiltinData.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/BuiltinData.cs index 6ed8ccd1f00..9631c205651 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/BuiltinData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/BuiltinData.cs @@ -69,5 +69,21 @@ public bool transparencyFog get => m_TransparencyFog; set => m_TransparencyFog = value; } + + [SerializeField] + bool m_AlphaTestShadow; + public bool alphaTestShadow + { + get => m_AlphaTestShadow; + set => m_AlphaTestShadow = value; + } + + [SerializeField] + bool m_BackThenFrontRendering; + public bool backThenFrontRendering + { + get => m_BackThenFrontRendering; + set => m_BackThenFrontRendering = value; + } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs index c0b3b8b2fca..1ba6b8061cf 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs @@ -104,21 +104,5 @@ public bool overrideBakedGI get => m_OverrideBakedGI; set => m_OverrideBakedGI = value; } - - [SerializeField] - bool m_AlphaTestShadow; - public bool alphaTestShadow - { - get => m_AlphaTestShadow; - set => m_AlphaTestShadow = value; - } - - [SerializeField] - bool m_BackThenFrontRendering; - public bool backThenFrontRendering - { - get => m_BackThenFrontRendering; - set => m_BackThenFrontRendering = value; - } } } From 64d35815d8c97ff2dc63ec36df6f86549a71e416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Tue, 26 May 2020 11:26:24 +0200 Subject: [PATCH 02/11] Made property row labels flexible --- com.unity.shadergraph/Editor/Resources/Styles/PropertyRow.uss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.shadergraph/Editor/Resources/Styles/PropertyRow.uss b/com.unity.shadergraph/Editor/Resources/Styles/PropertyRow.uss index 775aa955fff..40f0cff21d9 100644 --- a/com.unity.shadergraph/Editor/Resources/Styles/PropertyRow.uss +++ b/com.unity.shadergraph/Editor/Resources/Styles/PropertyRow.uss @@ -19,6 +19,8 @@ PropertyRow > #container{ } PropertyRow > #container > #label { + flex-grow: 5; + min-width: 92px; width: 92px; font-size: 12px; margin-right: 4px; From 021e99dfec962d7649b94841df0f0f77f3e85a13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Tue, 26 May 2020 11:36:05 +0200 Subject: [PATCH 03/11] Fixed indent level of propertyRow --- .../Contexts/TargetPropertyGUIContext.cs | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs b/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs index 1f64879804c..08f8465ca9a 100644 --- a/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs +++ b/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs @@ -10,6 +10,8 @@ namespace UnityEditor.ShaderGraph [GenerationAPI] internal class TargetPropertyGUIContext : VisualElement { + const int kIndentWidthInPixel = 20; + public TargetPropertyGUIContext() { @@ -43,29 +45,23 @@ public void AddProperty(string label, int indentLevel, BaseField field, Ev notifyValueChanged.RegisterValueChangedCallback(evt); } - string labelText = ""; - for (var i = 0; i < indentLevel; i++) - { - labelText += " "; - } - labelText += label; - var propertyRow = new PropertyRow(new Label(labelText)); + var propertyRow = new PropertyRow(new Label(label)); + ApplyPadding(propertyRow, indentLevel); propertyRow.Add(field); this.hierarchy.Add(propertyRow); } public void AddLabel(string label, int indentLevel) { - string labelText = ""; - for (var i = 0; i < indentLevel; i++) - { - labelText += " "; - } - labelText += label; - - var propertyRow = new PropertyRow(new Label(labelText)); + var propertyRow = new PropertyRow(new Label(label)); + ApplyPadding(propertyRow, indentLevel); this.hierarchy.Add(propertyRow); } + + void ApplyPadding(VisualElement element, int indentLevel) + { + element.style.paddingLeft = indentLevel * kIndentWidthInPixel; + } } } From f3cf3d58263028c9493fa873f17e3e469a6aa46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Tue, 26 May 2020 14:53:32 +0200 Subject: [PATCH 04/11] Added more control to indent level and clear foldout --- .../PropertyDrawers/GraphDataPropertyDrawer.cs | 1 + .../Generation/Contexts/TargetPropertyGUIContext.cs | 6 ++++-- .../Editor/Resources/Styles/InspectorView.uss | 11 ++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/GraphDataPropertyDrawer.cs b/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/GraphDataPropertyDrawer.cs index 021c587f054..64eabe68e85 100644 --- a/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/GraphDataPropertyDrawer.cs +++ b/com.unity.shadergraph/Editor/Drawing/Inspector/PropertyDrawers/GraphDataPropertyDrawer.cs @@ -96,6 +96,7 @@ void RegisterActionToUndo(string actionName) // Create foldout var foldout = new Foldout() { text = targetName, value = foldoutActive, name = "foldout" }; element.Add(foldout); + foldout.AddToClassList("MainFoldout"); foldout.RegisterValueChangedCallback(evt => { // Update foldout value and rebuild diff --git a/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs b/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs index 08f8465ca9a..120f0de6227 100644 --- a/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs +++ b/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs @@ -10,7 +10,9 @@ namespace UnityEditor.ShaderGraph [GenerationAPI] internal class TargetPropertyGUIContext : VisualElement { - const int kIndentWidthInPixel = 20; + const int kIndentWidthInPixel = 15; + + public int globalIndentLevel {get; set;} = 0; public TargetPropertyGUIContext() { @@ -61,7 +63,7 @@ public void AddLabel(string label, int indentLevel) void ApplyPadding(VisualElement element, int indentLevel) { - element.style.paddingLeft = indentLevel * kIndentWidthInPixel; + element.style.paddingLeft = (globalIndentLevel + indentLevel) * kIndentWidthInPixel; } } } diff --git a/com.unity.shadergraph/Editor/Resources/Styles/InspectorView.uss b/com.unity.shadergraph/Editor/Resources/Styles/InspectorView.uss index ccd6137f8c3..5aa67a04bce 100644 --- a/com.unity.shadergraph/Editor/Resources/Styles/InspectorView.uss +++ b/com.unity.shadergraph/Editor/Resources/Styles/InspectorView.uss @@ -1,8 +1,3 @@ -.unity-label { - padding: 5px 2px 2px; - margin: 2px 4px; -} - .InspectorView { position:absolute; justify-content: flex-start; @@ -65,3 +60,9 @@ font-size: 11px; color: #606060; } + +.MainFoldout { + background-color: #383838; + border-color: #1F1F1F; + border-top-width: 1px; +} \ No newline at end of file From 2d9adfd70c8d8107de79b3c31b9ba170309097ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Tue, 26 May 2020 17:39:20 +0200 Subject: [PATCH 05/11] Refactored inspector GUI for HD lit and hair master node --- .../Decal/ShaderGraph/DecalSubTarget.cs | 5 +- .../Material/Eye/ShaderGraph/EyeSubTarget.cs | 57 +-- .../Fabric/ShaderGraph/FabricSubTarget.cs | 56 +-- .../HairAdvancedOptionsPropertyBlock.cs | 35 ++ .../HairAdvancedOptionsPropertyBlock.cs.meta} | 2 +- .../Hair/ShaderGraph/HairSettingsView.cs | 273 ------------- .../Hair/ShaderGraph/HairSubTarget.cs | 61 +-- .../Lit/ShaderGraph/HDLitSettingsView.cs | 382 ------------------ .../Lit/ShaderGraph/HDLitSubTarget.cs | 70 +--- .../Lit/ShaderGraph/LitPropertyBlock.cs | 32 ++ .../ShaderGraph/LitPropertyBlock.cs.meta} | 2 +- .../LitSurfaceOptionPropertyBlock.cs | 40 ++ ... => LitSurfaceOptionPropertyBlock.cs.meta} | 2 +- .../AdvancedOptionsPropertyBlock.cs | 34 ++ .../AdvancedOptionsPropertyBlock.cs.meta | 11 + .../ShaderGraph/DistortionPropertyBlock.cs | 27 ++ .../DistortionPropertyBlock.cs.meta | 11 + ...PropertiesGUI.cs => HDPropertiesHeader.cs} | 10 +- .../ShaderGraph/HDPropertiesHeader.cs.meta | 11 + .../Material/ShaderGraph/HDSubTarget.cs | 39 +- .../Material/ShaderGraph/LightingSubTarget.cs | 45 ++- .../ShaderGraph/SubTargetPropertiesGUI.cs | 40 ++ ...cs.meta => SubTargetPropertiesGUI.cs.meta} | 0 .../ShaderGraph/SubTargetPropertyBlock.cs | 138 +++++++ .../SubTargetPropertyBlock.cs.meta | 11 + .../ShaderGraph/SurfaceOptionPropertiesGUI.cs | 54 --- .../ShaderGraph/SurfaceOptionPropertyBlock.cs | 97 +++++ .../SurfaceOptionPropertyBlock.cs.meta | 11 + .../Material/ShaderGraph/SurfaceSubTarget.cs | 123 +++++- .../StackLit/ShaderGraph/StackLitSubTarget.cs | 56 +-- .../Material/UIBlocks/DistortionUIBlock.cs | 2 +- .../Material/UIBlocks/RefractionUIBlock.cs | 2 +- .../Material/UIBlocks/SurfaceOptionUIBlock.cs | 6 +- .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 61 +-- .../Editor/ShaderGraph/HDTarget.cs | 6 +- .../ShaderGraph/TargetData/LightingData.cs | 8 + .../ShaderGraph/TargetData/SystemData.cs | 2 + 37 files changed, 710 insertions(+), 1112 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairAdvancedOptionsPropertyBlock.cs rename com.unity.render-pipelines.high-definition/Editor/Material/{ShaderGraph/SurfaceOptionPropertiesGUI.cs.meta => Hair/ShaderGraph/HairAdvancedOptionsPropertyBlock.cs.meta} (83%) delete mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs delete mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs rename com.unity.render-pipelines.high-definition/Editor/Material/{Hair/ShaderGraph/HairSettingsView.cs.meta => Lit/ShaderGraph/LitPropertyBlock.cs.meta} (83%) create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs rename com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/{HDLitSettingsView.cs.meta => LitSurfaceOptionPropertyBlock.cs.meta} (83%) create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs.meta create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DistortionPropertyBlock.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DistortionPropertyBlock.cs.meta rename com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/{TargetDataPropertiesGUI.cs => HDPropertiesHeader.cs} (57%) create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDPropertiesHeader.cs.meta create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertiesGUI.cs rename com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/{TargetDataPropertiesGUI.cs.meta => SubTargetPropertiesGUI.cs.meta} (100%) create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs.meta delete mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertiesGUI.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs.meta diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs index d10fe5c1170..544ff783a03 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs @@ -79,10 +79,9 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(BlockFields.SurfaceDescription.Emission); } - public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) + protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { - // SystemDataPropertiesGUI.AddProperties(ref context, onChange, registerUndo); - // DecalDataPropertiesGUI. + // blockList.AddPropertyBlock(new DecalPropertyBlock()); } protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs index 3e447273d1b..7dfe2973b1a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs @@ -43,10 +43,7 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - AddSystemDataFields(ref context); - AddSpecularOcclusionFields(ref context); - AddLitMiscFields(ref context); - AddSurfaceMiscFields(ref context); + base.GetFields(ref context); // Eye specific properties context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(EyeSubTarget.EyePasses.MotionVectors)); @@ -58,8 +55,7 @@ public override void GetFields(ref TargetFieldContext context) public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - AddVertexBlocks(ref context); - AddSurfaceBlocks(ref context); + base.GetActiveBlocks(ref context); // Eye specific blocks context.AddBlock(BlockFields.SurfaceDescription.NormalTS); @@ -71,54 +67,9 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, lightingData.subsurfaceScattering); } - public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) + protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { - // TODO: refactor this - var settingsView = new EyeSettingsView(this); - settingsView.GetPropertiesGUI(ref context, onChange, registerUndo); - } - - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) - { - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (builtinData.addPrecomputedVelocity) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } - - // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, lightingData.subsurfaceScattering, lightingData.receiveSSR); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - systemData.surfaceType, - systemData.blendMode, - systemData.sortPriority, - builtinData.alphaToMask, - systemData.zWrite, - systemData.transparentCullMode, - systemData.zTest, - false, - builtinData.transparencyFog - ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, false); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, systemData.doubleSidedMode); + // blockList.AddPropertyBlock(new DecalPropertyBlock()); } public override void ProcessPreviewMaterial(Material material) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs index c8550e44d1b..7e6c273fcef 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs @@ -45,10 +45,7 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - AddSystemDataFields(ref context); - AddSpecularOcclusionFields(ref context); - AddLitMiscFields(ref context); - AddSurfaceMiscFields(ref context); + base.GetFields(ref context); // Fabric specific properties context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(FabricSubTarget.FabricPasses.MotionVectors)); @@ -62,8 +59,7 @@ public override void GetFields(ref TargetFieldContext context) public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - AddVertexBlocks(ref context); - AddSurfaceBlocks(ref context); + base.GetActiveBlocks(ref context); // Fabric specific blocks context.AddBlock(BlockFields.SurfaceDescription.NormalTS); @@ -81,53 +77,9 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) } } - public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) + protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { - var settingsView = new FabricSettingsView(this); - settingsView.GetPropertiesGUI(ref context, onChange, registerUndo); - } - - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) - { - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (builtinData.addPrecomputedVelocity) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } - - // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, lightingData.subsurfaceScattering, lightingData.receiveSSR); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - systemData.surfaceType, - systemData.blendMode, - systemData.sortPriority, - builtinData.alphaToMask, - systemData.zWrite, - systemData.transparentCullMode, - systemData.zTest, - false, - builtinData.transparencyFog - ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, false); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, systemData.doubleSidedMode); + // blockList.AddPropertyBlock(new DecalPropertyBlock()); } public override void ProcessPreviewMaterial(Material material) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairAdvancedOptionsPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairAdvancedOptionsPropertyBlock.cs new file mode 100644 index 00000000000..126c5e7bcc0 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairAdvancedOptionsPropertyBlock.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine; + +// We share the name of the properties in the UI to avoid duplication +using static UnityEditor.Rendering.HighDefinition.AdvancedOptionsUIBlock.Styles; +using static UnityEditor.Rendering.HighDefinition.SurfaceOptionUIBlock.Styles; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + class HairAdvancedOptionsPropertyBlock : AdvancedOptionsPropertyBlock + { + class Styles + { + public static GUIContent useLightFacingNormal = new GUIContent("Use Light Facing Normal", "TODO"); + } + + HairData hairData; + + public HairAdvancedOptionsPropertyBlock(HairData hairData) => this.hairData = hairData; + + protected override void CreatePropertyGUI() + { + base.CreatePropertyGUI(); + + // Hair specific properties GUI + AddProperty(Styles.useLightFacingNormal, () => hairData.useLightFacingNormal, (newValue) => hairData.useLightFacingNormal = newValue); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertiesGUI.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairAdvancedOptionsPropertyBlock.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertiesGUI.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairAdvancedOptionsPropertyBlock.cs.meta index 5783516093a..429e4eda893 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertiesGUI.cs.meta +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairAdvancedOptionsPropertyBlock.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d2f6d49643ace004fac91de0814564e6 +guid: 7d7c6ea35025a26458a0d9af3098f7b9 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs deleted file mode 100644 index 1f692d87d2a..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs +++ /dev/null @@ -1,273 +0,0 @@ -using System; -using UnityEngine.Rendering; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; -using UnityEngine.UIElements; -using UnityEditor.UIElements; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - class HairSettingsView - { - SystemData systemData; - BuiltinData builtinData; - LightingData lightingData; - HairData hairData; - - IntegerField m_SortPriorityField; - - public HairSettingsView(HairSubTarget subTarget) - { - systemData = subTarget.systemData; - builtinData = subTarget.builtinData; - lightingData = subTarget.lightingData; - hairData = subTarget.hairData; - } - - public void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) - { - // Render State - DoRenderStateArea(ref context, systemData, 0, onChange, registerUndo); - - // Alpha Test - // TODO: AlphaTest is in SystemData but Alpha to Mask is in BuiltinData? - context.AddProperty("Alpha Clipping", 0, new Toggle() { value = systemData.alphaTest }, (evt) => - { - if (Equals(systemData.alphaTest, evt.newValue)) - return; - - registerUndo("Alpha Clipping"); - systemData.alphaTest = evt.newValue; - onChange(); - }); - context.AddProperty("Use Shadow Threshold", 1, new Toggle() { value = builtinData.alphaTestShadow }, systemData.alphaTest, (evt) => - { - if (Equals(builtinData.alphaTestShadow, evt.newValue)) - return; - - registerUndo("Use Shadow Threshold"); - builtinData.alphaTestShadow = evt.newValue; - onChange(); - }); - context.AddProperty("Alpha to Mask", 1, new Toggle() { value = builtinData.alphaToMask }, systemData.alphaTest, (evt) => - { - if (Equals(builtinData.alphaToMask, evt.newValue)) - return; - - registerUndo("Alpha to Mask"); - builtinData.alphaToMask = evt.newValue; - onChange(); - }); - - // Misc - context.AddProperty("Double-Sided Mode", 0, new EnumField(DoubleSidedMode.Disabled) { value = systemData.doubleSidedMode }, (evt) => - { - if (Equals(systemData.doubleSidedMode, evt.newValue)) - return; - - registerUndo("Double-Sided Mode"); - systemData.doubleSidedMode = (DoubleSidedMode)evt.newValue; - onChange(); - }); - context.AddProperty("Receive Decals", 0, new Toggle() { value = lightingData.receiveDecals }, (evt) => - { - if (Equals(lightingData.receiveDecals, evt.newValue)) - return; - - registerUndo("Receive Decals"); - lightingData.receiveDecals = evt.newValue; - onChange(); - }); - context.AddProperty("Receive SSR", 0, new Toggle() { value = lightingData.receiveSSR }, (evt) => - { - if (Equals(lightingData.receiveSSR, evt.newValue)) - return; - - registerUndo("Receive SSR"); - lightingData.receiveSSR = evt.newValue; - onChange(); - }); - context.AddProperty("Add Precomputed Velocity", 0, new Toggle() { value = builtinData.addPrecomputedVelocity }, (evt) => - { - if (Equals(builtinData.addPrecomputedVelocity, evt.newValue)) - return; - - registerUndo("Add Precomputed Velocity"); - builtinData.addPrecomputedVelocity = evt.newValue; - onChange(); - }); - context.AddProperty("Geometric Specular AA", 0, new Toggle() { value = lightingData.specularAA }, (evt) => - { - if (Equals(lightingData.specularAA, evt.newValue)) - return; - - registerUndo("Geometric Specular AA"); - lightingData.specularAA = evt.newValue; - onChange(); - }); - context.AddProperty("Specular Occlusion Mode", 0, new EnumField(SpecularOcclusionMode.Off) { value = lightingData.specularOcclusionMode }, (evt) => - { - if (Equals(lightingData.specularOcclusionMode, evt.newValue)) - return; - - registerUndo("Specular Occlusion Mode"); - lightingData.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; - onChange(); - }); - context.AddProperty("Override Baked GI", 0, new Toggle() { value = lightingData.overrideBakedGI }, (evt) => - { - if (Equals(lightingData.overrideBakedGI, evt.newValue)) - return; - - registerUndo("Override Baked GI"); - lightingData.overrideBakedGI = evt.newValue; - onChange(); - }); - context.AddProperty("Depth Offset", 0, new Toggle() { value = builtinData.depthOffset }, (evt) => - { - if (Equals(builtinData.depthOffset, evt.newValue)) - return; - - registerUndo("Depth Offset"); - builtinData.depthOffset = evt.newValue; - onChange(); - }); - context.AddProperty("Use Light Facing Normal", 0, new Toggle() { value = hairData.useLightFacingNormal }, (evt) => - { - if (Equals(hairData.useLightFacingNormal, evt.newValue)) - return; - - registerUndo("Use Light Facing Normal"); - hairData.useLightFacingNormal = evt.newValue; - onChange(); - }); - context.AddProperty("Support LOD CrossFade", 0, new Toggle() { value = systemData.supportLodCrossFade }, (evt) => - { - if (Equals(systemData.supportLodCrossFade, evt.newValue)) - return; - - registerUndo("Support LOD CrossFade"); - systemData.supportLodCrossFade = evt.newValue; - onChange(); - }); - } - - void DoRenderStateArea(ref TargetPropertyGUIContext context, SystemData systemData, int indentLevel, Action onChange, Action registerUndo) - { - context.AddProperty("Surface Type", indentLevel, new EnumField(SurfaceType.Opaque) { value = systemData.surfaceType }, (evt) => - { - if (Equals(systemData.surfaceType, evt.newValue)) - return; - - registerUndo("Surface Type"); - systemData.surfaceType = (SurfaceType)evt.newValue; - systemData.TryChangeRenderingPass(systemData.renderingPass); - onChange(); - }); - - context.AddProperty("Preserve Specular Lighting", indentLevel + 1, new Toggle() { value = lightingData.blendPreserveSpecular }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(lightingData.blendPreserveSpecular, evt.newValue)) - return; - - registerUndo("Preserve Specular Lighting"); - lightingData.blendPreserveSpecular = evt.newValue; - onChange(); - }); - - context.AddProperty("Receive Fog", indentLevel + 1, new Toggle() { value = builtinData.transparencyFog }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(builtinData.transparencyFog, evt.newValue)) - return; - - registerUndo("Receive Fog"); - builtinData.transparencyFog = evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Test", indentLevel + 1, new EnumField(systemData.zTest) { value = systemData.zTest }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zTest, evt.newValue)) - return; - - registerUndo("Depth Test"); - systemData.zTest = (CompareFunction)evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Write", indentLevel + 1, new Toggle() { value = systemData.zWrite }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zWrite, evt.newValue)) - return; - - registerUndo("Depth Write"); - systemData.zWrite = evt.newValue; - onChange(); - }); - - context.AddProperty("Cull Mode", indentLevel + 1, new EnumField(systemData.transparentCullMode) { value = systemData.transparentCullMode }, systemData.surfaceType == SurfaceType.Transparent && systemData.doubleSidedMode == DoubleSidedMode.Disabled, (evt) => - { - if (Equals(systemData.transparentCullMode, evt.newValue)) - return; - - registerUndo("Cull Mode"); - systemData.transparentCullMode = (TransparentCullMode)evt.newValue; - onChange(); - }); - - m_SortPriorityField = new IntegerField() { value = systemData.sortPriority }; - context.AddProperty("Sorting Priority", indentLevel + 1, m_SortPriorityField, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - var newValue = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); - if (Equals(systemData.sortPriority, newValue)) - return; - - registerUndo("Sorting Priority"); - m_SortPriorityField.value = newValue; - systemData.sortPriority = evt.newValue; - onChange(); - }); - - - context.AddProperty("Back Then Front Rendering", indentLevel + 1, new Toggle() { value = builtinData.backThenFrontRendering }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(builtinData.backThenFrontRendering, evt.newValue)) - return; - - registerUndo("Back Then Front Rendering"); - builtinData.backThenFrontRendering = evt.newValue; - onChange(); - }); - - context.AddProperty("Transparent Depth Prepass", indentLevel + 1, new Toggle() { value = systemData.alphaTestDepthPrepass }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.alphaTestDepthPrepass, evt.newValue)) - return; - - registerUndo("Transparent Depth Prepass"); - systemData.alphaTestDepthPrepass = evt.newValue; - onChange(); - }); - - context.AddProperty("Transparent Depth Postpass", indentLevel + 1, new Toggle() { value = systemData.alphaTestDepthPostpass }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.alphaTestDepthPostpass, evt.newValue)) - return; - - registerUndo("Transparent Depth Postpass"); - systemData.alphaTestDepthPostpass = evt.newValue; - onChange(); - }); - - context.AddProperty("Transparent Writes Motion Vector", indentLevel + 1, new Toggle() { value = builtinData.transparentWritesMotionVec }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(builtinData.transparentWritesMotionVec, evt.newValue)) - return; - - registerUndo("Transparent Writes Motion Vector"); - builtinData.transparentWritesMotionVec = evt.newValue; - onChange(); - }); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs index f7a09d0e13e..0f1eb11e8db 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs @@ -44,10 +44,11 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - AddSystemDataFields(ref context); - AddSpecularOcclusionFields(ref context); - AddLitMiscFields(ref context); - AddSurfaceMiscFields(ref context); + // TODO: move this elsewhere: + // Make sure that we don't end up in an unsupported configuration + lightingData.subsurfaceScattering = false; + + base.GetFields(ref context); // Hair specific properties: context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(HairSubTarget.HairPasses.MotionVectors)); @@ -70,8 +71,7 @@ public override void GetFields(ref TargetFieldContext context) public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - AddVertexBlocks(ref context); - AddSurfaceBlocks(ref context); + base.GetActiveBlocks(ref context); // Hair specific blocks context.AddBlock(BlockFields.SurfaceDescription.NormalTS); @@ -86,53 +86,10 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(HDBlockFields.SurfaceDescription.SecondarySpecularShift); } - public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) + protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { - var settingsView = new HairSettingsView(this); - settingsView.GetPropertiesGUI(ref context, onChange, registerUndo); - } - - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) - { - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (builtinData.addPrecomputedVelocity) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } - - // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, false, lightingData.receiveSSR); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - systemData.surfaceType, - systemData.blendMode, - systemData.sortPriority, - builtinData.alphaToMask, - systemData.zWrite, - systemData.transparentCullMode, - systemData.zTest, - builtinData.backThenFrontRendering, - builtinData.transparencyFog - ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, builtinData.alphaTestShadow); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, systemData.doubleSidedMode); + blockList.AddPropertyBlock(new SurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features.Lit)); + blockList.AddPropertyBlock(new HairAdvancedOptionsPropertyBlock(hairData)); } public override void ProcessPreviewMaterial(Material material) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs deleted file mode 100644 index 145694a50c5..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs +++ /dev/null @@ -1,382 +0,0 @@ -using System; -using UnityEngine.Rendering; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; -using UnityEngine.UIElements; -using UnityEditor.UIElements; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - class HDLitSettingsView - { - SystemData systemData; - BuiltinData builtinData; - LightingData lightingData; - HDLitData litData; - - IntegerField m_SortPriorityField; - - public HDLitSettingsView(HDLitSubTarget subTarget) - { - systemData = subTarget.systemData; - builtinData = subTarget.builtinData; - lightingData = subTarget.lightingData; - litData = subTarget.litData; - } - - public void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) - { - context.AddProperty("Ray Tracing (Preview)", 0, new Toggle() { value = litData.rayTracing }, (evt) => - { - if (Equals(litData.rayTracing, evt.newValue)) - return; - - registerUndo("Ray Tracing (Preview)"); - litData.rayTracing = evt.newValue; - onChange(); - }); - - // Render State - DoRenderStateArea(ref context, 0, onChange, registerUndo); - - context.AddProperty("Refraction Model", 1, new EnumField(ScreenSpaceRefraction.RefractionModel.None) { value = litData.refractionModel }, systemData.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction, (evt) => - { - if (Equals(litData.refractionModel, evt.newValue)) - return; - - registerUndo("Refraction Model"); - litData.refractionModel = (ScreenSpaceRefraction.RefractionModel)evt.newValue; - onChange(); - }); - - // Distortion - DoDistortionArea(ref context, 1, onChange, registerUndo); - - // Alpha Test - // TODO: AlphaTest is in SystemData but Alpha to Mask is in BuiltinData? - context.AddProperty("Alpha Clipping", 0, new Toggle() { value = systemData.alphaTest }, (evt) => - { - if (Equals(systemData.alphaTest, evt.newValue)) - return; - - registerUndo("Alpha Clipping"); - systemData.alphaTest = evt.newValue; - onChange(); - }); - context.AddProperty("Use Shadow Threshold", 1, new Toggle() { value = builtinData.alphaTestShadow }, systemData.alphaTest, (evt) => - { - if (Equals(builtinData.alphaTestShadow, evt.newValue)) - return; - - registerUndo("Use Shadow Threshold"); - builtinData.alphaTestShadow = evt.newValue; - onChange(); - }); - context.AddProperty("Alpha to Mask", 1, new Toggle() { value = builtinData.alphaToMask }, systemData.alphaTest, (evt) => - { - if (Equals(builtinData.alphaToMask, evt.newValue)) - return; - - registerUndo("Alpha to Mask"); - builtinData.alphaToMask = evt.newValue; - onChange(); - }); - - // Misc - context.AddProperty("Double-Sided Mode", 0, new EnumField(DoubleSidedMode.Disabled) { value = systemData.doubleSidedMode }, (evt) => - { - if (Equals(systemData.doubleSidedMode, evt.newValue)) - return; - - registerUndo("Double-Sided Mode"); - systemData.doubleSidedMode = (DoubleSidedMode)evt.newValue; - onChange(); - }); - context.AddProperty("Fragment Normal Space", 0, new EnumField(NormalDropOffSpace.Tangent) { value = lightingData.normalDropOffSpace }, (evt) => - { - if (Equals(lightingData.normalDropOffSpace, evt.newValue)) - return; - - registerUndo("Fragment Normal Space"); - lightingData.normalDropOffSpace = (NormalDropOffSpace)evt.newValue; - onChange(); - }); - - // Material - context.AddProperty("Material Type", 0, new EnumField(HDLitData.MaterialType.Standard) { value = litData.materialType }, (evt) => - { - if (Equals(litData.materialType, evt.newValue)) - return; - - registerUndo("Material Type"); - litData.materialType = (HDLitData.MaterialType)evt.newValue; - onChange(); - }); - context.AddProperty("Transmission", 1, new Toggle() { value = litData.sssTransmission }, litData.materialType == HDLitData.MaterialType.SubsurfaceScattering, (evt) => - { - if (Equals(litData.sssTransmission, evt.newValue)) - return; - - registerUndo("Transmission"); - litData.sssTransmission = evt.newValue; - onChange(); - }); - context.AddProperty("Energy Conserving Specular", 1, new Toggle() { value = lightingData.energyConservingSpecular }, litData.materialType == HDLitData.MaterialType.SpecularColor, (evt) => - { - if (Equals(lightingData.energyConservingSpecular, evt.newValue)) - return; - - registerUndo("Energy Conserving Specular"); - lightingData.energyConservingSpecular = evt.newValue; - onChange(); - }); - - // Misc Cont. - context.AddProperty("Receive Decals", 0, new Toggle() { value = lightingData.receiveDecals }, (evt) => - { - if (Equals(lightingData.receiveDecals, evt.newValue)) - return; - - registerUndo("Receive Decals"); - lightingData.receiveDecals = evt.newValue; - onChange(); - }); - context.AddProperty("Receive SSR", 0, new Toggle() { value = lightingData.receiveSSR }, (evt) => - { - if (Equals(lightingData.receiveSSR, evt.newValue)) - return; - - registerUndo("Receive SSR"); - lightingData.receiveSSR = evt.newValue; - onChange(); - }); - context.AddProperty("Add Precomputed Velocity", 0, new Toggle() { value = builtinData.addPrecomputedVelocity }, (evt) => - { - if (Equals(builtinData.addPrecomputedVelocity, evt.newValue)) - return; - - registerUndo("Add Precomputed Velocity"); - builtinData.addPrecomputedVelocity = evt.newValue; - onChange(); - }); - context.AddProperty("Geometric Specular AA", 0, new Toggle() { value = lightingData.specularAA }, (evt) => - { - if (Equals(lightingData.specularAA, evt.newValue)) - return; - - registerUndo("Geometric Specular AA"); - lightingData.specularAA = evt.newValue; - onChange(); - }); - context.AddProperty("Specular Occlusion Mode", 0, new EnumField(SpecularOcclusionMode.Off) { value = lightingData.specularOcclusionMode }, (evt) => - { - if (Equals(lightingData.specularOcclusionMode, evt.newValue)) - return; - - registerUndo("Specular Occlusion Mode"); - lightingData.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; - onChange(); - }); - context.AddProperty("Override Baked GI", 0, new Toggle() { value = lightingData.overrideBakedGI }, (evt) => - { - if (Equals(lightingData.overrideBakedGI, evt.newValue)) - return; - - registerUndo("Override Baked GI"); - lightingData.overrideBakedGI = evt.newValue; - onChange(); - }); - context.AddProperty("Depth Offset", 0, new Toggle() { value = builtinData.depthOffset }, (evt) => - { - if (Equals(builtinData.depthOffset, evt.newValue)) - return; - - registerUndo("Depth Offset"); - builtinData.depthOffset = evt.newValue; - onChange(); - }); - context.AddProperty("Support LOD CrossFade", 0, new Toggle() { value = systemData.supportLodCrossFade }, (evt) => - { - if (Equals(systemData.supportLodCrossFade, evt.newValue)) - return; - - registerUndo("Support LOD CrossFade"); - systemData.supportLodCrossFade = evt.newValue; - onChange(); - }); - } - - void DoRenderStateArea(ref TargetPropertyGUIContext context, int indentLevel, Action onChange, Action registerUndo) - { - context.AddProperty("Surface Type", indentLevel, new EnumField(SurfaceType.Opaque) { value = systemData.surfaceType }, (evt) => - { - if (Equals(systemData.surfaceType, evt.newValue)) - return; - - registerUndo("Surface Type"); - systemData.surfaceType = (SurfaceType)evt.newValue; - systemData.TryChangeRenderingPass(systemData.renderingPass); - onChange(); - }); - - var renderingPassList = HDSubShaderUtilities.GetRenderingPassList(systemData.surfaceType == SurfaceType.Opaque, false); - var renderingPassValue = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.GetOpaqueEquivalent(systemData.renderingPass) : HDRenderQueue.GetTransparentEquivalent(systemData.renderingPass); - var renderQueueType = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - context.AddProperty("Rendering Pass", indentLevel + 1, new PopupField(renderingPassList, renderQueueType, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName) { value = renderingPassValue }, (evt) => - { - registerUndo("Rendering Pass"); - if(systemData.TryChangeRenderingPass(evt.newValue)) - { - onChange(); - } - }); - - context.AddProperty("Blending Mode", indentLevel + 1, new EnumField(BlendMode.Alpha) { value = systemData.blendMode }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.blendMode, evt.newValue)) - return; - - registerUndo("Blending Mode"); - systemData.blendMode = (BlendMode)evt.newValue; - onChange(); - }); - - context.AddProperty("Preserve Specular Lighting", indentLevel + 1, new Toggle() { value = lightingData.blendPreserveSpecular }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(lightingData.blendPreserveSpecular, evt.newValue)) - return; - - registerUndo("Preserve Specular Lighting"); - lightingData.blendPreserveSpecular = evt.newValue; - onChange(); - }); - - context.AddProperty("Receive Fog", indentLevel + 1, new Toggle() { value = builtinData.transparencyFog }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(builtinData.transparencyFog, evt.newValue)) - return; - - registerUndo("Receive Fog"); - builtinData.transparencyFog = evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Test", indentLevel + 1, new EnumField(systemData.zTest) { value = systemData.zTest }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zTest, evt.newValue)) - return; - - registerUndo("Depth Test"); - systemData.zTest = (CompareFunction)evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Write", indentLevel + 1, new Toggle() { value = systemData.zWrite }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zWrite, evt.newValue)) - return; - - registerUndo("Depth Write"); - systemData.zWrite = evt.newValue; - onChange(); - }); - - context.AddProperty("Cull Mode", indentLevel + 1, new EnumField(systemData.transparentCullMode) { value = systemData.transparentCullMode }, systemData.surfaceType == SurfaceType.Transparent && systemData.doubleSidedMode == DoubleSidedMode.Disabled, (evt) => - { - if (Equals(systemData.transparentCullMode, evt.newValue)) - return; - - registerUndo("Cull Mode"); - systemData.transparentCullMode = (TransparentCullMode)evt.newValue; - onChange(); - }); - - m_SortPriorityField = new IntegerField() { value = systemData.sortPriority }; - context.AddProperty("Sorting Priority", indentLevel + 1, m_SortPriorityField, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - var newValue = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); - if (Equals(systemData.sortPriority, newValue)) - return; - - registerUndo("Sorting Priority"); - m_SortPriorityField.value = newValue; - systemData.sortPriority = evt.newValue; - onChange(); - }); - - - context.AddProperty("Back Then Front Rendering", indentLevel + 1, new Toggle() { value = builtinData.backThenFrontRendering }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(builtinData.backThenFrontRendering, evt.newValue)) - return; - - registerUndo("Back Then Front Rendering"); - builtinData.backThenFrontRendering = evt.newValue; - onChange(); - }); - - context.AddProperty("Transparent Depth Prepass", indentLevel + 1, new Toggle() { value = systemData.alphaTestDepthPrepass }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.alphaTestDepthPrepass, evt.newValue)) - return; - - registerUndo("Transparent Depth Prepass"); - systemData.alphaTestDepthPrepass = evt.newValue; - onChange(); - }); - - context.AddProperty("Transparent Depth Postpass", indentLevel + 1, new Toggle() { value = systemData.alphaTestDepthPostpass }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.alphaTestDepthPostpass, evt.newValue)) - return; - - registerUndo("Transparent Depth Postpass"); - systemData.alphaTestDepthPostpass = evt.newValue; - onChange(); - }); - - context.AddProperty("Transparent Writes Motion Vector", indentLevel + 1, new Toggle() { value = builtinData.transparentWritesMotionVec }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(builtinData.transparentWritesMotionVec, evt.newValue)) - return; - - registerUndo("Transparent Writes Motion Vector"); - builtinData.transparentWritesMotionVec = evt.newValue; - onChange(); - }); - } - - void DoDistortionArea(ref TargetPropertyGUIContext context, int indentLevel, Action onChange, Action registerUndo) - { - context.AddProperty("Distortion", indentLevel, new Toggle() { value = builtinData.distortion }, (evt) => - { - if (Equals(builtinData.distortion, evt.newValue)) - return; - - registerUndo("Distortion"); - builtinData.distortion = evt.newValue; - onChange(); - }); - - context.AddProperty("Distortion Blend Mode", indentLevel + 1, new EnumField(DistortionMode.Add) { value = builtinData.distortionMode }, builtinData.distortion, (evt) => - { - if (Equals(builtinData.distortionMode, evt.newValue)) - return; - - registerUndo("Distortion Blend Mode"); - builtinData.distortionMode = (DistortionMode)evt.newValue; - onChange(); - }); - - context.AddProperty("Distortion Depth Test", indentLevel + 1, new Toggle() { value = builtinData.distortionDepthTest }, builtinData.distortion, (evt) => - { - if (Equals(builtinData.distortionDepthTest, evt.newValue)) - return; - - registerUndo("Distortion Depth Test"); - builtinData.distortionDepthTest = evt.newValue; - onChange(); - }); - } - } -} 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 fac997d96a3..8e7577b5e25 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 @@ -46,12 +46,8 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - AddSystemDataFields(ref context); + base.GetFields(ref context); AddDistortionFields(ref context); - AddNormalDropOffFields(ref context); - AddSpecularOcclusionFields(ref context); - AddSurfaceMiscFields(ref context); - AddLitMiscFields(ref context); bool hasRefraction = (systemData.surfaceType == SurfaceType.Transparent && systemData.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction && litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None); @@ -98,8 +94,7 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) bool hasDistortion = (systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); // Vertex - AddVertexBlocks(ref context); - AddSurfaceBlocks(ref context); + base.GetActiveBlocks(ref context); AddDistortionBlocks(ref context); AddNormalBlocks(ref context); @@ -126,65 +121,20 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) litData.materialType == HDLitData.MaterialType.Iridescence); } - public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) - { - // TODO - // SystemDataPropertiesGUI.AddProperties(systemData, ref context, onChange, registerUndo); - // var settingsView = new HDLitSettingsView(this); - // settingsView.GetPropertiesGUI(ref context, onChange, registerUndo); - } - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) { - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - // ShaderGraph only property used to send the RenderQueueType to the material - collector.AddShaderProperty(new Vector1ShaderProperty - { - overrideReferenceName = "_RenderQueueType", - hidden = true, - value = (int)systemData.renderingPass, - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (builtinData.addPrecomputedVelocity) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } + base.CollectShaderProperties(collector, generationMode); - // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, litData.materialType == HDLitData.MaterialType.SubsurfaceScattering, lightingData.receiveSSR, litData.receiveSSRTransparent); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - systemData.surfaceType, - systemData.blendMode, - systemData.sortPriority, - builtinData.alphaToMask, - systemData.zWrite, - systemData.transparentCullMode, - systemData.zTest, - builtinData.backThenFrontRendering, - builtinData.transparencyFog - ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, builtinData.alphaTestShadow); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, systemData.doubleSidedMode); HDSubShaderUtilities.AddRayTracingProperty(collector, litData.rayTracing); } + protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) + { + blockList.AddPropertyBlock(new LitSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features.Lit, litData)); + blockList.AddPropertyBlock(new DistortionPropertyBlock()); + blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); + } + public override void ProcessPreviewMaterial(Material material) { // Fixup the material settings: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs new file mode 100644 index 00000000000..8267f78039f --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine; + +// We share the name of the properties in the UI to avoid duplication +using static UnityEditor.Rendering.HighDefinition.DistortionUIBlock.Styles; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + class LitPropertyBlock : SubTargetPropertyBlock + { + protected override string title => "Lit Properties"; + protected override int foldoutIndex => 2; + + HDLitData litData; + + public LitPropertyBlock(HDLitData litData) + { + this.litData = litData; + } + + protected override void CreatePropertyGUI() + { + + } + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs.meta index ab0b1913ab8..08db573feab 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSettingsView.cs.meta +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitPropertyBlock.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 32e16a9129dd75443a57732b47cfde94 +guid: c3d42a05c18dfbd47af8937648d6ec0d MonoImporter: externalObjects: {} serializedVersion: 2 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 new file mode 100644 index 00000000000..a89e7390850 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine; + +// We share the name of the properties in the UI to avoid duplication +using static UnityEditor.Rendering.HighDefinition.SurfaceOptionUIBlock.Styles; +using static UnityEditor.Rendering.HighDefinition.RefractionUIBlock.Styles; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + class LitSurfaceOptionPropertyBlock : SurfaceOptionPropertyBlock + { + HDLitData litData; + + public LitSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features features, HDLitData litData) : base(features) + => this.litData = litData; + + protected override void CreatePropertyGUI() + { + // Lit specific properties: + AddProperty(materialIDText, () => litData.materialType, (newValue) => + { + // Sync duplicated data in GUI + lightingData.subsurfaceScattering = litData.materialType == HDLitData.MaterialType.SubsurfaceScattering; + litData.materialType = newValue; + }); + AddProperty(rayTracingText, () => litData.rayTracing, (newValue) => litData.rayTracing = newValue); + + base.CreatePropertyGUI(); + + AddProperty(transmissionEnableText, () => litData.sssTransmission, (newValue) => litData.sssTransmission = newValue); + AddProperty(refractionModelText, () => litData.refractionModel, (newValue) => litData.refractionModel = newValue); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs.meta index e24452b95f8..232804fb6ad 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSettingsView.cs.meta +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 00b9f1cdcb0d93f40b3703a12d4c146f +guid: 660abe0253750824dbda6e78a07ce510 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs new file mode 100644 index 00000000000..384a2c44616 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine; + +// We share the name of the properties in the UI to avoid duplication +using static UnityEditor.Rendering.HighDefinition.AdvancedOptionsUIBlock.Styles; +using static UnityEditor.Rendering.HighDefinition.SurfaceOptionUIBlock.Styles; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + class AdvancedOptionsPropertyBlock : SubTargetPropertyBlock + { + class Styles + { + public static GUIContent overrideBakedGI = new GUIContent("Override Baked GI", "TODO"); + public static GUIContent supportLodCrossFade = new GUIContent("Support LOD CrossFade", "TODO"); + } + + protected override string title => "Advanced Options"; + protected override int foldoutIndex => 3; + + protected override void CreatePropertyGUI() + { + AddProperty(specularOcclusionModeText, () => lightingData.specularOcclusionMode, (newValue) => lightingData.specularOcclusionMode = newValue); + AddProperty(Styles.overrideBakedGI, () => lightingData.overrideBakedGI, (newValue) => lightingData.overrideBakedGI = newValue); + AddProperty(Styles.supportLodCrossFade, () => systemData.supportLodCrossFade, (newValue) => systemData.supportLodCrossFade = newValue); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs.meta new file mode 100644 index 00000000000..dd51756a261 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 27501b0b352a8d442a4f1e892d5d4887 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DistortionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DistortionPropertyBlock.cs new file mode 100644 index 00000000000..603e4d4da87 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DistortionPropertyBlock.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine; + +// We share the name of the properties in the UI to avoid duplication +using static UnityEditor.Rendering.HighDefinition.DistortionUIBlock.Styles; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + class DistortionPropertyBlock : SubTargetPropertyBlock + { + protected override string title => "Distortion"; + protected override int foldoutIndex => 1; + + protected override void CreatePropertyGUI() + { + AddProperty(distortionEnableText, () => builtinData.distortion, (newValue) => builtinData.distortion = newValue); + AddProperty(distortionBlendModeText, () => builtinData.distortionMode, (newValue) => builtinData.distortionMode = newValue); + AddProperty(distortionDepthTestText, () => builtinData.distortionDepthTest, (newValue) => builtinData.distortionDepthTest = newValue); + } + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DistortionPropertyBlock.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DistortionPropertyBlock.cs.meta new file mode 100644 index 00000000000..f5edddb757b --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DistortionPropertyBlock.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e555db764fc0c4942b3b48e1c40affe9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetDataPropertiesGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDPropertiesHeader.cs similarity index 57% rename from com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetDataPropertiesGUI.cs rename to com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDPropertiesHeader.cs index 383af09ab6f..559d224c165 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetDataPropertiesGUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDPropertiesHeader.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using UnityEngine.Rendering; using UnityEngine.Rendering.HighDefinition; using UnityEditor.ShaderGraph; @@ -7,14 +8,11 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { - abstract class TargetDataPropertiesGUI where T : HDTargetData + class HDPropertiesHeader : Toggle { - protected T targetData; - - public TargetDataPropertiesGUI(T targetData) + public HDPropertiesHeader(string label) : base(label) { - this.targetData = targetData; + } - } } \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDPropertiesHeader.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDPropertiesHeader.cs.meta new file mode 100644 index 00000000000..6ce96986ece --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDPropertiesHeader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 31b8812c1cf3c284e92bf49333fa31e3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs index 7dbb8176dfe..ae99d35dc01 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs @@ -72,45 +72,28 @@ public sealed override void Setup(ref TargetSetupContext context) } } - protected abstract IEnumerable EnumerateSubShaders(); - - // System data specific fields: - protected void AddSystemDataFields(ref TargetFieldContext context) + public override void GetFields(ref TargetFieldContext context) { - // Features - context.AddField(Fields.LodCrossFade, systemData.supportLodCrossFade); - + // Common properties between all HD master nodes // Surface Type context.AddField(Fields.SurfaceOpaque, systemData.surfaceType == SurfaceType.Opaque); context.AddField(Fields.SurfaceTransparent, systemData.surfaceType != SurfaceType.Opaque); // Dots context.AddField(HDFields.DotsInstancing, systemData.dotsInstancing); + } - // Blend Mode - context.AddField(Fields.BlendAdd, systemData.surfaceType != SurfaceType.Opaque && systemData.blendMode == BlendMode.Additive); - context.AddField(Fields.BlendAlpha, systemData.surfaceType != SurfaceType.Opaque && systemData.blendMode == BlendMode.Alpha); - context.AddField(Fields.BlendPremultiply, systemData.surfaceType != SurfaceType.Opaque && systemData.blendMode == BlendMode.Premultiply); - - // Double Sided - context.AddField(HDFields.DoubleSided, systemData.doubleSidedMode != DoubleSidedMode.Disabled); - - // We always generate the keyword ALPHATEST_ON - context.AddField(Fields.AlphaTest, systemData.alphaTest - && (context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold) - || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow) - || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass) - || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass))); - - context.AddField(HDFields.DoAlphaTestPrepass, systemData.alphaTest && systemData.alphaTestDepthPrepass - && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass)); - context.AddField(HDFields.DoAlphaTestPostpass, systemData.alphaTest && systemData.alphaTestDepthPostpass - && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass)); + protected abstract IEnumerable EnumerateSubShaders(); - context.AddField(HDFields.TransparentDepthPrePass, systemData.surfaceType != SurfaceType.Opaque && systemData.alphaTestDepthPrepass); - context.AddField(HDFields.TransparentDepthPostPass, systemData.surfaceType != SurfaceType.Opaque && systemData.alphaTestDepthPostpass); + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) + { + var gui = new SubTargetPropertiesGUI(context, onChange, registerUndo, systemData, null, null); + AddInspectorPropertyBlocks(gui); + context.Add(gui); } + protected abstract void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList); + public override object saveContext { get diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs index 8182af733af..db324f35b2c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs @@ -41,6 +41,13 @@ public LightingData lightingData set => m_LightingData = value; } + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) + { + var gui = new SubTargetPropertiesGUI(context, onChange, registerUndo, systemData, builtinData, lightingData); + AddInspectorPropertyBlocks(gui); + context.Add(gui); + } + protected override int ComputeMaterialNeedsUpdateHash() { int hash = base.ComputeMaterialNeedsUpdateHash(); @@ -56,8 +63,18 @@ protected override int ComputeMaterialNeedsUpdateHash() return hash; } - protected void AddLitMiscFields(ref TargetFieldContext context) + public override void GetFields(ref TargetFieldContext context) { + base.GetFields(ref context); + + // Common properties to all Lit master nodes + + // Normal dropoff space + context.AddField(Fields.NormalDropOffOS, lightingData.normalDropOffSpace == NormalDropOffSpace.Object); + context.AddField(Fields.NormalDropOffTS, lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent); + context.AddField(Fields.NormalDropOffWS, lightingData.normalDropOffSpace == NormalDropOffSpace.World); + + // Misc context.AddField(HDFields.BlendPreserveSpecular, systemData.surfaceType != SurfaceType.Opaque && lightingData.blendPreserveSpecular); context.AddField(HDFields.DisableDecals, !lightingData.receiveDecals); context.AddField(HDFields.DisableSSR, !lightingData.receiveSSR); @@ -65,24 +82,12 @@ protected void AddLitMiscFields(ref TargetFieldContext context) context.AddField(HDFields.SpecularAA, lightingData.specularAA && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAThreshold) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance)); - context.AddField(HDFields.BentNormal, context.blocks.Contains(HDBlockFields.SurfaceDescription.BentNormal) && context.connectedBlocks.Contains(HDBlockFields.SurfaceDescription.BentNormal) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.BentNormal)); - context.AddField(HDFields.AmbientOcclusion, context.blocks.Contains(BlockFields.SurfaceDescription.Occlusion) && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.Occlusion)); context.AddField(HDFields.LightingGI, context.blocks.Contains(HDBlockFields.SurfaceDescription.BakedGI) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.BakedGI)); context.AddField(HDFields.BackLightingGI, context.blocks.Contains(HDBlockFields.SurfaceDescription.BakedBackGI) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.BakedBackGI)); + context.AddField(HDFields.BentNormal, context.blocks.Contains(HDBlockFields.SurfaceDescription.BentNormal) && context.connectedBlocks.Contains(HDBlockFields.SurfaceDescription.BentNormal) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.BentNormal)); + context.AddField(HDFields.AmbientOcclusion, context.blocks.Contains(BlockFields.SurfaceDescription.Occlusion) && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.Occlusion)); - context.AddField(HDFields.TransparentBackFace, systemData.surfaceType != SurfaceType.Opaque && builtinData.backThenFrontRendering); - context.AddField(HDFields.DoAlphaTestShadow, systemData.alphaTest && builtinData.alphaTestShadow && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow)); - } - - protected void AddNormalDropOffFields(ref TargetFieldContext context) - { - context.AddField(Fields.NormalDropOffOS, lightingData.normalDropOffSpace == NormalDropOffSpace.Object); - context.AddField(Fields.NormalDropOffTS, lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent); - context.AddField(Fields.NormalDropOffWS, lightingData.normalDropOffSpace == NormalDropOffSpace.World); - } - - protected void AddSpecularOcclusionFields(ref TargetFieldContext context) - { + // Specular Occlusion Fields context.AddField(HDFields.SpecularOcclusionFromAO, lightingData.specularOcclusionMode == SpecularOcclusionMode.FromAO); context.AddField(HDFields.SpecularOcclusionFromAOBentNormal, lightingData.specularOcclusionMode == SpecularOcclusionMode.FromAOAndBentNormal); context.AddField(HDFields.SpecularOcclusionCustom, lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom); @@ -112,5 +117,13 @@ protected void AddNormalBlocks(ref TargetActiveBlockContext context) context.AddBlock(BlockFields.SurfaceDescription.NormalTS, lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent); context.AddBlock(BlockFields.SurfaceDescription.NormalWS, lightingData.normalDropOffSpace == NormalDropOffSpace.World); } + + public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) + { + base.CollectShaderProperties(collector, generationMode); + + // Add all shader properties required by the inspector + HDSubShaderUtilities.AddStencilShaderProperties(collector, lightingData.subsurfaceScattering, lightingData.receiveSSR); + } } } \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertiesGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertiesGUI.cs new file mode 100644 index 00000000000..8b224e2c236 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertiesGUI.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + class SubTargetPropertiesGUI : VisualElement + { + TargetPropertyGUIContext context; + Action onChange; + Action registerUndo; + SystemData systemData; + BuiltinData builtinData; + LightingData lightingData; + + public List uiBlocks = new List(); + + public SubTargetPropertiesGUI(TargetPropertyGUIContext context, Action onChange, Action registerUndo, + SystemData systemData, BuiltinData builtinData, LightingData lightingData) + { + this.context = context; + this.onChange = onChange; + this.registerUndo = registerUndo; + this.systemData = systemData; + this.builtinData = builtinData; + this.lightingData = lightingData; + } + + public void AddPropertyBlock(SubTargetPropertyBlock block) + { + block.Initialize(context, onChange, registerUndo, systemData, builtinData, lightingData); + block.CreatePropertyGUIWithHeader(); + Add(block); + } + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetDataPropertiesGUI.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertiesGUI.cs.meta similarity index 100% rename from com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetDataPropertiesGUI.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertiesGUI.cs.meta diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs new file mode 100644 index 00000000000..58b4cdaa9c0 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs @@ -0,0 +1,138 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine; +using RenderQueueType = UnityEngine.Rendering.HighDefinition.HDRenderQueue.RenderQueueType; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + abstract class SubTargetPropertyBlock : VisualElement + { + // Null/Empty means no title + protected virtual string title => null; + + protected TargetPropertyGUIContext context; + protected Action onChange; + protected Action registerUndo; + protected SystemData systemData; + protected BuiltinData builtinData; + protected LightingData lightingData; + + internal void Initialize(TargetPropertyGUIContext context, Action onChange, Action registerUndo, + SystemData systemData, BuiltinData builtinData, LightingData lightingData) + { + this.context = context; + this.onChange = onChange; + this.registerUndo = registerUndo; + this.systemData = systemData; + this.builtinData = builtinData; + this.lightingData = lightingData; + } + + // Utility function to create UIElement fields: + protected void AddProperty(string displayName, Func getter, Action setter, int indentLevel = 0) + => AddProperty(new GUIContent(displayName), getter, setter, indentLevel); + + protected void AddProperty(GUIContent displayName, Func getter, Action setter, int indentLevel = 0) + { + // Create UIElement from type: + BaseField elem = null; + BaseField elemEnum = null; + + switch (getter()) + { + case bool b: elem = new Toggle { value = b, tooltip = displayName.tooltip } as BaseField; break; + case int i: elem = new IntegerField { value = i, tooltip = displayName.tooltip } as BaseField; break; + case float f: elem = new FloatField { value = f, tooltip = displayName.tooltip } as BaseField; break; + case SurfaceType e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case RenderQueueType e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case BlendMode e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case CompareFunction e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case TransparentCullMode e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case DoubleSidedMode e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case NormalDropOffSpace e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case HDLitData.MaterialType e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case DistortionMode e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case ScreenSpaceRefraction.RefractionModel e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case SpecularOcclusionMode e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + default: throw new Exception($"Can't create UI field for type {getter().GetType()}, please add it if it's relevant."); + } + + if (elem != null) + { + context.AddProperty(displayName.text, indentLevel, elem, (evt) => { + if (Equals(getter(), evt.newValue)) + return; + + registerUndo(displayName.text); + setter(evt.newValue); + onChange(); + }); + } + else + { + context.AddProperty(displayName.text, indentLevel, elemEnum, (evt) => { + if (Equals(getter(), evt.newValue)) + return; + + registerUndo(displayName.text); + setter((Data)(object)evt.newValue); + onChange(); + }); + } + } + + protected void AddFoldout(string text, Func getter, Action setter) + => AddFoldout(new GUIContent(text), getter, setter); + + protected void AddFoldout(GUIContent content, Func getter, Action setter) + { + var foldout = new Foldout() { + value = getter(), + text = content.text, + tooltip = content.tooltip + }; + + foldout.RegisterValueChangedCallback((evt) => { + setter(evt.newValue); + onChange(); + }); + + // Apply padding: + foldout.style.paddingLeft = context.globalIndentLevel * 15; + + context.Add(foldout); + } + + public void CreatePropertyGUIWithHeader() + { + if (!String.IsNullOrEmpty(title)) + { + int index = foldoutIndex; + AddFoldout(title, + () => (systemData.inspectorFoldoutMask & (1 << index)) != 0, + (value) => + { + systemData.inspectorFoldoutMask &= ~(1 << index); // Clear + systemData.inspectorFoldoutMask |= (value ? 1 : 0) << index; // Set + } + ); + context.globalIndentLevel++; + if ((systemData.inspectorFoldoutMask & (1 << index)) != 0) + CreatePropertyGUI(); + context.globalIndentLevel--; + } + else + CreatePropertyGUI(); + } + + protected abstract void CreatePropertyGUI(); + + /// Warning: this property must have a different value for each property block type! + protected abstract int foldoutIndex { get; } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs.meta new file mode 100644 index 00000000000..976be52ab1d --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 75e8a39b82611424ea7f2a18003ab651 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertiesGUI.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertiesGUI.cs deleted file mode 100644 index b384cefebe9..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertiesGUI.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using UnityEngine.Rendering; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; -using UnityEngine.UIElements; -using UnityEditor.UIElements; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - static class SurfaceOptionPropertiesGUI - { - public delegate void Olol(T data, ref object field); - - static TargetPropertyGUIContext ctx; - static Action change; - static Action undo; - - /// Standard function to create the UI for a property - static void AddProperty(string displayName, ref Data field, BaseField elem) - { - // ctx.AddProperty(displayName, 0, elem, (evt) => { - // if (Equals(field, evt.newValue)) - // return; - - // undo(displayName); - // field = evt.newValue; - // change(); - // }); - } - - public static void AddProperties(SystemData systemData, ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) - { - ctx = context; - undo = registerUndo; - change = onChange; - // Alpha Test - // TODO: AlphaTest is in SystemData but Alpha to Mask is in BuiltinData? - // AddProperty("Alpha Clipping", systemData, nameof(systemData.alphaTest)); - - // AddProperty("Alpha Clipping", () => systemData.alphaTest, (newValue) => systemData.alphaTest); - - // Misc - context.AddProperty("Double-Sided Mode", 0, new EnumField(DoubleSidedMode.Disabled) { value = systemData.doubleSidedMode }, (evt) => - { - if (Equals(systemData.doubleSidedMode, evt.newValue)) - return; - - registerUndo("Double-Sided Mode"); - systemData.doubleSidedMode = (DoubleSidedMode)evt.newValue; - onChange(); - }); - } - } -} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs new file mode 100644 index 00000000000..784240e6f59 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine; + +// We share the name of the properties in the UI to avoid duplication +using static UnityEditor.Rendering.HighDefinition.SurfaceOptionUIBlock.Styles; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + class SurfaceOptionPropertyBlock : SubTargetPropertyBlock + { + [Flags] + public enum Features + { + None = 0, + All = ~0, + + Unlit = All, + Lit = All, + } + + class Styles + { + public static GUIContent fragmentNormalSpace = new GUIContent("Fragment Normal Space", "TODO"); + } + + Features enabledFeatures; + + protected override string title => "Surface Option"; + protected override int foldoutIndex => 0; + + public SurfaceOptionPropertyBlock(Features features) => enabledFeatures = features; + + protected override void CreatePropertyGUI() + { + AddProperty(surfaceTypeText, () => systemData.surfaceType, (newValue) => { + systemData.surfaceType = newValue; + systemData.TryChangeRenderingPass(systemData.renderingPass); + }); + + var renderingPassList = HDSubShaderUtilities.GetRenderingPassList(systemData.surfaceType == SurfaceType.Opaque, false); + var renderingPassValue = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.GetOpaqueEquivalent(systemData.renderingPass) : HDRenderQueue.GetTransparentEquivalent(systemData.renderingPass); + var renderQueueType = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; + context.AddProperty(renderingPassText, new PopupField(renderingPassList, renderQueueType, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName) { value = renderingPassValue }, (evt) => + { + registerUndo(renderingPassText); + if(systemData.TryChangeRenderingPass(evt.newValue)) + onChange(); + }); + + if (systemData.surfaceType == SurfaceType.Transparent) + { + context.globalIndentLevel++; + AddProperty(blendModeText, () => systemData.blendMode, (newValue) => systemData.blendMode = newValue); + AddProperty(enableTransparentFogText, () => builtinData.transparencyFog, (newValue) => builtinData.transparencyFog = newValue); + AddProperty(transparentZTestText, () => systemData.zTest, (newValue) => systemData.zTest = newValue); + AddProperty(zWriteEnableText, () => systemData.zWrite, (newValue) => systemData.zWrite = newValue); + AddProperty(transparentCullModeText, () => systemData.transparentCullMode, (newValue) => systemData.transparentCullMode = newValue); + AddProperty(transparentSortPriorityText, () => systemData.sortPriority, (newValue) => systemData.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(newValue)); + AddProperty(transparentBackfaceEnableText, () => builtinData.backThenFrontRendering, (newValue) => builtinData.backThenFrontRendering = newValue); + AddProperty(transparentDepthPrepassEnableText, () => systemData.alphaTestDepthPrepass, (newValue) => systemData.alphaTestDepthPrepass = newValue); + AddProperty(transparentDepthPostpassEnableText, () => systemData.alphaTestDepthPostpass, (newValue) => systemData.alphaTestDepthPostpass = newValue); + AddProperty(transparentWritingMotionVecText, () => builtinData.transparentWritesMotionVec, (newValue) => builtinData.transparentWritesMotionVec = newValue); + + if (lightingData != null) + AddProperty(enableBlendModePreserveSpecularLightingText, () => lightingData.blendPreserveSpecular, (newValue) => lightingData.blendPreserveSpecular = newValue); + context.globalIndentLevel--; + } + + // Alpha Test + // TODO: AlphaTest is in SystemData but Alpha to Mask is in BuiltinData? + AddProperty(alphaCutoffEnableText, () => systemData.alphaTest, (newValue) => systemData.alphaTest = newValue); + AddProperty(useShadowThresholdText, () => builtinData.alphaTestShadow, (newValue) => builtinData.alphaTestShadow = newValue); + AddProperty(alphaToMaskText, () => builtinData.alphaToMask, (newValue) => builtinData.alphaToMask = newValue); + AddProperty(alphaToMaskText, () => builtinData.alphaToMask, (newValue) => builtinData.alphaToMask = newValue); + + // Misc + AddProperty(doubleSidedNormalModeText, () => systemData.doubleSidedMode, (newValue) => systemData.doubleSidedMode = newValue); + if (lightingData != null) + AddProperty(Styles.fragmentNormalSpace, () => lightingData.normalDropOffSpace, (newValue) => lightingData.normalDropOffSpace = newValue); + + // Misc Cont. + if (lightingData != null) + { + AddProperty(supportDecalsText, () => lightingData.receiveDecals, (newValue) => lightingData.receiveDecals = newValue); + AddProperty(receivesSSRText, () => lightingData.receiveSSR, (newValue) => lightingData.receiveSSR = newValue); + AddProperty(enableGeometricSpecularAAText, () => lightingData.specularAA, (newValue) => lightingData.specularAA = newValue); + } + AddProperty(depthOffsetEnableText, () => builtinData.depthOffset, (newValue) => builtinData.depthOffset = newValue); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs.meta new file mode 100644 index 00000000000..cb3a746ffdf --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cc62914ce909bf94f8b31d46a1ad9778 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs index d334a6266d1..1705246a10f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs @@ -34,7 +34,47 @@ protected override string renderQueue { get => HDRenderQueue.GetShaderTagValue(HDRenderQueue.ChangeType(systemData.renderingPass, systemData.sortPriority, systemData.alphaTest)); } - + + public override void GetFields(ref TargetFieldContext context) + { + base.GetFields(ref context); + + // Common properties between all "surface" master nodes (everything except decal right now) + + // Blend Mode + context.AddField(Fields.BlendAdd, systemData.surfaceType != SurfaceType.Opaque && systemData.blendMode == BlendMode.Additive); + context.AddField(Fields.BlendAlpha, systemData.surfaceType != SurfaceType.Opaque && systemData.blendMode == BlendMode.Alpha); + context.AddField(Fields.BlendPremultiply, systemData.surfaceType != SurfaceType.Opaque && systemData.blendMode == BlendMode.Premultiply); + + // We always generate the keyword ALPHATEST_ON + context.AddField(Fields.AlphaTest, systemData.alphaTest + && (context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold) + || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow) + || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass) + || context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass))); + + // Double Sided + context.AddField(HDFields.DoubleSided, systemData.doubleSidedMode != DoubleSidedMode.Disabled); + + context.AddField(HDFields.DoAlphaTestPrepass, systemData.alphaTest && systemData.alphaTestDepthPrepass + && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass)); + context.AddField(HDFields.DoAlphaTestPostpass, systemData.alphaTest && systemData.alphaTestDepthPostpass + && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass)); + + context.AddField(HDFields.TransparentDepthPrePass, systemData.surfaceType != SurfaceType.Opaque && systemData.alphaTestDepthPrepass); + context.AddField(HDFields.TransparentDepthPostPass, systemData.surfaceType != SurfaceType.Opaque && systemData.alphaTestDepthPostpass); + + // Features & Misc + context.AddField(Fields.LodCrossFade, systemData.supportLodCrossFade); + context.AddField(Fields.VelocityPrecomputed, builtinData.addPrecomputedVelocity); + context.AddField(HDFields.TransparentWritesMotionVec, systemData.surfaceType != SurfaceType.Opaque && builtinData.transparentWritesMotionVec); + context.AddField(Fields.AlphaToMask, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold) && builtinData.alphaToMask); + context.AddField(HDFields.DepthOffset, builtinData.depthOffset && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.DepthOffset)); + context.AddField(HDFields.AlphaFog, systemData.surfaceType != SurfaceType.Opaque && builtinData.transparencyFog); + context.AddField(HDFields.DoAlphaTestShadow, systemData.alphaTest && builtinData.alphaTestShadow && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow)); + context.AddField(HDFields.TransparentBackFace, systemData.surfaceType != SurfaceType.Opaque && builtinData.backThenFrontRendering); + } + protected void AddDistortionFields(ref TargetFieldContext context) { // Distortion @@ -45,31 +85,15 @@ protected void AddDistortionFields(ref TargetFieldContext context) context.AddField(HDFields.TransparentDistortion, systemData.surfaceType != SurfaceType.Opaque && builtinData.distortion); } - protected void AddSurfaceMiscFields(ref TargetFieldContext context) - { - context.AddField(Fields.AlphaToMask, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold) && builtinData.alphaToMask); - context.AddField(HDFields.AlphaFog, systemData.surfaceType != SurfaceType.Opaque && builtinData.transparencyFog); - context.AddField(Fields.VelocityPrecomputed, builtinData.addPrecomputedVelocity); - context.AddField(HDFields.TransparentWritesMotionVec, systemData.surfaceType != SurfaceType.Opaque && builtinData.transparentWritesMotionVec); - context.AddField(HDFields.DepthOffset, builtinData.depthOffset && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.DepthOffset)); - } - - /// Add vertex inputs for standard surface shader - protected void AddVertexBlocks(ref TargetActiveBlockContext context) + public override void GetActiveBlocks(ref TargetActiveBlockContext context) { + // Common block between all "surface" master nodes + // Vertex context.AddBlock(BlockFields.VertexDescription.Position); context.AddBlock(BlockFields.VertexDescription.Normal); context.AddBlock(BlockFields.VertexDescription.Tangent); - } - protected void AddDistortionBlocks(ref TargetActiveBlockContext context) - { - context.AddBlock(HDBlockFields.SurfaceDescription.Distortion, systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); - context.AddBlock(HDBlockFields.SurfaceDescription.DistortionBlur, systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); - } - - protected void AddSurfaceBlocks(ref TargetActiveBlockContext context) - { + // Surface context.AddBlock(BlockFields.SurfaceDescription.BaseColor); context.AddBlock(BlockFields.SurfaceDescription.Emission); context.AddBlock(BlockFields.SurfaceDescription.Alpha); @@ -83,5 +107,62 @@ protected void AddSurfaceBlocks(ref TargetActiveBlockContext context) // Misc context.AddBlock(HDBlockFields.SurfaceDescription.DepthOffset, builtinData.depthOffset); } + + protected void AddDistortionBlocks(ref TargetActiveBlockContext context) + { + context.AddBlock(HDBlockFields.SurfaceDescription.Distortion, systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); + context.AddBlock(HDBlockFields.SurfaceDescription.DistortionBlur, systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); + } + + public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) + { + // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. + // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 + // The user will then need to explicitly disable emissive GI if it is not needed. + // To be able to automatically disable emission based on the ShaderGraph config when emission is black, + // we will need a more general way to communicate this to the engine (not directly tied to a material property). + collector.AddShaderProperty(new ColorShaderProperty() + { + overrideReferenceName = "_EmissionColor", + hidden = true, + value = new Color(1.0f, 1.0f, 1.0f, 1.0f) + }); + // ShaderGraph only property used to send the RenderQueueType to the material + collector.AddShaderProperty(new Vector1ShaderProperty + { + overrideReferenceName = "_RenderQueueType", + hidden = true, + value = (int)systemData.renderingPass, + }); + + //See SG-ADDITIONALVELOCITY-NOTE + if (builtinData.addPrecomputedVelocity) + { + collector.AddShaderProperty(new BooleanShaderProperty + { + value = true, + hidden = true, + overrideReferenceName = kAddPrecomputedVelocity, + }); + } + + // Common properties for all "surface" master nodes + HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, builtinData.alphaTestShadow); + HDSubShaderUtilities.AddDoubleSidedProperty(collector, systemData.doubleSidedMode); + + // Add all shader properties required by the inspector + HDSubShaderUtilities.AddBlendingStatesShaderProperties( + collector, + systemData.surfaceType, + systemData.blendMode, + systemData.sortPriority, + builtinData.alphaToMask, + systemData.zWrite, + systemData.transparentCullMode, + systemData.zTest, + builtinData.backThenFrontRendering, + builtinData.transparencyFog + ); + } } } \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs index 42d03908cfe..34c73aa3ae8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs @@ -158,11 +158,8 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { - AddSystemDataFields(ref context); - AddNormalDropOffFields(ref context); + base.GetFields(ref context); AddDistortionFields(ref context); - AddLitMiscFields(ref context); - AddSurfaceMiscFields(ref context); // StackLit specific properties context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(StackLitSubTarget.StackLitPasses.MotionVectors)); @@ -288,8 +285,7 @@ public override void GetFields(ref TargetFieldContext context) public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - AddVertexBlocks(ref context); - AddSurfaceBlocks(ref context); + base.GetActiveBlocks(ref context); AddNormalBlocks(ref context); AddDistortionBlocks(ref context); @@ -350,14 +346,16 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(HDBlockFields.SurfaceDescription.SpecularAAThreshold, stackLitData.geometricSpecularAA); } - public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) + protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { - var settingsView = new StackLitSettingsView(this); - settingsView.GetPropertiesGUI(ref context, onChange, registerUndo); + // TODO + // blockList.AddPropertyBlock(new DecalPropertyBlock()); } public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) { + base.CollectShaderProperties(collector, generationMode); + if (stackLitData.debug) { // We have useful debug options in StackLit, so add them always, and let the UI editor (non shadergraph) handle displaying them @@ -399,46 +397,6 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera value = new Vector4(2.0f, 2.0f, 1.0f, 2.0f) }); } - - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (builtinData.addPrecomputedVelocity) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } - - // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, lightingData.subsurfaceScattering, lightingData.receiveSSR); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - systemData.surfaceType, - systemData.blendMode, - systemData.sortPriority, - builtinData.alphaToMask, - systemData.zWrite, - systemData.transparentCullMode, - systemData.zTest, - false, - builtinData.transparencyFog - ); - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, false); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, systemData.doubleSidedMode); } public override void ProcessPreviewMaterial(Material material) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DistortionUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DistortionUIBlock.cs index cdcf1add479..a77a4ae9bc6 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DistortionUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DistortionUIBlock.cs @@ -7,7 +7,7 @@ namespace UnityEditor.Rendering.HighDefinition { class DistortionUIBlock : MaterialUIBlock { - protected static class Styles + internal static class Styles { public static GUIContent distortionEnableText = new GUIContent("Distortion", "When enabled, HDRP processes distortion for this Material."); public static GUIContent distortionOnlyText = new GUIContent("Distortion Only", "When enabled, HDRP only uses this Material to render distortion."); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs index 22804b829bd..52993cd879a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/RefractionUIBlock.cs @@ -10,7 +10,7 @@ namespace UnityEditor.Rendering.HighDefinition { class RefractionUIBlock : MaterialUIBlock { - protected static class Styles + internal static class Styles { public static string refractionModelText = "Refraction Model"; public static GUIContent refractionIorText = new GUIContent("Index Of Refraction", "Controls the index of refraction for this Material."); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs index 0d030662fa1..09703769abf 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/SurfaceOptionUIBlock.cs @@ -9,7 +9,7 @@ namespace UnityEditor.Rendering.HighDefinition { - class SurfaceOptionUIBlock : MaterialUIBlock + internal class SurfaceOptionUIBlock : MaterialUIBlock { [Flags] public enum Features @@ -31,7 +31,7 @@ public enum Features All = ~0, } - static class Styles + internal static class Styles { public const string optionText = "Surface Options"; public const string surfaceTypeText = "Surface Type"; @@ -575,7 +575,7 @@ void SurfaceTypePopup() var newMode = (SurfaceType)EditorGUILayout.Popup(Styles.surfaceTypeText, (int)mode, Styles.surfaceTypeNames); if (newMode != mode) //EditorGUI.EndChangeCheck is called even if value remain the same after the popup. Prefer not to use it here { - materialEditor.RegisterPropertyChangeUndo("Surface Type"); + materialEditor.RegisterPropertyChangeUndo(Styles.surfaceTypeText); surfaceType.floatValue = (float)newMode; HDRenderQueue.RenderQueueType targetQueueType; switch(newMode) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs index 48e3e508389..807b7946109 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs @@ -49,8 +49,8 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { + base.GetFields(ref context); AddDistortionFields(ref context); - AddSurfaceMiscFields(ref context); // Unlit specific properties context.AddField(HDFields.EnableShadowMatte, unlitData.enableShadowMatte); @@ -59,54 +59,22 @@ public override void GetFields(ref TargetFieldContext context) public override void GetActiveBlocks(ref TargetActiveBlockContext context) { - AddVertexBlocks(ref context); + base.GetActiveBlocks(ref context); AddDistortionBlocks(ref context); - AddSurfaceBlocks(ref context); // Unlit specific blocks context.AddBlock(HDBlockFields.SurfaceDescription.ShadowTint, unlitData.enableShadowMatte); } - public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) + protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { - // TODO: refactor - var settingsView = new HDUnlitSettingsView(this); - settingsView.GetPropertiesGUI(ref context, onChange, registerUndo); + // blockList.AddPropertyBlock(new DecalPropertyBlock()); } public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) { - // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. - // ShaderGraph doesn't use this property, so currently it inserts a dummy color (white). This dummy color may be removed entirely once the following PR has been merged in trunk: Pull request #74105 - // The user will then need to explicitly disable emissive GI if it is not needed. - // To be able to automatically disable emission based on the ShaderGraph config when emission is black, - // we will need a more general way to communicate this to the engine (not directly tied to a material property). - collector.AddShaderProperty(new ColorShaderProperty() - { - overrideReferenceName = "_EmissionColor", - hidden = true, - value = new Color(1.0f, 1.0f, 1.0f, 1.0f) - }); - - // ShaderGraph only property used to send the RenderQueueType to the material - collector.AddShaderProperty(new Vector1ShaderProperty - { - overrideReferenceName = "_RenderQueueType", - hidden = true, - value = (int)systemData.renderingPass, - }); - - //See SG-ADDITIONALVELOCITY-NOTE - if (builtinData.addPrecomputedVelocity) - { - collector.AddShaderProperty(new BooleanShaderProperty - { - value = true, - hidden = true, - overrideReferenceName = kAddPrecomputedVelocity, - }); - } - + base.CollectShaderProperties(collector, generationMode); + if (unlitData.enableShadowMatte) { uint mantissa = ((uint)LightFeatureFlags.Punctual | (uint)LightFeatureFlags.Directional | (uint)LightFeatureFlags.Area) & 0x007FFFFFu; @@ -119,23 +87,8 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera }); } - // Add all shader properties required by the inspector + // Stencil state for unlit: HDSubShaderUtilities.AddStencilShaderProperties(collector, false, false); - HDSubShaderUtilities.AddBlendingStatesShaderProperties( - collector, - systemData.surfaceType, - systemData.blendMode, - systemData.sortPriority, - systemData.alphaTest, - systemData.zWrite, - systemData.transparentCullMode, - systemData.zTest, - false, - builtinData.transparencyFog - ); - - HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, false); - HDSubShaderUtilities.AddDoubleSidedProperty(collector, systemData.doubleSidedMode); } public override void ProcessPreviewMaterial(Material material) diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs index 61d9bc312ac..5d26d4d0ddb 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs @@ -141,7 +141,9 @@ public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Acti { if(m_ActiveSubTarget.value == null) return; - + + context.globalIndentLevel++; + // Core properties m_SubTargetField = new PopupField(m_SubTargetNames, activeSubTargetIndex); context.AddProperty("Material", m_SubTargetField, (evt) => @@ -175,6 +177,8 @@ public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Acti onChange(); }); context.AddProperty("Custom Editor GUI", m_CustomGUIField, (evt) => {}); + + context.globalIndentLevel--; } public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs index 1ba6b8061cf..e9a8553e86c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs @@ -39,6 +39,14 @@ public bool receiveSSR set => m_ReceiveSSR = value; } + [SerializeField] + bool m_ReceiveSSRTransparent = false; + public bool receiveSSRTransparent + { + get => m_ReceiveSSRTransparent; + set => m_ReceiveSSRTransparent = value; + } + [SerializeField] bool m_EnergyConservingSpecular = true; public bool energyConservingSpecular diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/SystemData.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/SystemData.cs index ab61e7b4976..639a49cd148 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/SystemData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/SystemData.cs @@ -123,6 +123,8 @@ public bool dotsInstancing get => m_DOTSInstancing; set => m_DOTSInstancing = value; } + + internal int inspectorFoldoutMask; } static class HDSystemDataExtensions From fe1c5341858d86003c1a7d02fdc92ab6e846d8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Tue, 26 May 2020 17:55:11 +0200 Subject: [PATCH 06/11] Fixed compilation --- .../Editor/Material/ShaderGraph/LightingSubTarget.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs index 72cbf449e37..69c04adf179 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs @@ -123,7 +123,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera base.CollectShaderProperties(collector, generationMode); // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, lightingData, systemData); + HDSubShaderUtilities.AddStencilShaderProperties(collector, systemData, lightingData); } } } \ No newline at end of file From 5d37b43daabdf38e04cfd65d80bf1272aa5c7a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Tue, 26 May 2020 18:35:37 +0200 Subject: [PATCH 07/11] Moved fabric subtarget GUI to new system --- .../Material/Fabric/ShaderGraph/FabricData.cs | 8 + .../Fabric/ShaderGraph/FabricSettingsView.cs | 241 ------------------ .../ShaderGraph/FabricSubTarget.Migration.cs | 2 +- .../Fabric/ShaderGraph/FabricSubTarget.cs | 6 +- .../FabricSurfaceOptionPropertyBlock.cs | 41 +++ ... FabricSurfaceOptionPropertyBlock.cs.meta} | 2 +- .../Material/Lit/ShaderGraph/HDLitData.cs | 8 + .../ShaderGraph/HDLitSubTarget.Migration.cs | 2 +- .../Lit/ShaderGraph/HDLitSubTarget.cs | 2 +- .../LitSurfaceOptionPropertyBlock.cs | 2 + .../AdvancedOptionsPropertyBlock.cs | 1 + .../StackLit/ShaderGraph/StackLitData.cs | 8 + .../ShaderGraph/StackLitSettingsView.cs | 6 +- .../StackLitSubTarget.Migration.cs | 2 +- .../StackLit/ShaderGraph/StackLitSubTarget.cs | 2 +- .../UIBlocks/LitSurfaceInputsUIBlock.cs | 1 + .../ShaderGraph/TargetData/LightingData.cs | 8 - 17 files changed, 81 insertions(+), 261 deletions(-) delete mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSettingsView.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSurfaceOptionPropertyBlock.cs rename com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/{FabricSettingsView.cs.meta => FabricSurfaceOptionPropertyBlock.cs.meta} (83%) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricData.cs index 3fc1e080f77..f5d4878eced 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricData.cs @@ -19,5 +19,13 @@ public MaterialType materialType get => m_MaterialType; set => m_MaterialType = value; } + + [SerializeField] + bool m_EnergyConservingSpecular = true; + public bool energyConservingSpecular + { + get => m_EnergyConservingSpecular; + set => m_EnergyConservingSpecular = value; + } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSettingsView.cs deleted file mode 100644 index fb227b13b26..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSettingsView.cs +++ /dev/null @@ -1,241 +0,0 @@ -using System; -using UnityEngine.Rendering; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; -using UnityEngine.UIElements; -using UnityEditor.UIElements; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - class FabricSettingsView - { - SystemData systemData; - BuiltinData builtinData; - LightingData lightingData; - FabricData fabricData; - - IntegerField m_SortPriorityField; - - public FabricSettingsView(FabricSubTarget subTarget) - { - systemData = subTarget.systemData; - builtinData = subTarget.builtinData; - lightingData = subTarget.lightingData; - fabricData = subTarget.fabricData; - } - - public void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) - { - // Render State - DoRenderStateArea(ref context, systemData, 0, onChange, registerUndo); - - // Alpha Test - // TODO: AlphaTest is in SystemData but Alpha to Mask is in BuiltinData? - context.AddProperty("Alpha Clipping", 0, new Toggle() { value = systemData.alphaTest }, (evt) => - { - if (Equals(systemData.alphaTest, evt.newValue)) - return; - - registerUndo("Alpha Clipping"); - systemData.alphaTest = evt.newValue; - onChange(); - }); - context.AddProperty("Alpha to Mask", 1, new Toggle() { value = builtinData.alphaToMask }, systemData.alphaTest, (evt) => - { - if (Equals(builtinData.alphaToMask, evt.newValue)) - return; - - registerUndo("Alpha to Mask"); - builtinData.alphaToMask = evt.newValue; - onChange(); - }); - - // Misc - context.AddProperty("Double-Sided Mode", 0, new EnumField(DoubleSidedMode.Disabled) { value = systemData.doubleSidedMode }, (evt) => - { - if (Equals(systemData.doubleSidedMode, evt.newValue)) - return; - - registerUndo("Double-Sided Mode"); - systemData.doubleSidedMode = (DoubleSidedMode)evt.newValue; - onChange(); - }); - context.AddProperty("Energy Conserving Specular", 0, new Toggle() { value = lightingData.energyConservingSpecular }, (evt) => - { - if (Equals(lightingData.energyConservingSpecular, evt.newValue)) - return; - - registerUndo("Energy Conserving Specular"); - lightingData.energyConservingSpecular = evt.newValue; - onChange(); - }); - context.AddProperty("Material Type", 0, new EnumField(FabricData.MaterialType.CottonWool) { value = fabricData.materialType }, (evt) => - { - if (Equals(fabricData.materialType, evt.newValue)) - return; - - registerUndo("Material Type"); - fabricData.materialType = (FabricData.MaterialType)evt.newValue; - onChange(); - }); - context.AddProperty("Subsurface Scattering", 0, new Toggle() { value = lightingData.subsurfaceScattering }, systemData.surfaceType != SurfaceType.Transparent, (evt) => - { - if (Equals(lightingData.subsurfaceScattering, evt.newValue)) - return; - - registerUndo("Subsurface Scattering"); - lightingData.subsurfaceScattering = evt.newValue; - onChange(); - }); - context.AddProperty("Transmission", 0, new Toggle() { value = lightingData.transmission }, (evt) => - { - if (Equals(lightingData.transmission, evt.newValue)) - return; - - registerUndo("Transmission"); - lightingData.transmission = evt.newValue; - onChange(); - }); - context.AddProperty("Receive Decals", 0, new Toggle() { value = lightingData.receiveDecals }, (evt) => - { - if (Equals(lightingData.receiveDecals, evt.newValue)) - return; - - registerUndo("Receive Decals"); - lightingData.receiveDecals = evt.newValue; - onChange(); - }); - context.AddProperty("Receive SSR", 0, new Toggle() { value = lightingData.receiveSSR }, (evt) => - { - if (Equals(lightingData.receiveSSR, evt.newValue)) - return; - - registerUndo("Receive SSR"); - lightingData.receiveSSR = evt.newValue; - onChange(); - }); - context.AddProperty("Add Precomputed Velocity", 0, new Toggle() { value = builtinData.addPrecomputedVelocity }, (evt) => - { - if (Equals(builtinData.addPrecomputedVelocity, evt.newValue)) - return; - - registerUndo("Add Precomputed Velocity"); - builtinData.addPrecomputedVelocity = evt.newValue; - onChange(); - }); - context.AddProperty("Specular Occlusion Mode", 0, new EnumField(SpecularOcclusionMode.Off) { value = lightingData.specularOcclusionMode }, (evt) => - { - if (Equals(lightingData.specularOcclusionMode, evt.newValue)) - return; - - registerUndo("Specular Occlusion Mode"); - lightingData.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; - onChange(); - }); - context.AddProperty("Override Baked GI", 0, new Toggle() { value = lightingData.overrideBakedGI }, (evt) => - { - if (Equals(lightingData.overrideBakedGI, evt.newValue)) - return; - - registerUndo("Override Baked GI"); - lightingData.overrideBakedGI = evt.newValue; - onChange(); - }); - context.AddProperty("Depth Offset", 0, new Toggle() { value = builtinData.depthOffset }, (evt) => - { - if (Equals(builtinData.depthOffset, evt.newValue)) - return; - - registerUndo("Depth Offset"); - builtinData.depthOffset = evt.newValue; - onChange(); - }); - context.AddProperty("Support LOD CrossFade", 0, new Toggle() { value = systemData.supportLodCrossFade }, (evt) => - { - if (Equals(systemData.supportLodCrossFade, evt.newValue)) - return; - - registerUndo("Support LOD CrossFade"); - systemData.supportLodCrossFade = evt.newValue; - onChange(); - }); - } - - void DoRenderStateArea(ref TargetPropertyGUIContext context, SystemData systemData, int indentLevel, Action onChange, Action registerUndo) - { - context.AddProperty("Surface Type", indentLevel, new EnumField(SurfaceType.Opaque) { value = systemData.surfaceType }, (evt) => - { - if (Equals(systemData.surfaceType, evt.newValue)) - return; - - registerUndo("Surface Type"); - systemData.surfaceType = (SurfaceType)evt.newValue; - systemData.TryChangeRenderingPass(systemData.renderingPass); - onChange(); - }); - - context.AddProperty("Blend Preserves Specular", indentLevel + 1, new Toggle() { value = lightingData.blendPreserveSpecular }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(lightingData.blendPreserveSpecular, evt.newValue)) - return; - - registerUndo("Blend Preserves Specular"); - lightingData.blendPreserveSpecular = evt.newValue; - onChange(); - }); - - context.AddProperty("Fog", indentLevel + 1, new Toggle() { value = builtinData.transparencyFog }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(builtinData.transparencyFog, evt.newValue)) - return; - - registerUndo("Fog"); - builtinData.transparencyFog = evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Test", indentLevel + 1, new EnumField(systemData.zTest) { value = systemData.zTest }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zTest, evt.newValue)) - return; - - registerUndo("Depth Test"); - systemData.zTest = (CompareFunction)evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Write", indentLevel + 1, new Toggle() { value = systemData.zWrite }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zWrite, evt.newValue)) - return; - - registerUndo("Depth Write"); - systemData.zWrite = evt.newValue; - onChange(); - }); - - context.AddProperty("Cull Mode", indentLevel + 1, new EnumField(systemData.transparentCullMode) { value = systemData.transparentCullMode }, systemData.surfaceType == SurfaceType.Transparent && systemData.doubleSidedMode == DoubleSidedMode.Disabled, (evt) => - { - if (Equals(systemData.transparentCullMode, evt.newValue)) - return; - - registerUndo("Cull Mode"); - systemData.transparentCullMode = (TransparentCullMode)evt.newValue; - onChange(); - }); - - m_SortPriorityField = new IntegerField() { value = systemData.sortPriority }; - context.AddProperty("Sorting Priority", indentLevel + 1, m_SortPriorityField, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - var newValue = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); - if (Equals(systemData.sortPriority, newValue)) - return; - - registerUndo("Sorting Priority"); - m_SortPriorityField.value = newValue; - systemData.sortPriority = evt.newValue; - onChange(); - }); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs index c926b9f1e7c..9608d2d2441 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs @@ -42,12 +42,12 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary this.fabricData = fabricData; + + protected override void CreatePropertyGUI() + { + AddProperty(Styles.materialType, () => fabricData.materialType, (newValue) => fabricData.materialType = newValue); + + base.CreatePropertyGUI(); + + // Fabric specific properties: + AddProperty(energyConservingSpecularColorText, () => fabricData.energyConservingSpecular, (newValue) => fabricData.energyConservingSpecular = newValue); + AddProperty(subsurfaceEnableText, () => lightingData.subsurfaceScattering, (newValue) => lightingData.subsurfaceScattering = newValue); + AddProperty(transmissionEnableText, () => lightingData.transmission, (newValue) => lightingData.transmission = newValue); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSettingsView.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSurfaceOptionPropertyBlock.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSettingsView.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSurfaceOptionPropertyBlock.cs.meta index 33bf72a5e24..17e924ca6d6 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSettingsView.cs.meta +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSurfaceOptionPropertyBlock.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: dbe8d40ff0e92474a8f400bfad8310bc +guid: 0ecbbfd0c8f45b046bd39742548eb207 MonoImporter: externalObjects: {} serializedVersion: 2 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 d5774952c9a..c3e2497f874 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 @@ -58,5 +58,13 @@ public bool sssTransmission // get => m_DiffusionProfile; // set => m_DiffusionProfile = value; // } + + [SerializeField] + bool m_EnergyConservingSpecular = true; + public bool energyConservingSpecular + { + get => m_EnergyConservingSpecular; + set => m_EnergyConservingSpecular = 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 ff595097c48..dd889cfe8de 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 @@ -123,12 +123,12 @@ void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary 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/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs index 384a2c44616..36ae9bca156 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs @@ -29,6 +29,7 @@ protected override void CreatePropertyGUI() AddProperty(specularOcclusionModeText, () => lightingData.specularOcclusionMode, (newValue) => lightingData.specularOcclusionMode = newValue); AddProperty(Styles.overrideBakedGI, () => lightingData.overrideBakedGI, (newValue) => lightingData.overrideBakedGI = newValue); AddProperty(Styles.supportLodCrossFade, () => systemData.supportLodCrossFade, (newValue) => systemData.supportLodCrossFade = newValue); + AddProperty(addPrecomputedVelocityText, () => builtinData.addPrecomputedVelocity, (newValue) => builtinData.addPrecomputedVelocity = newValue); } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitData.cs index 86644ac34f9..0d59695c8fc 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitData.cs @@ -266,5 +266,13 @@ public bool devMode get => m_DevMode; set => m_DevMode = value; } + + [SerializeField] + bool m_EnergyConservingSpecular = true; + public bool energyConservingSpecular + { + get => m_EnergyConservingSpecular; + set => m_EnergyConservingSpecular = value; + } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs index 9e46052ae22..abf721cc47e 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs @@ -111,13 +111,13 @@ public void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChan stackLitData.baseParametrization = (StackLit.BaseParametrization)evt.newValue; onChange(); }); - context.AddProperty("Energy Conserving Specular", 1, new Toggle() { value = lightingData.energyConservingSpecular }, stackLitData.baseParametrization == StackLit.BaseParametrization.SpecularColor, (evt) => + context.AddProperty("Energy Conserving Specular", 1, new Toggle() { value = stackLitData.energyConservingSpecular }, stackLitData.baseParametrization == StackLit.BaseParametrization.SpecularColor, (evt) => { - if (Equals(lightingData.energyConservingSpecular, evt.newValue)) + if (Equals(stackLitData.energyConservingSpecular, evt.newValue)) return; registerUndo("Energy Conserving Specular"); - lightingData.energyConservingSpecular = evt.newValue; + stackLitData.energyConservingSpecular = evt.newValue; onChange(); }); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs index a65e2593509..470dce52403 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs @@ -46,11 +46,11 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary m_ReceiveSSRTransparent = value; } - [SerializeField] - bool m_EnergyConservingSpecular = true; - public bool energyConservingSpecular - { - get => m_EnergyConservingSpecular; - set => m_EnergyConservingSpecular = value; - } - [SerializeField] bool m_Transmission = false; public bool transmission From 1ccbcba9c7de518bcefd3e08a671c0ef87df6889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Tue, 26 May 2020 19:51:18 +0200 Subject: [PATCH 08/11] Converted Eye and stacklit settings to new GUI system --- .../Eye/ShaderGraph/EyeSettingsView.cs | 241 -------- .../Material/Eye/ShaderGraph/EyeSubTarget.cs | 23 +- .../EyeSubrafceOptionPropertyBlock.cs | 39 ++ ...=> EyeSubrafceOptionPropertyBlock.cs.meta} | 2 +- .../Fabric/ShaderGraph/FabricSubTarget.cs | 20 - .../Hair/ShaderGraph/HairSubTarget.cs | 20 - .../Lit/ShaderGraph/HDLitSubTarget.cs | 21 +- .../ShaderGraph/SubTargetPropertyBlock.cs | 6 +- .../ShaderGraph/SurfaceOptionPropertyBlock.cs | 1 + .../Material/ShaderGraph/SurfaceSubTarget.cs | 18 + .../ShaderGraph/StackLitSettingsView.cs | 548 ------------------ .../StackLit/ShaderGraph/StackLitSubTarget.cs | 26 +- .../StackLitSurfaceOptionPropertyBlock.cs | 124 ++++ ...tackLitSurfaceOptionPropertyBlock.cs.meta} | 2 +- .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 21 +- .../Contexts/TargetPropertyGUIContext.cs | 4 +- 16 files changed, 201 insertions(+), 915 deletions(-) delete mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSettingsView.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubrafceOptionPropertyBlock.cs rename com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/{EyeSettingsView.cs.meta => EyeSubrafceOptionPropertyBlock.cs.meta} (83%) delete mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs rename com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/{StackLitSettingsView.cs.meta => StackLitSurfaceOptionPropertyBlock.cs.meta} (83%) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSettingsView.cs deleted file mode 100644 index 65179a7306a..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSettingsView.cs +++ /dev/null @@ -1,241 +0,0 @@ -using System; -using UnityEngine.Rendering; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; -using UnityEngine.UIElements; -using UnityEditor.UIElements; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - class EyeSettingsView - { - SystemData systemData; - BuiltinData builtinData; - LightingData lightingData; - EyeData eyeData; - - IntegerField m_SortPriorityField; - - public EyeSettingsView(EyeSubTarget subTarget) - { - systemData = subTarget.systemData; - builtinData = subTarget.builtinData; - lightingData = subTarget.lightingData; - eyeData = subTarget.eyeData; - } - - public void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) - { - // Render State - DoRenderStateArea(ref context, systemData, 0, onChange, registerUndo); - - // Alpha Test - // TODO: AlphaTest is in SystemData but Alpha to Mask is in BuiltinData? - context.AddProperty("Alpha Clipping", 0, new Toggle() { value = systemData.alphaTest }, (evt) => - { - if (Equals(systemData.alphaTest, evt.newValue)) - return; - - registerUndo("Alpha Clipping"); - systemData.alphaTest = evt.newValue; - onChange(); - }); - context.AddProperty("Alpha to Mask", 1, new Toggle() { value = builtinData.alphaToMask }, systemData.alphaTest, (evt) => - { - if (Equals(builtinData.alphaToMask, evt.newValue)) - return; - - registerUndo("Alpha to Mask"); - builtinData.alphaToMask = evt.newValue; - onChange(); - }); - context.AddProperty("Alpha Cutoff Depth Prepass", 1, new Toggle() { value = systemData.alphaTestDepthPrepass }, systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest, (evt) => - { - if (Equals(systemData.alphaTestDepthPrepass, evt.newValue)) - return; - - registerUndo("Alpha Cutoff Depth Prepass"); - systemData.alphaTestDepthPrepass = evt.newValue; - onChange(); - }); - context.AddProperty("Alpha Cutoff Depth Postpass", 1, new Toggle() { value = systemData.alphaTestDepthPostpass }, systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest, (evt) => - { - if (Equals(systemData.alphaTestDepthPostpass, evt.newValue)) - return; - - registerUndo("Alpha Cutoff Depth Postpass"); - systemData.alphaTestDepthPostpass = evt.newValue; - onChange(); - }); - - // Misc - context.AddProperty("Double-Sided Mode", 0, new EnumField(DoubleSidedMode.Disabled) { value = systemData.doubleSidedMode }, (evt) => - { - if (Equals(systemData.doubleSidedMode, evt.newValue)) - return; - - registerUndo("Double-Sided Mode"); - systemData.doubleSidedMode = (DoubleSidedMode)evt.newValue; - onChange(); - }); - context.AddProperty("Material Type", 0, new EnumField(EyeData.MaterialType.Eye) { value = eyeData.materialType }, (evt) => - { - if (Equals(eyeData.materialType, evt.newValue)) - return; - - registerUndo("Material Type"); - eyeData.materialType = (EyeData.MaterialType)evt.newValue; - onChange(); - }); - context.AddProperty("Subsurface Scattering", 0, new Toggle() { value = lightingData.subsurfaceScattering }, systemData.surfaceType != SurfaceType.Transparent, (evt) => - { - if (Equals(lightingData.subsurfaceScattering, evt.newValue)) - return; - - registerUndo("Subsurface Scattering"); - lightingData.subsurfaceScattering = evt.newValue; - onChange(); - }); - context.AddProperty("Receive Decals", 0, new Toggle() { value = lightingData.receiveDecals }, (evt) => - { - if (Equals(lightingData.receiveDecals, evt.newValue)) - return; - - registerUndo("Receive Decals"); - lightingData.receiveDecals = evt.newValue; - onChange(); - }); - context.AddProperty("Receive SSR", 0, new Toggle() { value = lightingData.receiveSSR }, (evt) => - { - if (Equals(lightingData.receiveSSR, evt.newValue)) - return; - - registerUndo("Receive SSR"); - lightingData.receiveSSR = evt.newValue; - onChange(); - }); - context.AddProperty("Add Precomputed Velocity", 0, new Toggle() { value = builtinData.addPrecomputedVelocity }, (evt) => - { - if (Equals(builtinData.addPrecomputedVelocity, evt.newValue)) - return; - - registerUndo("Add Precomputed Velocity"); - builtinData.addPrecomputedVelocity = evt.newValue; - onChange(); - }); - context.AddProperty("Specular Occlusion Mode", 0, new EnumField(SpecularOcclusionMode.Off) { value = lightingData.specularOcclusionMode }, (evt) => - { - if (Equals(lightingData.specularOcclusionMode, evt.newValue)) - return; - - registerUndo("Specular Occlusion Mode"); - lightingData.specularOcclusionMode = (SpecularOcclusionMode)evt.newValue; - onChange(); - }); - context.AddProperty("Override Baked GI", 0, new Toggle() { value = lightingData.overrideBakedGI }, (evt) => - { - if (Equals(lightingData.overrideBakedGI, evt.newValue)) - return; - - registerUndo("Override Baked GI"); - lightingData.overrideBakedGI = evt.newValue; - onChange(); - }); - context.AddProperty("Depth Offset", 0, new Toggle() { value = builtinData.depthOffset }, (evt) => - { - if (Equals(builtinData.depthOffset, evt.newValue)) - return; - - registerUndo("Depth Offset"); - builtinData.depthOffset = evt.newValue; - onChange(); - }); - context.AddProperty("Support LOD CrossFade", 0, new Toggle() { value = systemData.supportLodCrossFade }, (evt) => - { - if (Equals(systemData.supportLodCrossFade, evt.newValue)) - return; - - registerUndo("Support LOD CrossFade"); - systemData.supportLodCrossFade = evt.newValue; - onChange(); - }); - } - - void DoRenderStateArea(ref TargetPropertyGUIContext context, SystemData systemData, int indentLevel, Action onChange, Action registerUndo) - { - context.AddProperty("Surface Type", indentLevel, new EnumField(SurfaceType.Opaque) { value = systemData.surfaceType }, (evt) => - { - if (Equals(systemData.surfaceType, evt.newValue)) - return; - - registerUndo("Surface Type"); - systemData.surfaceType = (SurfaceType)evt.newValue; - systemData.TryChangeRenderingPass(systemData.renderingPass); - onChange(); - }); - - context.AddProperty("Blend Preserves Specular", indentLevel + 1, new Toggle() { value = lightingData.blendPreserveSpecular }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(lightingData.blendPreserveSpecular, evt.newValue)) - return; - - registerUndo("Blend Preserves Specular"); - lightingData.blendPreserveSpecular = evt.newValue; - onChange(); - }); - - context.AddProperty("Fog", indentLevel + 1, new Toggle() { value = builtinData.transparencyFog }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(builtinData.transparencyFog, evt.newValue)) - return; - - registerUndo("Fog"); - builtinData.transparencyFog = evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Test", indentLevel + 1, new EnumField(systemData.zTest) { value = systemData.zTest }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zTest, evt.newValue)) - return; - - registerUndo("Depth Test"); - systemData.zTest = (CompareFunction)evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Write", indentLevel + 1, new Toggle() { value = systemData.zWrite }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zWrite, evt.newValue)) - return; - - registerUndo("Depth Write"); - systemData.zWrite = evt.newValue; - onChange(); - }); - - context.AddProperty("Cull Mode", indentLevel + 1, new EnumField(systemData.transparentCullMode) { value = systemData.transparentCullMode }, systemData.surfaceType == SurfaceType.Transparent && systemData.doubleSidedMode == DoubleSidedMode.Disabled, (evt) => - { - if (Equals(systemData.transparentCullMode, evt.newValue)) - return; - - registerUndo("Cull Mode"); - systemData.transparentCullMode = (TransparentCullMode)evt.newValue; - onChange(); - }); - - m_SortPriorityField = new IntegerField() { value = systemData.sortPriority }; - context.AddProperty("Sorting Priority", indentLevel + 1, m_SortPriorityField, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - var newValue = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); - if (Equals(systemData.sortPriority, newValue)) - return; - - registerUndo("Sorting Priority"); - m_SortPriorityField.value = newValue; - systemData.sortPriority = evt.newValue; - onChange(); - }); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs index 7dfe2973b1a..5c70bd5e45d 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.cs @@ -69,27 +69,8 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { - // blockList.AddPropertyBlock(new DecalPropertyBlock()); - } - - public override void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)systemData.surfaceType); - material.SetFloat(kDoubleSidedNormalMode, (int)systemData.doubleSidedMode); - material.SetFloat(kDoubleSidedEnable, systemData.doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); - material.SetFloat(kAlphaCutoffEnabled, systemData.alphaTest ? 1 : 0); - material.SetFloat(kBlendMode, (int)systemData.blendMode); - material.SetFloat(kEnableFogOnTransparent, builtinData.transparencyFog ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)systemData.zTest); - material.SetFloat(kTransparentCullMode, (int)systemData.transparentCullMode); - material.SetFloat(kZWrite, systemData.zWrite ? 1.0f : 0.0f); - - // No sorting priority for shader graph preview - var renderingPass = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: systemData.alphaTest); - - EyeGUI.SetupMaterialKeywordsAndPass(material); + blockList.AddPropertyBlock(new EyeSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features.Lit, eyeData)); + blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); } #region SubShaders diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubrafceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubrafceOptionPropertyBlock.cs new file mode 100644 index 00000000000..2e23349ff3f --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubrafceOptionPropertyBlock.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine; + +// We share the name of the properties in the UI to avoid duplication +using static UnityEditor.Rendering.HighDefinition.LitSurfaceInputsUIBlock.Styles; +using static UnityEditor.Rendering.HighDefinition.SurfaceOptionUIBlock.Styles; +using static UnityEditor.Rendering.HighDefinition.RefractionUIBlock.Styles; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + class EyeSurfaceOptionPropertyBlock : SurfaceOptionPropertyBlock + { + class Styles + { + public static GUIContent materialType = new GUIContent("Material Type", "TODO"); + } + + EyeData eyeData; + + public EyeSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features features, EyeData eyeData) : base(features) + => this.eyeData = eyeData; + + protected override void CreatePropertyGUI() + { + AddProperty(Styles.materialType, () => eyeData.materialType, (newValue) => eyeData.materialType = newValue); + + base.CreatePropertyGUI(); + + // Eye specific properties: + AddProperty(subsurfaceEnableText, () => lightingData.subsurfaceScattering, (newValue) => lightingData.subsurfaceScattering = newValue); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSettingsView.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubrafceOptionPropertyBlock.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSettingsView.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubrafceOptionPropertyBlock.cs.meta index 717d7ea547c..93aa4315e03 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSettingsView.cs.meta +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubrafceOptionPropertyBlock.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a16e0965efec43748ab4d96982eebc60 +guid: 8457a6f490f4bd24cb340713da4c499c MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs index 919e9dddd1e..f886fb15a82 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.cs @@ -83,26 +83,6 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); } - public override void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)systemData.surfaceType); - material.SetFloat(kDoubleSidedNormalMode, (int)systemData.doubleSidedMode); - material.SetFloat(kDoubleSidedEnable, systemData.doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); - material.SetFloat(kAlphaCutoffEnabled, systemData.alphaTest ? 1 : 0); - material.SetFloat(kBlendMode, (int)systemData.blendMode); - material.SetFloat(kEnableFogOnTransparent, builtinData.transparencyFog ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)systemData.zTest); - material.SetFloat(kTransparentCullMode, (int)systemData.transparentCullMode); - material.SetFloat(kZWrite, systemData.zWrite ? 1.0f : 0.0f); - - // No sorting priority for shader graph preview - var renderingPass = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: systemData.alphaTest); - - FabricGUI.SetupMaterialKeywordsAndPass(material); - } - #region SubShaders static class SubShaders { diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs index 0f1eb11e8db..3af25e2b8cf 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.cs @@ -92,26 +92,6 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL blockList.AddPropertyBlock(new HairAdvancedOptionsPropertyBlock(hairData)); } - public override void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)systemData.surfaceType); - material.SetFloat(kDoubleSidedNormalMode, (int)systemData.doubleSidedMode); - material.SetFloat(kDoubleSidedEnable, systemData.doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); - material.SetFloat(kAlphaCutoffEnabled, systemData.alphaTest ? 1 : 0); - material.SetFloat(kBlendMode, (int)systemData.blendMode); - material.SetFloat(kEnableFogOnTransparent, builtinData.transparencyFog ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)systemData.zTest); - material.SetFloat(kTransparentCullMode, (int)systemData.transparentCullMode); - material.SetFloat(kZWrite, systemData.zWrite ? 1.0f : 0.0f); - - // No sorting priority for shader graph preview - var renderingPass = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: systemData.alphaTest); - - HairGUI.SetupMaterialKeywordsAndPass(material); - } - #region SubShaders static class SubShaders { 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 a351513753d..d4a500fe4ce 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 @@ -131,28 +131,11 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { blockList.AddPropertyBlock(new LitSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features.Lit, litData)); - blockList.AddPropertyBlock(new DistortionPropertyBlock()); + if (systemData.surfaceType == SurfaceType.Transparent) + blockList.AddPropertyBlock(new DistortionPropertyBlock()); blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); } - public override void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)systemData.surfaceType); - material.SetFloat(kDoubleSidedNormalMode, (int)systemData.doubleSidedMode); - material.SetFloat(kAlphaCutoffEnabled, systemData.alphaTest ? 1 : 0); - material.SetFloat(kBlendMode, (int)systemData.blendMode); - material.SetFloat(kEnableFogOnTransparent, builtinData.transparencyFog ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)systemData.zTest); - material.SetFloat(kTransparentCullMode, (int)systemData.transparentCullMode); - material.SetFloat(kZWrite, systemData.zWrite ? 1.0f : 0.0f); - - // No sorting priority for shader graph preview - material.renderQueue = (int)HDRenderQueue.ChangeType(systemData.renderingPass, offset: 0, alphaTest: systemData.alphaTest); - - HDLitGUI.SetupMaterialKeywordsAndPass(material); - } - protected override int ComputeMaterialNeedsUpdateHash() { bool subsurfaceScattering = litData.materialType == HDLitData.MaterialType.SubsurfaceScattering; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs index 58b4cdaa9c0..f264df1f5a3 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SubTargetPropertyBlock.cs @@ -59,7 +59,11 @@ protected void AddProperty(GUIContent displayName, Func getter, Acti case DistortionMode e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; case ScreenSpaceRefraction.RefractionModel e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; case SpecularOcclusionMode e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; - default: throw new Exception($"Can't create UI field for type {getter().GetType()}, please add it if it's relevant."); + case FabricData.MaterialType e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case EyeData.MaterialType e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case StackLit.BaseParametrization e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + case StackLit.DualSpecularLobeParametrization e: elemEnum = new EnumField(e) { value = e, tooltip = displayName.tooltip } as BaseField; break; + default: throw new Exception($"Can't create UI field for type {getter().GetType()}, please add it if it's relevant. If you can't consider using TargetPropertyGUIContext.AddProperty instead."); } if (elem != null) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs index 784240e6f59..c674490e8fe 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs @@ -15,6 +15,7 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph class SurfaceOptionPropertyBlock : SubTargetPropertyBlock { [Flags] + // TODO: remove ? public enum Features { None = 0, diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs index 1705246a10f..fb6dedee2cb 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs @@ -164,5 +164,23 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera builtinData.transparencyFog ); } + + public override void ProcessPreviewMaterial(Material material) + { + // Fixup the material settings: + material.SetFloat(kSurfaceType, (int)systemData.surfaceType); + material.SetFloat(kDoubleSidedNormalMode, (int)systemData.doubleSidedMode); + material.SetFloat(kAlphaCutoffEnabled, systemData.alphaTest ? 1 : 0); + material.SetFloat(kBlendMode, (int)systemData.blendMode); + material.SetFloat(kEnableFogOnTransparent, builtinData.transparencyFog ? 1.0f : 0.0f); + material.SetFloat(kZTestTransparent, (int)systemData.zTest); + material.SetFloat(kTransparentCullMode, (int)systemData.transparentCullMode); + material.SetFloat(kZWrite, systemData.zWrite ? 1.0f : 0.0f); + + // No sorting priority for shader graph preview + material.renderQueue = (int)HDRenderQueue.ChangeType(systemData.renderingPass, offset: 0, alphaTest: systemData.alphaTest); + + HDLitGUI.SetupMaterialKeywordsAndPass(material); + } } } \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs deleted file mode 100644 index abf721cc47e..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs +++ /dev/null @@ -1,548 +0,0 @@ -using System; -using UnityEngine.Rendering; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; -using UnityEngine.UIElements; -using UnityEditor.UIElements; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - class StackLitSettingsView - { - SystemData systemData; - BuiltinData builtinData; - LightingData lightingData; - StackLitData stackLitData; - - IntegerField m_SortPriorityField; - - public StackLitSettingsView(StackLitSubTarget subTarget) - { - systemData = subTarget.systemData; - builtinData = subTarget.builtinData; - lightingData = subTarget.lightingData; - stackLitData = subTarget.stackLitData; - } - - public void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) - { - // Render State - DoRenderStateArea(ref context, 0, onChange, registerUndo); - - // Distortion - if(systemData.surfaceType == SurfaceType.Transparent) - { - DoDistortionArea(ref context, 1, onChange, registerUndo); - } - - // Alpha Test - // TODO: AlphaTest is in SystemData but Alpha to Mask is in BuiltinData? - context.AddProperty("Alpha Clipping", 0, new Toggle() { value = systemData.alphaTest }, (evt) => - { - if (Equals(systemData.alphaTest, evt.newValue)) - return; - - registerUndo("Alpha Clipping"); - systemData.alphaTest = evt.newValue; - onChange(); - }); - context.AddProperty("Alpha to Mask", 1, new Toggle() { value = builtinData.alphaToMask }, systemData.alphaTest, (evt) => - { - if (Equals(builtinData.alphaToMask, evt.newValue)) - return; - - registerUndo("Alpha to Mask"); - builtinData.alphaToMask = evt.newValue; - onChange(); - }); - - // Misc - context.AddProperty("Double-Sided Mode", 0, new EnumField(DoubleSidedMode.Disabled) { value = systemData.doubleSidedMode }, (evt) => - { - if (Equals(systemData.doubleSidedMode, evt.newValue)) - return; - - registerUndo("Double-Sided Mode"); - systemData.doubleSidedMode = (DoubleSidedMode)evt.newValue; - onChange(); - }); - context.AddProperty("Fragment Normal Space", 0, new EnumField(NormalDropOffSpace.Tangent) { value = lightingData.normalDropOffSpace }, (evt) => - { - if (Equals(lightingData.normalDropOffSpace, evt.newValue)) - return; - - registerUndo("Fragment Normal Space"); - lightingData.normalDropOffSpace = (NormalDropOffSpace)evt.newValue; - onChange(); - }); - - // Rest of UI looks like this: - // - // baseParametrization - // energyConservingSpecular - // - // anisotropy - // coat - // coatNormal - // dualSpecularLobe - // dualSpecularLobeParametrization - // capHazinessWrtMetallic - // iridescence - // subsurfaceScattering - // transmission - // - // receiveDecals - // receiveSSR - // addPrecomputedVelocity - // geometricSpecularAA - // specularOcclusion - // - // anisotropyForAreaLights - // recomputeStackPerLight - // shadeBaseUsingRefractedAngles - - // Base parametrization: - context.AddProperty("Base Color Parametrization", 0, new EnumField(StackLit.BaseParametrization.BaseMetallic) { value = stackLitData.baseParametrization }, (evt) => - { - if (Equals(stackLitData.baseParametrization, evt.newValue)) - return; - - registerUndo("Base Color Parametrization"); - stackLitData.baseParametrization = (StackLit.BaseParametrization)evt.newValue; - onChange(); - }); - context.AddProperty("Energy Conserving Specular", 1, new Toggle() { value = stackLitData.energyConservingSpecular }, stackLitData.baseParametrization == StackLit.BaseParametrization.SpecularColor, (evt) => - { - if (Equals(stackLitData.energyConservingSpecular, evt.newValue)) - return; - - registerUndo("Energy Conserving Specular"); - stackLitData.energyConservingSpecular = evt.newValue; - onChange(); - }); - - // Material type enables: - context.AddLabel("Material Core Features", 0); - context.AddProperty("Anisotropy", 1, new Toggle() { value = stackLitData.anisotropy }, (evt) => - { - if (Equals(stackLitData.anisotropy, evt.newValue)) - return; - - registerUndo("Anisotropy"); - stackLitData.anisotropy = evt.newValue; - onChange(); - }); - context.AddProperty("Coat", 1, new Toggle() { value = stackLitData.coat }, (evt) => - { - if (Equals(stackLitData.coat, evt.newValue)) - return; - - registerUndo("Coat"); - stackLitData.coat = evt.newValue; - onChange(); - }); - context.AddProperty("Coat Normal", 2, new Toggle() { value = stackLitData.coatNormal }, stackLitData.coat, (evt) => - { - if (Equals(stackLitData.coatNormal, evt.newValue)) - return; - - registerUndo("Coat Normal"); - stackLitData.coatNormal = evt.newValue; - onChange(); - }); - context.AddProperty("Dual Specular Lobe", 1, new Toggle() { value = stackLitData.dualSpecularLobe }, (evt) => - { - if (Equals(stackLitData.dualSpecularLobe, evt.newValue)) - return; - - registerUndo("Dual Specular Lobe"); - stackLitData.dualSpecularLobe = evt.newValue; - onChange(); - }); - context.AddProperty("Dual SpecularLobe Parametrization", 2, new EnumField(StackLit.DualSpecularLobeParametrization.HazyGloss) { value = stackLitData.dualSpecularLobeParametrization }, stackLitData.dualSpecularLobe, (evt) => - { - if (Equals(stackLitData.dualSpecularLobeParametrization, evt.newValue)) - return; - - registerUndo("Dual SpecularLobe Parametrization"); - stackLitData.dualSpecularLobeParametrization = (StackLit.DualSpecularLobeParametrization)evt.newValue; - onChange(); - }); - var capHazinessForNonMetallic = stackLitData.dualSpecularLobe && (stackLitData.baseParametrization == StackLit.BaseParametrization.BaseMetallic) && (stackLitData.dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss); - context.AddProperty("Cap Haziness For Non Metallic", 2, new Toggle() { value = stackLitData.capHazinessWrtMetallic }, capHazinessForNonMetallic, (evt) => - { - if (Equals(stackLitData.capHazinessWrtMetallic, evt.newValue)) - return; - - registerUndo("Cap Haziness For Non Metallic"); - stackLitData.capHazinessWrtMetallic = evt.newValue; - onChange(); - }); - context.AddProperty("Iridescence", 1, new Toggle() { value = stackLitData.iridescence }, (evt) => - { - if (Equals(stackLitData.iridescence, evt.newValue)) - return; - - registerUndo("Iridescence"); - stackLitData.iridescence = evt.newValue; - onChange(); - }); - context.AddProperty("Subsurface Scattering", 1, new Toggle() { value = lightingData.subsurfaceScattering }, systemData.surfaceType != SurfaceType.Transparent, (evt) => - { - if (Equals(lightingData.subsurfaceScattering, evt.newValue)) - return; - - registerUndo("Subsurface Scattering"); - lightingData.subsurfaceScattering = evt.newValue; - onChange(); - }); - context.AddProperty("Transmission", 1, new Toggle() { value = lightingData.transmission }, (evt) => - { - if (Equals(lightingData.transmission, evt.newValue)) - return; - - registerUndo("Transmission"); - lightingData.transmission = evt.newValue; - onChange(); - }); - - // Misc - context.AddProperty("Receive Decals", 0, new Toggle() { value = lightingData.receiveDecals }, (evt) => - { - if (Equals(lightingData.receiveDecals, evt.newValue)) - return; - - registerUndo("Receive Decals"); - lightingData.receiveDecals = evt.newValue; - onChange(); - }); - context.AddProperty("Receive SSR", 0, new Toggle() { value = lightingData.receiveSSR }, (evt) => - { - if (Equals(lightingData.receiveSSR, evt.newValue)) - return; - - registerUndo("Receive SSR"); - lightingData.receiveSSR = evt.newValue; - onChange(); - }); - context.AddProperty("Add Precomputed Velocity", 0, new Toggle() { value = builtinData.addPrecomputedVelocity }, (evt) => - { - if (Equals(builtinData.addPrecomputedVelocity, evt.newValue)) - return; - - registerUndo("Add Precomputed Velocity"); - builtinData.addPrecomputedVelocity = evt.newValue; - onChange(); - }); - // TODO: Can this use lightingData.specularAA? - context.AddProperty("Geometric Specular AA", 0, new Toggle() { value = stackLitData.geometricSpecularAA }, (evt) => - { - if (Equals(stackLitData.geometricSpecularAA, evt.newValue)) - return; - - registerUndo("Geometric Specular AA"); - stackLitData.geometricSpecularAA = evt.newValue; - onChange(); - }); - - // SpecularOcclusion from SSAO - context.AddProperty("Specular Occlusion (from SSAO)", 0, new EnumField(StackLitData.SpecularOcclusionBaseMode.DirectFromAO) { value = stackLitData.screenSpaceSpecularOcclusionBaseMode }, stackLitData.devMode, (evt) => - { - if (Equals(stackLitData.screenSpaceSpecularOcclusionBaseMode, evt.newValue)) - return; - - registerUndo("Specular Occlusion (from SSAO)"); - stackLitData.screenSpaceSpecularOcclusionBaseMode = (StackLitData.SpecularOcclusionBaseMode)evt.newValue; - onChange(); - }); - var specularOcclusionSSUsesVisibilityCone = stackLitData.devMode && StackLitSubTarget.SpecularOcclusionModeUsesVisibilityCone(stackLitData.screenSpaceSpecularOcclusionBaseMode); - context.AddProperty("Specular Occlusion (SS) AO Cone Weight", 1, new EnumField(StackLitData.SpecularOcclusionAOConeSize.CosWeightedAO) { value = stackLitData.screenSpaceSpecularOcclusionAOConeSize }, specularOcclusionSSUsesVisibilityCone, (evt) => - { - if (Equals(stackLitData.screenSpaceSpecularOcclusionAOConeSize, evt.newValue)) - return; - - registerUndo("Specular Occlusion (SS) AO Cone Weight"); - stackLitData.screenSpaceSpecularOcclusionAOConeSize = (StackLitData.SpecularOcclusionAOConeSize)evt.newValue; - onChange(); - }); - context.AddProperty("Specular Occlusion (SS) AO Cone Dir", 1, new EnumField(StackLitData.SpecularOcclusionAOConeDir.ShadingNormal) { value = stackLitData.screenSpaceSpecularOcclusionAOConeDir }, specularOcclusionSSUsesVisibilityCone, (evt) => - { - if (Equals(stackLitData.screenSpaceSpecularOcclusionAOConeDir, evt.newValue)) - return; - - registerUndo("Specular Occlusion (SS) AO Cone Dir"); - stackLitData.screenSpaceSpecularOcclusionAOConeDir = (StackLitData.SpecularOcclusionAOConeDir)evt.newValue; - onChange(); - }); - - // SpecularOcclusion from input AO (baked or data-based SO) - EnumField specularOcclusionFromInputAOField; - if(stackLitData.devMode) - { - specularOcclusionFromInputAOField = new EnumField(StackLitData.SpecularOcclusionBaseMode.DirectFromAO); - specularOcclusionFromInputAOField.value = stackLitData.dataBasedSpecularOcclusionBaseMode; - } - else - { - specularOcclusionFromInputAOField = new EnumField(StackLitData.SpecularOcclusionBaseModeSimple.DirectFromAO); - specularOcclusionFromInputAOField.value = Enum.TryParse(stackLitData.dataBasedSpecularOcclusionBaseMode.ToString(), out StackLitData.SpecularOcclusionBaseModeSimple parsedValue) ? - parsedValue : StackLitData.SpecularOcclusionBaseModeSimple.SPTDIntegrationOfBentAO; - } - context.AddProperty("Specular Occlusion (from input AO)", 0, specularOcclusionFromInputAOField, (evt) => - { - if (Equals(stackLitData.dataBasedSpecularOcclusionBaseMode, evt.newValue)) - return; - - registerUndo("Specular Occlusion (from input AO)"); - stackLitData.dataBasedSpecularOcclusionBaseMode = (StackLitData.SpecularOcclusionBaseMode)evt.newValue; - onChange(); - }); - var specularOcclusionUsesVisibilityCone = StackLitSubTarget.SpecularOcclusionModeUsesVisibilityCone(stackLitData.dataBasedSpecularOcclusionBaseMode); - context.AddProperty("Specular Occlusion AO Cone Weight", 1, new EnumField(StackLitData.SpecularOcclusionAOConeSize.CosWeightedBentCorrectAO) { value = stackLitData.dataBasedSpecularOcclusionAOConeSize }, specularOcclusionUsesVisibilityCone, (evt) => - { - if (Equals(stackLitData.dataBasedSpecularOcclusionAOConeSize, evt.newValue)) - return; - - registerUndo("Specular Occlusion AO Cone Weight"); - stackLitData.dataBasedSpecularOcclusionAOConeSize = (StackLitData.SpecularOcclusionAOConeSize)evt.newValue; - onChange(); - }); - - // Specular Occlusion Bent Normal - var useBentConeFixup = StackLitSubTarget.SpecularOcclusionUsesBentNormal(stackLitData); - context.AddProperty("Specular Occlusion Bent Cone Fixup", 0, new EnumField(StackLitData.SpecularOcclusionConeFixupMethod.Off) { value = stackLitData.specularOcclusionConeFixupMethod }, useBentConeFixup && stackLitData.devMode, (evt) => - { - if (Equals(stackLitData.specularOcclusionConeFixupMethod, evt.newValue)) - return; - - registerUndo("Specular Occlusion Bent Cone Fixup"); - stackLitData.specularOcclusionConeFixupMethod = (StackLitData.SpecularOcclusionConeFixupMethod)evt.newValue; - onChange(); - }); - context.AddProperty("Specular Occlusion Bent Cone Fixup", 0, new Toggle() { value = stackLitData.specularOcclusionConeFixupMethod != StackLitData.SpecularOcclusionConeFixupMethod.Off }, useBentConeFixup && !stackLitData.devMode, (evt) => - { - if ( (evt.newValue == false && Equals(stackLitData.specularOcclusionConeFixupMethod, StackLitData.SpecularOcclusionConeFixupMethod.Off)) - || (evt.newValue == true && Equals(stackLitData.specularOcclusionConeFixupMethod, StackLitData.SpecularOcclusionConeFixupMethod.BoostAndTilt)) ) - return; - - registerUndo("Specular Occlusion Bent Cone Fixup"); - stackLitData.specularOcclusionConeFixupMethod = evt.newValue ? StackLitData.SpecularOcclusionConeFixupMethod.BoostAndTilt - : StackLitData.SpecularOcclusionConeFixupMethod.Off; - onChange(); - }); - - // Misc Cont. - context.AddProperty("Support LOD CrossFade", 0, new Toggle() { value = systemData.supportLodCrossFade }, (evt) => - { - if (Equals(systemData.supportLodCrossFade, evt.newValue)) - return; - - registerUndo("Support LOD CrossFade"); - systemData.supportLodCrossFade = evt.newValue; - onChange(); - }); - - // Advanced Options - context.AddLabel("Advanced Options", 0); - context.AddProperty("Anisotropy For Area Lights", 1, new Toggle() { value = stackLitData.anisotropyForAreaLights }, (evt) => - { - if (Equals(stackLitData.anisotropyForAreaLights, evt.newValue)) - return; - - registerUndo("Anisotropy For Area Lights"); - stackLitData.anisotropyForAreaLights = evt.newValue; - onChange(); - }); - - // Per Punctual/Directional Lights - context.AddLabel("Per Punctual/Directional Lights:", 1); - context.AddProperty("Base Layer Uses Refracted Angles", 2, new Toggle() { value = stackLitData.shadeBaseUsingRefractedAngles }, stackLitData.coat, (evt) => - { - if (Equals(stackLitData.shadeBaseUsingRefractedAngles, evt.newValue)) - return; - - registerUndo("Base Layer Uses Refracted Angles"); - stackLitData.shadeBaseUsingRefractedAngles = evt.newValue; - onChange(); - }); - context.AddProperty("Recompute Stack & Iridescence", 2, new Toggle() { value = stackLitData.recomputeStackPerLight }, stackLitData.coat || stackLitData.iridescence, (evt) => - { - if (Equals(stackLitData.recomputeStackPerLight, evt.newValue)) - return; - - registerUndo("Recompute Stack & Iridescence"); - stackLitData.recomputeStackPerLight = evt.newValue; - onChange(); - }); - context.AddProperty("Honor Per Light Max Smoothness", 2, new Toggle() { value = stackLitData.honorPerLightMinRoughness }, (evt) => - { - if (Equals(stackLitData.honorPerLightMinRoughness, evt.newValue)) - return; - - registerUndo("Honor Per Light Max Smoothness"); - stackLitData.honorPerLightMinRoughness = evt.newValue; - onChange(); - }); - - // Debug - // Uncomment to show the dev mode UI: - // context.AddProperty("Enable Dev Mode", 1, new Toggle() { value = stackLitData.devMode }, (evt) => - // { - // if (Equals(stackLitData.devMode, evt.newValue)) - // return; - // registerUndo("Enable Dev Mode"); - // stackLitData.devMode = evt.newValue; - // onChange(); - // }); - context.AddProperty("Show And Enable StackLit Debugs", 1, new Toggle() { value = stackLitData.debug }, stackLitData.devMode, (evt) => - { - if (Equals(stackLitData.debug, evt.newValue)) - return; - - registerUndo("Show And Enable StackLit Debugs"); - stackLitData.debug = evt.newValue; - onChange(); - }); - - // Misc Cont. - context.AddProperty("Override Baked GI", 1, new Toggle() { value = lightingData.overrideBakedGI }, (evt) => - { - if (Equals(lightingData.overrideBakedGI, evt.newValue)) - return; - - registerUndo("Override Baked GI"); - lightingData.overrideBakedGI = evt.newValue; - onChange(); - }); - context.AddProperty("Depth Offset", 1, new Toggle() { value = builtinData.depthOffset }, (evt) => - { - if (Equals(builtinData.depthOffset, evt.newValue)) - return; - - registerUndo("Depth Offset"); - builtinData.depthOffset = evt.newValue; - onChange(); - }); - } - - void DoRenderStateArea(ref TargetPropertyGUIContext context, int indentLevel, Action onChange, Action registerUndo) - { - context.AddProperty("Surface Type", indentLevel, new EnumField(SurfaceType.Opaque) { value = systemData.surfaceType }, (evt) => - { - if (Equals(systemData.surfaceType, evt.newValue)) - return; - - registerUndo("Surface Type"); - systemData.surfaceType = (SurfaceType)evt.newValue; - systemData.TryChangeRenderingPass(systemData.renderingPass); - onChange(); - }); - - context.AddProperty("Blending Mode", indentLevel + 1, new EnumField(BlendMode.Alpha) { value = systemData.blendMode }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.blendMode, evt.newValue)) - return; - - registerUndo("Blending Mode"); - systemData.blendMode = (BlendMode)evt.newValue; - onChange(); - }); - - context.AddProperty("Blend Preserves Specular", indentLevel + 1, new Toggle() { value = lightingData.blendPreserveSpecular }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(lightingData.blendPreserveSpecular, evt.newValue)) - return; - - registerUndo("Blend Preserves Specular"); - lightingData.blendPreserveSpecular = evt.newValue; - onChange(); - }); - - context.AddProperty("Fog", indentLevel + 1, new Toggle() { value = builtinData.transparencyFog }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(builtinData.transparencyFog, evt.newValue)) - return; - - registerUndo("Fog"); - builtinData.transparencyFog = evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Test", indentLevel + 1, new EnumField(systemData.zTest) { value = systemData.zTest }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zTest, evt.newValue)) - return; - - registerUndo("Depth Test"); - systemData.zTest = (CompareFunction)evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Write", indentLevel + 1, new Toggle() { value = systemData.zWrite }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zWrite, evt.newValue)) - return; - - registerUndo("Depth Write"); - systemData.zWrite = evt.newValue; - onChange(); - }); - - context.AddProperty("Cull Mode", indentLevel + 1, new EnumField(systemData.transparentCullMode) { value = systemData.transparentCullMode }, systemData.surfaceType == SurfaceType.Transparent && systemData.doubleSidedMode == DoubleSidedMode.Disabled, (evt) => - { - if (Equals(systemData.transparentCullMode, evt.newValue)) - return; - - registerUndo("Cull Mode"); - systemData.transparentCullMode = (TransparentCullMode)evt.newValue; - onChange(); - }); - - m_SortPriorityField = new IntegerField() { value = systemData.sortPriority }; - context.AddProperty("Sorting Priority", indentLevel + 1, m_SortPriorityField, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - var newValue = HDRenderQueue.ClampsTransparentRangePriority(evt.newValue); - if (Equals(systemData.sortPriority, newValue)) - return; - - registerUndo("Sorting Priority"); - m_SortPriorityField.value = newValue; - systemData.sortPriority = evt.newValue; - onChange(); - }); - } - - void DoDistortionArea(ref TargetPropertyGUIContext context, int indentLevel, Action onChange, Action registerUndo) - { - context.AddProperty("Distortion", indentLevel, new Toggle() { value = builtinData.distortion }, (evt) => - { - if (Equals(builtinData.distortion, evt.newValue)) - return; - - registerUndo("Distortion"); - builtinData.distortion = evt.newValue; - onChange(); - }); - - context.AddProperty("Distortion Blend Mode", indentLevel + 1, new EnumField(DistortionMode.Add) { value = builtinData.distortionMode }, builtinData.distortion, (evt) => - { - if (Equals(builtinData.distortionMode, evt.newValue)) - return; - - registerUndo("Distortion Blend Mode"); - builtinData.distortionMode = (DistortionMode)evt.newValue; - onChange(); - }); - - context.AddProperty("Distortion Depth Test", indentLevel + 1, new Toggle() { value = builtinData.distortionDepthTest }, builtinData.distortion, (evt) => - { - if (Equals(builtinData.distortionDepthTest, evt.newValue)) - return; - - registerUndo("Distortion Depth Test"); - builtinData.distortionDepthTest = evt.newValue; - onChange(); - }); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs index f2afda5626e..ff6dd13e246 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs @@ -348,8 +348,10 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { - // TODO - // blockList.AddPropertyBlock(new DecalPropertyBlock()); + blockList.AddPropertyBlock(new StackLitSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features.Lit, stackLitData)); + if (systemData.surfaceType == SurfaceType.Transparent) + blockList.AddPropertyBlock(new DistortionPropertyBlock()); + blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); } public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) @@ -399,26 +401,6 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera } } - public override void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)systemData.surfaceType); - material.SetFloat(kDoubleSidedNormalMode, (int)systemData.doubleSidedMode); - material.SetFloat(kDoubleSidedEnable, systemData.doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); - material.SetFloat(kAlphaCutoffEnabled, systemData.alphaTest ? 1 : 0); - material.SetFloat(kBlendMode, (int)systemData.blendMode); - material.SetFloat(kEnableFogOnTransparent, builtinData.transparencyFog ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)systemData.zTest); - material.SetFloat(kTransparentCullMode, (int)systemData.transparentCullMode); - material.SetFloat(kZWrite, systemData.zWrite ? 1.0f : 0.0f); - - // No sorting priority for shader graph preview - var renderingPass = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - material.renderQueue = (int)HDRenderQueue.ChangeType(renderingPass, offset: 0, alphaTest: systemData.alphaTest); - - StackLitGUI.SetupMaterialKeywordsAndPass(material); - } - public static bool SpecularOcclusionModeUsesVisibilityCone(StackLitData.SpecularOcclusionBaseMode soMethod) { return (soMethod == StackLitData.SpecularOcclusionBaseMode.ConeConeFromBentAO diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs new file mode 100644 index 00000000000..2a2e393eb73 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine; + +// We share the name of the properties in the UI to avoid duplication +using static UnityEditor.Rendering.HighDefinition.LitSurfaceInputsUIBlock.Styles; +using static UnityEditor.Rendering.HighDefinition.SurfaceOptionUIBlock.Styles; +using static UnityEditor.Rendering.HighDefinition.RefractionUIBlock.Styles; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + class StackLitSurfaceOptionPropertyBlock : SurfaceOptionPropertyBlock + { + class Styles + { + public static GUIContent materialType = new GUIContent("Material Type", "TODO"); + } + + StackLitData stackLitData; + + public StackLitSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features features, StackLitData stackLitData) : base(features) + => this.stackLitData = stackLitData; + + protected override void CreatePropertyGUI() + { + base.CreatePropertyGUI(); + + // StackLit specific properties: + + AddProperty("Base Color Parametrization", () => stackLitData.baseParametrization, (newValue) => stackLitData.baseParametrization = newValue); + AddProperty("Energy Conserving Specular", () => stackLitData.energyConservingSpecular, (newValue) => stackLitData.energyConservingSpecular = newValue, 1); + + // Material type enables: + context.AddLabel("Material Core Features", 0); + AddProperty("Anisotropy", () => stackLitData.anisotropy, (newValue) => stackLitData.anisotropy = newValue); + AddProperty("Coat", () => stackLitData.coat, (newValue) => stackLitData.coat = newValue, 1); + AddProperty("Coat Normal", () => stackLitData.coatNormal, (newValue) => stackLitData.coatNormal = newValue, 2); + AddProperty("Dual Specular Lobe", () => stackLitData.dualSpecularLobe, (newValue) => stackLitData.dualSpecularLobe = newValue, 1); + AddProperty("Dual SpecularLobe Parametrization", () => stackLitData.dualSpecularLobeParametrization, (newValue) => stackLitData.dualSpecularLobeParametrization = newValue, 2); + if (stackLitData.dualSpecularLobe && (stackLitData.baseParametrization == StackLit.BaseParametrization.BaseMetallic) && (stackLitData.dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss)) + AddProperty("Cap Haziness For Non Metallic", () => stackLitData.capHazinessWrtMetallic, (newValue) => stackLitData.capHazinessWrtMetallic = newValue, 2); + AddProperty("Iridescence", () => stackLitData.iridescence, (newValue) => stackLitData.iridescence = newValue, 1); + if (systemData.surfaceType != SurfaceType.Transparent) + AddProperty("Subsurface Scattering", () => lightingData.subsurfaceScattering, (newValue) => lightingData.subsurfaceScattering = newValue, 1); + AddProperty("Transmission", () => lightingData.transmission, (newValue) => lightingData.transmission = newValue, 1); + + // TODO: Can this use lightingData.specularAA? + AddProperty("Geometric Specular AA", () => stackLitData.geometricSpecularAA, (newValue) => stackLitData.geometricSpecularAA = newValue, 0); + + // SpecularOcclusion from SSAO + if (stackLitData.devMode) + AddProperty("Specular Occlusion (from SSAO)", () => stackLitData.screenSpaceSpecularOcclusionBaseMode, (newValue) => stackLitData.screenSpaceSpecularOcclusionBaseMode = newValue, 0); + var specularOcclusionSSUsesVisibilityCone = stackLitData.devMode && StackLitSubTarget.SpecularOcclusionModeUsesVisibilityCone(stackLitData.screenSpaceSpecularOcclusionBaseMode); + if (specularOcclusionSSUsesVisibilityCone) + { + AddProperty("Specular Occlusion (SS) AO Cone Weight", () => stackLitData.screenSpaceSpecularOcclusionAOConeSize, (newValue) => stackLitData.screenSpaceSpecularOcclusionAOConeSize = newValue, 1); + AddProperty("Specular Occlusion (SS) AO Cone Dir", () => stackLitData.screenSpaceSpecularOcclusionAOConeDir, (newValue) => stackLitData.screenSpaceSpecularOcclusionAOConeDir = newValue, 1); + } + + // SpecularOcclusion from input AO (baked or data-based SO) + EnumField specularOcclusionFromInputAOField; + if(stackLitData.devMode) + { + specularOcclusionFromInputAOField = new EnumField(StackLitData.SpecularOcclusionBaseMode.DirectFromAO); + specularOcclusionFromInputAOField.value = stackLitData.dataBasedSpecularOcclusionBaseMode; + } + else + { + specularOcclusionFromInputAOField = new EnumField(StackLitData.SpecularOcclusionBaseModeSimple.DirectFromAO); + specularOcclusionFromInputAOField.value = Enum.TryParse(stackLitData.dataBasedSpecularOcclusionBaseMode.ToString(), out StackLitData.SpecularOcclusionBaseModeSimple parsedValue) ? + parsedValue : StackLitData.SpecularOcclusionBaseModeSimple.SPTDIntegrationOfBentAO; + } + context.AddProperty("Specular Occlusion (from input AO)", 0, specularOcclusionFromInputAOField, (evt) => + { + if (Equals(stackLitData.dataBasedSpecularOcclusionBaseMode, evt.newValue)) + return; + + registerUndo("Specular Occlusion (from input AO)"); + stackLitData.dataBasedSpecularOcclusionBaseMode = (StackLitData.SpecularOcclusionBaseMode)evt.newValue; + onChange(); + }); + var specularOcclusionUsesVisibilityCone = StackLitSubTarget.SpecularOcclusionModeUsesVisibilityCone(stackLitData.dataBasedSpecularOcclusionBaseMode); + if (specularOcclusionUsesVisibilityCone) + AddProperty("Specular Occlusion AO Cone Weight", () => stackLitData.dataBasedSpecularOcclusionAOConeSize, (newValue) => stackLitData.dataBasedSpecularOcclusionAOConeSize = newValue, 1); + + // Specular Occlusion Bent Normal + var useBentConeFixup = StackLitSubTarget.SpecularOcclusionUsesBentNormal(stackLitData); + if (useBentConeFixup) + { + AddProperty("Specular Occlusion Bent Cone Fixup", () => stackLitData.specularOcclusionConeFixupMethod, (newValue) => stackLitData.specularOcclusionConeFixupMethod = newValue, 0); + AddProperty("Specular Occlusion Bent Cone Fixup", () => stackLitData.specularOcclusionConeFixupMethod != StackLitData.SpecularOcclusionConeFixupMethod.Off, (newValue) => + { + stackLitData.specularOcclusionConeFixupMethod = newValue ? StackLitData.SpecularOcclusionConeFixupMethod.BoostAndTilt + : StackLitData.SpecularOcclusionConeFixupMethod.Off; + }, 0); + } + + // Misc Cont. + // Advanced Options + context.AddLabel("Advanced Options", 0); + AddProperty("Anisotropy For Area Lights", () => stackLitData.anisotropyForAreaLights, (newValue) => stackLitData.anisotropyForAreaLights = newValue, 1); + + // Per Punctual/Directional Lights + context.AddLabel("Per Punctual/Directional Lights:", 1); + if (stackLitData.coat) + AddProperty("Base Layer Uses Refracted Angles", () => stackLitData.shadeBaseUsingRefractedAngles, (newValue) => stackLitData.shadeBaseUsingRefractedAngles = newValue, 2); + if (stackLitData.coat || stackLitData.iridescence) + AddProperty("Recompute Stack & Iridescence", () => stackLitData.recomputeStackPerLight, (newValue) => stackLitData.recomputeStackPerLight = newValue, 2); + AddProperty("Honor Per Light Max Smoothness", () => stackLitData.honorPerLightMinRoughness, (newValue) => stackLitData.honorPerLightMinRoughness = newValue, 2); + + // Debug + // Uncomment to show the dev mode UI: + // if (stackLitData.devMode) + // AddProperty("Enable Dev Mode", () => stackLitData.devMode, (newValue) => stackLitData.devMode = newValue, 1); + if (stackLitData.devMode) + AddProperty("Show And Enable StackLit Debugs", () => stackLitData.debug, (newValue) => stackLitData.debug = newValue, 1); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs.meta index 8315539b31c..7370f3f848b 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSettingsView.cs.meta +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8181fef146d3d7a4ab3a814e8963dbf2 +guid: 975437fb4199b8c48a2b9e540239bf50 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs index 4fd98e96daa..df9ec2f66b6 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs @@ -68,7 +68,8 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { - // blockList.AddPropertyBlock(new DecalPropertyBlock()); + blockList.AddPropertyBlock(new SurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features.Unlit)); + blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); } public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) @@ -91,24 +92,6 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera HDSubShaderUtilities.AddStencilShaderProperties(collector, systemData, null); } - public override void ProcessPreviewMaterial(Material material) - { - // Fixup the material settings: - material.SetFloat(kSurfaceType, (int)(SurfaceType)systemData.surfaceType); - material.SetFloat(kDoubleSidedEnable, systemData.doubleSidedMode != DoubleSidedMode.Disabled ? 1.0f : 0.0f); - material.SetFloat(kAlphaCutoffEnabled, systemData.alphaTest ? 1 : 0); - material.SetFloat(kBlendMode, (int)systemData.blendMode); - material.SetFloat(kEnableFogOnTransparent, builtinData.transparencyFog ? 1.0f : 0.0f); - material.SetFloat(kZTestTransparent, (int)systemData.zTest); - material.SetFloat(kTransparentCullMode, (int)systemData.transparentCullMode); - material.SetFloat(kZWrite, systemData.zWrite ? 1.0f : 0.0f); - - // No sorting priority for shader graph preview - material.renderQueue = (int)HDRenderQueue.ChangeType(systemData.renderingPass, offset: 0, alphaTest: systemData.alphaTest); - - HDUnlitGUI.SetupMaterialKeywordsAndPass(material); - } - #region SubShaders static class SubShaders { diff --git a/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs b/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs index 120f0de6227..108d8f204aa 100644 --- a/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs +++ b/com.unity.shadergraph/Editor/Generation/Contexts/TargetPropertyGUIContext.cs @@ -61,9 +61,9 @@ public void AddLabel(string label, int indentLevel) this.hierarchy.Add(propertyRow); } - void ApplyPadding(VisualElement element, int indentLevel) + void ApplyPadding(PropertyRow row, int indentLevel) { - element.style.paddingLeft = (globalIndentLevel + indentLevel) * kIndentWidthInPixel; + row.Q(className: "unity-label").style.marginLeft = (globalIndentLevel + indentLevel) * kIndentWidthInPixel; } } } From 026cc02031761025cfa037511c70fe74b89b7862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 27 May 2020 11:58:02 +0200 Subject: [PATCH 09/11] Finished decal and unlit inspector settings --- .../Decal/ShaderGraph/DecalPropertyBlock.cs | 41 ++++ ...iew.cs.meta => DecalPropertyBlock.cs.meta} | 2 +- .../Decal/ShaderGraph/DecalSettingsView.cs | 84 ------- .../Decal/ShaderGraph/DecalSubTarget.cs | 2 +- .../Material/Fabric/ShaderGraph/FabricData.cs | 8 + .../ShaderGraph/FabricSubTarget.Migration.cs | 6 +- .../Fabric/ShaderGraph/FabricSubTarget.cs | 6 +- .../FabricSurfaceOptionPropertyBlock.cs | 2 +- .../AdvancedOptionsPropertyBlock.cs | 7 +- .../Material/ShaderGraph/SurfaceSubTarget.cs | 7 + .../StackLit/ShaderGraph/StackLitData.cs | 17 +- .../StackLitSubTarget.Migration.cs | 10 +- .../StackLit/ShaderGraph/StackLitSubTarget.cs | 14 +- .../StackLitSurfaceOptionPropertyBlock.cs | 5 +- .../UIBlocks/DecalSurfaceInputsUIBlock.cs | 1 + .../Unlit/ShaderGraph/HDUnlitSettingsView.cs | 221 ------------------ .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 4 +- .../HDUnlitSurfaceOptionPropertyBlock.cs | 37 +++ ...HDUnlitSurfaceOptionPropertyBlock.cs.meta} | 2 +- .../ShaderGraph/TargetData/LightingData.cs | 8 - 20 files changed, 133 insertions(+), 351 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPropertyBlock.cs rename com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/{DecalSettingsView.cs.meta => DecalPropertyBlock.cs.meta} (83%) delete mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSettingsView.cs delete mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSettingsView.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSurfaceOptionPropertyBlock.cs rename com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/{HDUnlitSettingsView.cs.meta => HDUnlitSurfaceOptionPropertyBlock.cs.meta} (83%) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPropertyBlock.cs new file mode 100644 index 00000000000..f7ea757dacc --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPropertyBlock.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine; + +// We share the name of the properties in the UI to avoid duplication +using static UnityEditor.Rendering.HighDefinition.DecalSurfaceInputsUIBlock.Styles; +using static UnityEditor.Rendering.HighDefinition.SurfaceOptionUIBlock.Styles; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + class DecalPropertyBlock : SubTargetPropertyBlock + { + class Styles + { + public static GUIContent normalModeText = new GUIContent("Affect Normal", "TODO"); + public static GUIContent affectEmissionText = new GUIContent("Affect Emission", "TODO"); + } + + DecalData decalData; + + protected override string title => "Surface Settings"; + protected override int foldoutIndex => 4; + + public DecalPropertyBlock(DecalData decalData) => this.decalData = decalData; + + protected override void CreatePropertyGUI() + { + AddProperty(albedoModeText, () => decalData.affectsAlbedo, (newValue) => decalData.affectsAlbedo = newValue); + AddProperty(Styles.normalModeText, () => decalData.affectsNormal, (newValue) => decalData.affectsNormal = newValue); + AddProperty(affectMetalText, () => decalData.affectsMetal, (newValue) => decalData.affectsMetal = newValue); + AddProperty(affectAmbientOcclusionText, () => decalData.affectsAO, (newValue) => decalData.affectsAO = newValue); + AddProperty(affectSmoothnessText, () => decalData.affectsSmoothness, (newValue) => decalData.affectsSmoothness = newValue); + AddProperty(Styles.affectEmissionText, () => decalData.affectsEmission, (newValue) => decalData.affectsEmission = newValue); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSettingsView.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPropertyBlock.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSettingsView.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPropertyBlock.cs.meta index 2966f8d6023..c316e4df613 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSettingsView.cs.meta +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalPropertyBlock.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0f478c54cb669c743a23580d825341fe +guid: 45a92369f76e2124582437d711355c96 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSettingsView.cs deleted file mode 100644 index ec37b9fb2be..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSettingsView.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using UnityEngine.Rendering; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; -using UnityEngine.UIElements; -using UnityEditor.UIElements; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - class DecalSettingsView - { - SystemData systemData; - DecalData decalData; - - public DecalSettingsView(DecalSubTarget subTarget) - { - systemData = subTarget.systemData; - decalData = subTarget.decalData; - } - - public void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) - { - context.AddProperty("Affects BaseColor", 0, new Toggle() { value = decalData.affectsAlbedo }, (evt) => - { - if (Equals(decalData.affectsAlbedo, evt.newValue)) - return; - - registerUndo("Affects BaseColor"); - decalData.affectsAlbedo = evt.newValue; - onChange(); - }); - - context.AddProperty("Affects Normal", 0, new Toggle() { value = decalData.affectsNormal }, (evt) => - { - if (Equals(decalData.affectsNormal, evt.newValue)) - return; - - registerUndo("Affects Normal"); - decalData.affectsNormal = evt.newValue; - onChange(); - }); - - context.AddProperty("Affects Metal", 0, new Toggle() { value = decalData.affectsMetal }, (evt) => - { - if (Equals(decalData.affectsMetal, evt.newValue)) - return; - - registerUndo("Affects Metal"); - decalData.affectsMetal = evt.newValue; - onChange(); - }); - - context.AddProperty("Affects AO", 0, new Toggle() { value = decalData.affectsAO }, (evt) => - { - if (Equals(decalData.affectsAO, evt.newValue)) - return; - - registerUndo("Affects AO"); - decalData.affectsAO = evt.newValue; - onChange(); - }); - - context.AddProperty("Affects Smoothness", 0, new Toggle() { value = decalData.affectsSmoothness }, (evt) => - { - if (Equals(decalData.affectsSmoothness, evt.newValue)) - return; - - registerUndo("Affects Smoothness"); - decalData.affectsSmoothness = evt.newValue; - onChange(); - }); - - context.AddProperty("Affects Emission", 0, new Toggle() { value = decalData.affectsEmission }, (evt) => - { - if (Equals(decalData.affectsEmission, evt.newValue)) - return; - - registerUndo("Affects Emission"); - decalData.affectsEmission = evt.newValue; - onChange(); - }); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs index 544ff783a03..7f1d3e043e0 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Decal/ShaderGraph/DecalSubTarget.cs @@ -81,7 +81,7 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { - // blockList.AddPropertyBlock(new DecalPropertyBlock()); + blockList.AddPropertyBlock(new DecalPropertyBlock(decalData)); } protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricData.cs index f5d4878eced..1cd2953ef3c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricData.cs @@ -27,5 +27,13 @@ public bool energyConservingSpecular get => m_EnergyConservingSpecular; set => m_EnergyConservingSpecular = value; } + + [SerializeField] + bool m_Transmission = false; + public bool transmission + { + get => m_Transmission; + set => m_Transmission = value; + } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs index 9608d2d2441..b84fd2e2086 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs @@ -44,9 +44,9 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary fabricData.energyConservingSpecular, (newValue) => fabricData.energyConservingSpecular = newValue); AddProperty(subsurfaceEnableText, () => lightingData.subsurfaceScattering, (newValue) => lightingData.subsurfaceScattering = newValue); - AddProperty(transmissionEnableText, () => lightingData.transmission, (newValue) => lightingData.transmission = newValue); + AddProperty(transmissionEnableText, () => fabricData.transmission, (newValue) => fabricData.transmission = newValue); } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs index 36ae9bca156..2706b9cec3f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs @@ -26,8 +26,11 @@ class Styles protected override void CreatePropertyGUI() { - AddProperty(specularOcclusionModeText, () => lightingData.specularOcclusionMode, (newValue) => lightingData.specularOcclusionMode = newValue); - AddProperty(Styles.overrideBakedGI, () => lightingData.overrideBakedGI, (newValue) => lightingData.overrideBakedGI = newValue); + if (lightingData != null) + { + AddProperty(specularOcclusionModeText, () => lightingData.specularOcclusionMode, (newValue) => lightingData.specularOcclusionMode = newValue); + AddProperty(Styles.overrideBakedGI, () => lightingData.overrideBakedGI, (newValue) => lightingData.overrideBakedGI = newValue); + } AddProperty(Styles.supportLodCrossFade, () => systemData.supportLodCrossFade, (newValue) => systemData.supportLodCrossFade = newValue); AddProperty(addPrecomputedVelocityText, () => builtinData.addPrecomputedVelocity, (newValue) => builtinData.addPrecomputedVelocity = newValue); } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs index fb6dedee2cb..93acb78b7ad 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs @@ -114,6 +114,13 @@ protected void AddDistortionBlocks(ref TargetActiveBlockContext context) context.AddBlock(HDBlockFields.SurfaceDescription.DistortionBlur, systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion); } + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) + { + var gui = new SubTargetPropertiesGUI(context, onChange, registerUndo, systemData, builtinData, null); + AddInspectorPropertyBlocks(gui); + context.Add(gui); + } + public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) { // Trunk currently relies on checking material property "_EmissionColor" to allow emissive GI. If it doesn't find that property, or it is black, GI is forced off. diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitData.cs index 0d59695c8fc..c028789ad15 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitData.cs @@ -148,15 +148,6 @@ public bool iridescence set => m_Iridescence = value; } - // TODO: Can this re-use HDLightingData.m_SpecularAA instead? - [SerializeField] - bool m_GeometricSpecularAA; - public bool geometricSpecularAA - { - get => m_GeometricSpecularAA; - set => m_GeometricSpecularAA = value; - } - [SerializeField] SpecularOcclusionBaseMode m_ScreenSpaceSpecularOcclusionBaseMode = SpecularOcclusionBaseMode.DirectFromAO; public SpecularOcclusionBaseMode screenSpaceSpecularOcclusionBaseMode @@ -274,5 +265,13 @@ public bool energyConservingSpecular get => m_EnergyConservingSpecular; set => m_EnergyConservingSpecular = value; } + + [SerializeField] + bool m_Transmission = false; + public bool transmission + { + get => m_Transmission; + set => m_Transmission = value; + } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs index 470dce52403..037704dec73 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs @@ -47,9 +47,10 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary stackLitData.iridescence, (newValue) => stackLitData.iridescence = newValue, 1); if (systemData.surfaceType != SurfaceType.Transparent) AddProperty("Subsurface Scattering", () => lightingData.subsurfaceScattering, (newValue) => lightingData.subsurfaceScattering = newValue, 1); - AddProperty("Transmission", () => lightingData.transmission, (newValue) => lightingData.transmission = newValue, 1); - - // TODO: Can this use lightingData.specularAA? - AddProperty("Geometric Specular AA", () => stackLitData.geometricSpecularAA, (newValue) => stackLitData.geometricSpecularAA = newValue, 0); + AddProperty("Transmission", () => stackLitData.transmission, (newValue) => stackLitData.transmission = newValue, 1); // SpecularOcclusion from SSAO if (stackLitData.devMode) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceInputsUIBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceInputsUIBlock.cs index 23f9f91c38f..2ea7ac2be49 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceInputsUIBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/UIBlocks/DecalSurfaceInputsUIBlock.cs @@ -21,6 +21,7 @@ public class Styles public static GUIContent normalMapText = new GUIContent("Normal Map", "Specifies the normal map for this Material (BC7/BC5/DXT5(nm))."); public static GUIContent decalBlendText = new GUIContent("Global Opacity", "Controls the opacity of the entire decal."); public static GUIContent albedoModeText = new GUIContent("Affect BaseColor", "Base color + Opacity, Opacity only."); + public static GUIContent normalModeText = new GUIContent("Affect Normal", "TODO"); public static GUIContent normalOpacityChannelText = new GUIContent("Normal Opacity Channel", "Specifies the source this Material uses as opacity for its Normal Map."); public static GUIContent smoothnessRemappingText = new GUIContent("Smoothness Remapping", "Controls a remap for the smoothness channel in the Mask Map."); public static GUIContent metallicText = new GUIContent("Metallic Scale", "Controls a scale factor for the metallic channel in the Mask Map."); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSettingsView.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSettingsView.cs deleted file mode 100644 index b73c5b76b91..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSettingsView.cs +++ /dev/null @@ -1,221 +0,0 @@ -using System; -using UnityEngine.Rendering; -using UnityEngine.Rendering.HighDefinition; -using UnityEditor.ShaderGraph; -using UnityEngine.UIElements; -using UnityEditor.UIElements; - -namespace UnityEditor.Rendering.HighDefinition.ShaderGraph -{ - class HDUnlitSettingsView - { - SystemData systemData; - BuiltinData builtinData; - HDUnlitData unlitData; - - public HDUnlitSettingsView(HDUnlitSubTarget subTarget) - { - systemData = subTarget.systemData; - builtinData = subTarget.builtinData; - unlitData = subTarget.unlitData; - } - - public void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) - { - // TODO: Register Undo actions... - - // Render State - DoRenderStateArea(ref context, systemData, 0, onChange, registerUndo); - - // Transparent - context.AddProperty("Receive Fog", 1, new Toggle() { value = builtinData.transparencyFog }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(builtinData.transparencyFog, evt.newValue)) - return; - - registerUndo("Receive Fog"); - builtinData.transparencyFog = evt.newValue; - onChange(); - }); - - // Distortion - if(systemData.surfaceType == SurfaceType.Transparent) - { - DoDistortionArea(ref context, builtinData, 1, onChange, registerUndo); - } - - // Alpha Test - // TODO: AlphaTest is in SystemData but Alpha to Mask is in BuiltinData? - context.AddProperty("Alpha Clipping", 0, new Toggle() { value = systemData.alphaTest }, (evt) => - { - if (Equals(systemData.alphaTest, evt.newValue)) - return; - - registerUndo("Alpha Clipping"); - systemData.alphaTest = evt.newValue; - onChange(); - }); - context.AddProperty("Alpha to Mask", 1, new Toggle() { value = builtinData.alphaToMask }, systemData.alphaTest, (evt) => - { - if (Equals(builtinData.alphaToMask, evt.newValue)) - return; - - registerUndo("Alpha to Mask"); - builtinData.alphaToMask = evt.newValue; - onChange(); - }); - - // Misc - context.AddProperty("Double-Sided Mode", 0, new EnumField(DoubleSidedMode.Disabled) { value = systemData.doubleSidedMode }, (evt) => - { - if (Equals(systemData.doubleSidedMode, evt.newValue)) - return; - - registerUndo("Double-Sided Mode"); - systemData.doubleSidedMode = (DoubleSidedMode)evt.newValue; - onChange(); - }); - context.AddProperty("Add Precomputed Velocity", 0, new Toggle() { value = builtinData.addPrecomputedVelocity }, (evt) => - { - if (Equals(builtinData.addPrecomputedVelocity, evt.newValue)) - return; - - registerUndo("Add Precomputed Velocity"); - builtinData.addPrecomputedVelocity = evt.newValue; - onChange(); - }); - context.AddProperty("Shadow Matte", 0, new Toggle() { value = unlitData.enableShadowMatte }, (evt) => - { - if (Equals(unlitData.enableShadowMatte, evt.newValue)) - return; - - registerUndo("Shadow Matte"); - unlitData.enableShadowMatte = evt.newValue; - onChange(); - }); - } - - // TODO: Can we make this static and use it for all SubTargets? - void DoRenderStateArea(ref TargetPropertyGUIContext context, SystemData systemData, int indentLevel, Action onChange, Action registerUndo) - { - context.AddProperty("Surface Type", indentLevel, new EnumField(SurfaceType.Opaque) { value = systemData.surfaceType }, (evt) => - { - if (Equals(systemData.surfaceType, evt.newValue)) - return; - - registerUndo("Surface Type"); - systemData.surfaceType = (SurfaceType)evt.newValue; - systemData.TryChangeRenderingPass(systemData.renderingPass); - onChange(); - }); - - var renderingPassList = HDSubShaderUtilities.GetRenderingPassList(systemData.surfaceType == SurfaceType.Opaque, true); - var renderingPassValue = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.GetOpaqueEquivalent(systemData.renderingPass) : HDRenderQueue.GetTransparentEquivalent(systemData.renderingPass); - var renderQueueType = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent; - context.AddProperty("Rendering Pass", indentLevel + 1, new PopupField(renderingPassList, renderQueueType, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName) { value = renderingPassValue }, (evt) => - { - registerUndo("Rendering Pass"); - if(systemData.TryChangeRenderingPass(evt.newValue)) - { - onChange(); - } - }); - - context.AddProperty("Blending Mode", indentLevel + 1, new EnumField(BlendMode.Alpha) { value = systemData.blendMode }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.blendMode, evt.newValue)) - return; - - registerUndo("Blending Mode"); - systemData.blendMode = (BlendMode)evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Test", indentLevel + 1, new EnumField(systemData.zTest) { value = systemData.zTest }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zTest, evt.newValue)) - return; - - registerUndo("Depth Test"); - systemData.zTest = (CompareFunction)evt.newValue; - onChange(); - }); - - context.AddProperty("Depth Write", indentLevel + 1, new Toggle() { value = systemData.zWrite }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.zWrite, evt.newValue)) - return; - - registerUndo("Depth Write"); - systemData.zWrite = evt.newValue; - onChange(); - }); - - context.AddProperty("Cull Mode", indentLevel + 1, new EnumField(systemData.transparentCullMode) { value = systemData.transparentCullMode }, systemData.surfaceType == SurfaceType.Transparent && systemData.doubleSidedMode == DoubleSidedMode.Disabled, (evt) => - { - if (Equals(systemData.transparentCullMode, evt.newValue)) - return; - - registerUndo("Cull Mode"); - systemData.transparentCullMode = (TransparentCullMode)evt.newValue; - onChange(); - }); - - context.AddProperty("Sorting Priority", indentLevel + 1, new IntegerField() { value = systemData.sortPriority }, systemData.surfaceType == SurfaceType.Transparent, (evt) => - { - if (Equals(systemData.sortPriority, evt.newValue)) - return; - - registerUndo("Sorting Priority"); - systemData.sortPriority = evt.newValue; - onChange(); - }); - } - - // TODO: Can we make this static and use it for all SubTargets? - void DoDistortionArea(ref TargetPropertyGUIContext context, BuiltinData builtinData, int indentLevel, Action onChange, Action registerUndo) - { - context.AddProperty("Distortion", 1, new Toggle() { value = builtinData.distortion }, (evt) => - { - if (Equals(builtinData.distortion, evt.newValue)) - return; - - registerUndo("Distortion"); - builtinData.distortion = evt.newValue; - onChange(); - }); - - context.AddProperty("Distortion Blend Mode", 2, new EnumField(DistortionMode.Add) { value = builtinData.distortionMode }, builtinData.distortion, (evt) => - { - if (Equals(builtinData.distortionMode, evt.newValue)) - return; - - registerUndo("Distortion Blend Mode"); - builtinData.distortionMode = (DistortionMode)evt.newValue; - onChange(); - }); - - // TODO: This was on HDUnlitMaster but not used anywhere - // TODO: Can this be removed (See HDBuiltinData)? - // context.AddProperty("Distortion Only", 2, new Toggle() { value = builtinData.distortionOnly }, builtinData.distortion, (evt) => - // { - // if (Equals(builtinData.distortionOnly, evt.newValue)) - // return; - - // registerUndo("Distortion Only"); - // builtinData.distortionOnly = evt.newValue; - // onChange(); - // }); - - context.AddProperty("Distortion Depth Test", 2, new Toggle() { value = builtinData.distortionDepthTest }, builtinData.distortion, (evt) => - { - if (Equals(builtinData.distortionDepthTest, evt.newValue)) - return; - - registerUndo("Distortion Depth Test"); - builtinData.distortionDepthTest = evt.newValue; - onChange(); - }); - } - } -} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs index df9ec2f66b6..2fbcf29e1fa 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSubTarget.cs @@ -68,7 +68,9 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) { - blockList.AddPropertyBlock(new SurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features.Unlit)); + blockList.AddPropertyBlock(new HDUnlitSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features.Unlit, unlitData)); + if (systemData.surfaceType == SurfaceType.Transparent) + blockList.AddPropertyBlock(new DistortionPropertyBlock()); blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSurfaceOptionPropertyBlock.cs new file mode 100644 index 00000000000..7b1a9b1f558 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSurfaceOptionPropertyBlock.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Rendering; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEngine.UIElements; +using UnityEditor.UIElements; +using UnityEngine; + +// We share the name of the properties in the UI to avoid duplication +using static UnityEditor.Rendering.HighDefinition.LitSurfaceInputsUIBlock.Styles; +using static UnityEditor.Rendering.HighDefinition.SurfaceOptionUIBlock.Styles; +using static UnityEditor.Rendering.HighDefinition.RefractionUIBlock.Styles; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + class HDUnlitSurfaceOptionPropertyBlock : SurfaceOptionPropertyBlock + { + class Styles + { + public static GUIContent shadowMatte = new GUIContent("Shadow Matte", "TODO"); + } + + HDUnlitData unlitData; + + public HDUnlitSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features features, HDUnlitData unlitData) : base(features) + => this.unlitData = unlitData; + + protected override void CreatePropertyGUI() + { + base.CreatePropertyGUI(); + + // HDUnlit specific properties: + AddProperty(Styles.shadowMatte, () => unlitData.enableShadowMatte, (newValue) => unlitData.enableShadowMatte = newValue); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSettingsView.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSurfaceOptionPropertyBlock.cs.meta similarity index 83% rename from com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSettingsView.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSurfaceOptionPropertyBlock.cs.meta index 27342fdb336..3440865c67d 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSettingsView.cs.meta +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitSurfaceOptionPropertyBlock.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 775f9331f25e19640bcba701363f3f36 +guid: d0de5ce599107e548b5600cff185256e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs index c55533b39e5..9cb666960cf 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/TargetData/LightingData.cs @@ -47,14 +47,6 @@ public bool receiveSSRTransparent set => m_ReceiveSSRTransparent = value; } - [SerializeField] - bool m_Transmission = false; - public bool transmission - { - get => m_Transmission; - set => m_Transmission = value; - } - [SerializeField] bool m_SubsurfaceScattering = false; public bool subsurfaceScattering From 70216ed0dd03b6b6d4592baea5eeadc9c2ac1d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 27 May 2020 19:35:07 +0200 Subject: [PATCH 10/11] Fixed bent normal compilation issue --- .../Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs | 1 - .../Editor/Material/ShaderGraph/LightingSubTarget.cs | 8 ++++---- .../Material/StackLit/ShaderGraph/StackLitSubTarget.cs | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) 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 d4a500fe4ce..03db300ab22 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 @@ -96,7 +96,6 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) // Vertex base.GetActiveBlocks(ref context); AddDistortionBlocks(ref context); - AddNormalBlocks(ref context); // Common context.AddBlock(HDBlockFields.SurfaceDescription.CoatMask); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs index 69c04adf179..bac2f087a61 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs @@ -93,8 +93,10 @@ public override void GetFields(ref TargetFieldContext context) context.AddField(HDFields.SpecularOcclusionCustom, lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom); } - protected void AddLightingBlocks(ref TargetActiveBlockContext context) + public override void GetActiveBlocks(ref TargetActiveBlockContext context) { + base.GetActiveBlocks(ref context); + context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); context.AddBlock(BlockFields.SurfaceDescription.Smoothness); context.AddBlock(BlockFields.SurfaceDescription.Occlusion); @@ -109,10 +111,8 @@ protected void AddLightingBlocks(ref TargetActiveBlockContext context) // Misc context.AddBlock(HDBlockFields.SurfaceDescription.SpecularOcclusion, lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom); - } - protected void AddNormalBlocks(ref TargetActiveBlockContext context) - { + // Normal dropoff space context.AddBlock(BlockFields.SurfaceDescription.NormalOS, lightingData.normalDropOffSpace == NormalDropOffSpace.Object); context.AddBlock(BlockFields.SurfaceDescription.NormalTS, lightingData.normalDropOffSpace == NormalDropOffSpace.Tangent); context.AddBlock(BlockFields.SurfaceDescription.NormalWS, lightingData.normalDropOffSpace == NormalDropOffSpace.World); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs index 2d94430967f..24cfdfb16e9 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs @@ -286,7 +286,6 @@ public override void GetFields(ref TargetFieldContext context) public override void GetActiveBlocks(ref TargetActiveBlockContext context) { base.GetActiveBlocks(ref context); - AddNormalBlocks(ref context); AddDistortionBlocks(ref context); // Common From c8aa459ff5fc53af2a0c6c07ab5d782ea8f678ce Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Wed, 27 May 2020 20:20:48 +0200 Subject: [PATCH 11/11] Rename file EyeSurfaceOptionPropertyBlock.cs --- ...fceOptionPropertyBlock.cs => EyeSurfaceOptionPropertyBlock.cs} | 0 ...ropertyBlock.cs.meta => EyeSurfaceOptionPropertyBlock.cs.meta} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/{EyeSubrafceOptionPropertyBlock.cs => EyeSurfaceOptionPropertyBlock.cs} (100%) rename com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/{EyeSubrafceOptionPropertyBlock.cs.meta => EyeSurfaceOptionPropertyBlock.cs.meta} (100%) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubrafceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSurfaceOptionPropertyBlock.cs similarity index 100% rename from com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubrafceOptionPropertyBlock.cs rename to com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSurfaceOptionPropertyBlock.cs diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubrafceOptionPropertyBlock.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSurfaceOptionPropertyBlock.cs.meta similarity index 100% rename from com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubrafceOptionPropertyBlock.cs.meta rename to com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSurfaceOptionPropertyBlock.cs.meta