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/30] 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/30] 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/30] 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/30] 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/30] 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/30] 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/30] 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/30] 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/30] 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 8a59d3a9fc53c00588f7261e182f9e2715fee229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Thu, 28 May 2020 14:37:24 +0200 Subject: [PATCH 10/30] Add missing unlit distortion only + remove unlitPass template + fix duplicated alpha to mask option --- .../Lit/ShaderGraph/HDLitSubTarget.cs | 3 +- .../ShaderGraph/SurfaceOptionPropertyBlock.cs | 4 +- .../Material/Unlit/ShaderGraph/HDUnlitData.cs | 24 +--- .../HDUnlitDistortionPropertyBlock.cs | 27 ++++ .../HDUnlitDistortionPropertyBlock.cs.meta | 11 ++ .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 3 +- .../Unlit/ShaderGraph/UnlitPass.template | 134 ------------------ .../Unlit/ShaderGraph/UnlitPass.template.meta | 7 - 8 files changed, 49 insertions(+), 164 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs.meta delete mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitPass.template delete mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitPass.template.meta 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..030bb6e6d93 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 @@ -138,12 +138,11 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL protected override int ComputeMaterialNeedsUpdateHash() { - bool subsurfaceScattering = litData.materialType == HDLitData.MaterialType.SubsurfaceScattering; int hash = base.ComputeMaterialNeedsUpdateHash(); unchecked { - hash = hash * 23 + lightingData.receiveSSRTransparent.GetHashCode(); + bool subsurfaceScattering = litData.materialType == HDLitData.MaterialType.SubsurfaceScattering; hash = hash * 23 + subsurfaceScattering.GetHashCode(); } 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 c674490e8fe..6ef3e38dc30 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 @@ -28,6 +28,7 @@ public enum Features class Styles { public static GUIContent fragmentNormalSpace = new GUIContent("Fragment Normal Space", "TODO"); + public static GUIContent doubleSidedModeText = new GUIContent("Double Sided Mode", "TODO"); } Features enabledFeatures; @@ -78,10 +79,9 @@ protected override void CreatePropertyGUI() 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); + AddProperty(Styles.doubleSidedModeText, () => systemData.doubleSidedMode, (newValue) => systemData.doubleSidedMode = newValue); if (lightingData != null) AddProperty(Styles.fragmentNormalSpace, () => lightingData.normalDropOffSpace, (newValue) => lightingData.normalDropOffSpace = newValue); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitData.cs index 8c7612c4fee..8d229a24df1 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitData.cs @@ -14,22 +14,12 @@ public bool enableShadowMatte set => m_EnableShadowMatte = value; } - // TODO: This was on HDUnlitMaster but not used anywhere, can this be removed? - // [SerializeField] - // bool m_DistortionOnly = true; - // public bool distortionOnly - // { - // get => m_DistortionOnly; - // set => m_DistortionOnly = value; - // } - - // TODO: HDUnlitMaster used this instead of DoubleSidedMode, presumably because normals are irrelevant - // [SerializeField] - // bool m_DoubleSided; - // public bool doubleSided - // { - // get => m_DoubleSided; - // set => m_DoubleSided = value; - // } + [SerializeField] + bool m_DistortionOnly = false; + public bool distortionOnly + { + get => m_DistortionOnly; + set => m_DistortionOnly = value; + } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs new file mode 100644 index 00000000000..b52e23c356c --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.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 HDUnlitDistortionPropertyBlock : DistortionPropertyBlock + { + HDUnlitData unlitData; + + public HDUnlitDistortionPropertyBlock(HDUnlitData unlitData) => this.unlitData = unlitData; + + protected override void CreatePropertyGUI() + { + AddProperty(distortionOnlyText, () => unlitData.distortionOnly, (newValue) => unlitData.distortionOnly = newValue); + base.CreatePropertyGUI(); + } + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs.meta new file mode 100644 index 00000000000..a60954392f9 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4905ec7b1708c8d4aad3bebdab1a6ef8 +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 2fbcf29e1fa..bbde5ac38c4 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 @@ -19,7 +19,6 @@ sealed partial class HDUnlitSubTarget : SurfaceSubTarget, ILegacyTarget, IRequir // TODO: Why do the raytracing passes use the template for the pipeline agnostic Unlit master node? // TODO: This should be resolved so we can delete the second pass template static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template"; - static string raytracingPassTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/UnlitPass.template"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Unlit; protected override string renderType => HDRenderTypeTags.HDUnlitShader.ToString(); protected override string subTargetAssetGuid => "4516595d40fa52047a77940183dc8e74"; // HDUnlitSubTarget @@ -70,7 +69,7 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL { blockList.AddPropertyBlock(new HDUnlitSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features.Unlit, unlitData)); if (systemData.surfaceType == SurfaceType.Transparent) - blockList.AddPropertyBlock(new DistortionPropertyBlock()); + blockList.AddPropertyBlock(new HDUnlitDistortionPropertyBlock(unlitData)); blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitPass.template b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitPass.template deleted file mode 100644 index 05bdf5feb5d..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitPass.template +++ /dev/null @@ -1,134 +0,0 @@ -Pass -{ - $splice(PassName) - Tags - { - $splice(LightMode) - } - - // Render State - $splice(RenderState) - - // Debug - $splice(Debug) - - // -------------------------------------------------- - // Pass - - HLSLPROGRAM - - // Pragmas - $splice(PassPragmas) - - // Keywords - $splice(PassKeywords) - $splice(GraphKeywords) - - // Defines - $SurfaceType.Transparent: #define _SURFACE_TYPE_TRANSPARENT 1 - $BlendMode.Alpha: #define _BLENDMODE_ALPHA 1 - $BlendMode.Add: #define _BLENDMODE_ADD 1 - $BlendMode.Premultiply: #define _BLENDMODE_PRE_MULTIPLY 1 - $AddPrecomputedVelocity: #define _ADD_PRECOMPUTED_VELOCITY - $AttributesMesh.normalOS: #define ATTRIBUTES_NEED_NORMAL - $AttributesMesh.tangentOS: #define ATTRIBUTES_NEED_TANGENT - $AttributesMesh.uv0: #define ATTRIBUTES_NEED_TEXCOORD0 - $AttributesMesh.uv1: #define ATTRIBUTES_NEED_TEXCOORD1 - $AttributesMesh.uv2: #define ATTRIBUTES_NEED_TEXCOORD2 - $AttributesMesh.uv3: #define ATTRIBUTES_NEED_TEXCOORD3 - $AttributesMesh.color: #define ATTRIBUTES_NEED_COLOR - $VaryingsMeshToPS.positionRWS: #define VARYINGS_NEED_POSITION_WS - $VaryingsMeshToPS.normalWS: #define VARYINGS_NEED_TANGENT_TO_WORLD - $VaryingsMeshToPS.texCoord0: #define VARYINGS_NEED_TEXCOORD0 - $VaryingsMeshToPS.texCoord1: #define VARYINGS_NEED_TEXCOORD1 - $VaryingsMeshToPS.texCoord2: #define VARYINGS_NEED_TEXCOORD2 - $VaryingsMeshToPS.texCoord3: #define VARYINGS_NEED_TEXCOORD3 - $VaryingsMeshToPS.color: #define VARYINGS_NEED_COLOR - $VaryingsMeshToPS.cullFace: #define VARYINGS_NEED_CULLFACE - $features.graphVertex: #define HAVE_MESH_MODIFICATION - $splice(GraphDefines) - - $splice(HybridV1InjectedBuiltinProperties) - - // Includes - $splice(PreGraphIncludes) - - // Used by SceneSelectionPass - int _ObjectId; - int _PassValue; - - // -------------------------------------------------- - // Structs and Packing - - $splice(PassStructs) - - $splice(InterpolatorPack) - - // -------------------------------------------------- - // Graph - - // Graph Properties - $splice(GraphProperties) - - // Graph Functions - $splice(GraphFunctions) - - // Graph Vertex - $splice(GraphVertex) - - // Graph Pixel - $splice(GraphPixel) - - // -------------------------------------------------- - // Build Graph Inputs - - $features.graphVertex: $include("VertexAnimation.template.hlsl") - $features.graphPixel: $include("SharedCode.template.hlsl") - - // -------------------------------------------------- - // Build Surface Data - - void BuildSurfaceData(FragInputs fragInputs, inout SurfaceDescription surfaceDescription, float3 V, PositionInputs posInput, out SurfaceData surfaceData) - { - // setup defaults -- these are used if the graph doesn't output a value - ZERO_INITIALIZE(SurfaceData, surfaceData); - - // copy across graph values, if defined - $SurfaceDescription.BaseColor: surfaceData.color = surfaceDescription.BaseColor; - - #if defined(DEBUG_DISPLAY) - if (_DebugMipMapMode != DEBUGMIPMAPMODE_NONE) - { - // TODO - } - #endif - } - - void GetSurfaceAndBuiltinData(FragInputs fragInputs, float3 V, inout PositionInputs posInput, out SurfaceData surfaceData, out BuiltinData builtinData RAY_TRACING_OPTIONAL_PARAMETERS) - { - SurfaceDescriptionInputs surfaceDescriptionInputs = FragInputsToSurfaceDescriptionInputs(fragInputs, V); - SurfaceDescription surfaceDescription = SurfaceDescriptionFunction(surfaceDescriptionInputs); - - // Perform alpha test very early to save performance (a killed pixel will not sample textures) - // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. - $AlphaTest: GENERIC_ALPHA_TEST(surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold); - - BuildSurfaceData(fragInputs, surfaceDescription, V, posInput, surfaceData); - - // Builtin Data - ZERO_INITIALIZE(BuiltinData, builtinData); // No call to InitBuiltinData as we don't have any lighting - builtinData.opacity = surfaceDescription.Alpha; - -#if !defined(_SURFACE_TYPE_TRANSPARENT) - $SurfaceDescription.VTPackedFeedback: builtinData.vtPackedFeedback = surfaceDescription.VTPackedFeedback; -#endif - RAY_TRACING_OPTIONAL_ALPHA_TEST_PASS - } - - // -------------------------------------------------- - // Main - - $splice(PostGraphIncludes) - - ENDHLSL -} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitPass.template.meta b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitPass.template.meta deleted file mode 100644 index cd4a400d871..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/UnlitPass.template.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 1dcf57b107a24784cb16ec0278437fbd -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: From 69ee8dcdbc848ddbbb0e253d0fc07ce701b48ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Thu, 28 May 2020 14:39:47 +0200 Subject: [PATCH 11/30] Testing new pass override system --- .../ProjectSettings/GraphicsSettings.asset | 2 +- .../UserSettings/EditorUserSettings.asset | 25 +- .../Decal/ShaderGraph/DecalSubTarget.cs | 7 +- .../Material/Eye/ShaderGraph/EyeSubTarget.cs | 10 +- .../Fabric/ShaderGraph/FabricSubTarget.cs | 8 +- .../Hair/ShaderGraph/HairSubTarget.cs | 16 +- .../Lit/ShaderGraph/HDLitSubTarget.cs | 12 +- .../Material/ShaderGraph/HDSubTarget.cs | 1 + .../Material/ShaderGraph/LightingSubTarget.cs | 2 + .../Material/ShaderGraph/SurfaceSubTarget.cs | 234 ++++++++++++++++++ .../StackLit/ShaderGraph/StackLitSubTarget.cs | 13 +- .../ShaderGraph/HDUnlitSubTarget.Migration.cs | 1 + .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 87 +++---- 13 files changed, 336 insertions(+), 82 deletions(-) diff --git a/TestProjects/HDRP_Tests/ProjectSettings/GraphicsSettings.asset b/TestProjects/HDRP_Tests/ProjectSettings/GraphicsSettings.asset index ca9dc00be0e..dd90c191192 100644 --- a/TestProjects/HDRP_Tests/ProjectSettings/GraphicsSettings.asset +++ b/TestProjects/HDRP_Tests/ProjectSettings/GraphicsSettings.asset @@ -35,7 +35,7 @@ GraphicsSettings: m_PreloadedShaders: [] m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} - m_CustomRenderPipeline: {fileID: 11400000, guid: 8650072ee85219341b65a263bf871815, + m_CustomRenderPipeline: {fileID: 11400000, guid: d7fe5f39d2c099a4ea1f1f610af309d7, type: 2} m_TransparencySortMode: 0 m_TransparencySortAxis: {x: 0, y: 0, z: 1} diff --git a/TestProjects/HDRP_Tests/UserSettings/EditorUserSettings.asset b/TestProjects/HDRP_Tests/UserSettings/EditorUserSettings.asset index 62e82ff008a..2a64524a099 100644 --- a/TestProjects/HDRP_Tests/UserSettings/EditorUserSettings.asset +++ b/TestProjects/HDRP_Tests/UserSettings/EditorUserSettings.asset @@ -5,6 +5,24 @@ EditorUserSettings: m_ObjectHideFlags: 0 serializedVersion: 4 m_ConfigSettings: + RecentlyUsedScenePath-0: + value: 224247031146467c1f0f1c2a19206b1505030b651f2b233e283a526afadf1b2ceae224a6be6c6f6e0631e4350a30043bdf0f1a03d40a1e081907f3095cd01e5d04cb11d103 + flags: 0 + RecentlyUsedScenePath-1: + value: 224247031146467c1f0f1c2a19206b1505030b651f2b233e283a5262fadf1939f6e224e0e6362c736853bf6e3b0b0f33fb1e362fff181e04031af4011fb1051d18d101 + flags: 0 + RecentlyUsedScenePath-2: + value: 224247031146466f08031c6d046d4a1e1f0301 + flags: 0 + ShaderGraph.SubWindow: + value: 18135939215a0a5004000b0e15254b524c030a3f2964643d120d1230e9e93a3fd6e826abbd2e2d293c4ead313b08042de6030a0afa240c0d020be94c4ba65e435d8715fa32c70d15d11612dacc11fee5d3c5d1fe9ab1b7968e93e2ffcbc3e7e2f0b3ffe0e8b0be9af9f6afffff8e85dd8390e39d9f8899daa7 + flags: 0 + UnityEditor.ShaderGraph.FloatingWindowsLayout2: + value: 181344140043005e1a220d3b1f364b524c0c5a27130c293326201334cee5322ca0bd30e8eb293a707b0fd0180b3d0a36fc0d3d04e649500d1002ee0b5dbd1d2c27c00ad113cb1e10e41f1addc80993b982839aba94a9eae7f6d0b2fbeeffe0ecf4fd8afdacbbf9d4e8f5a8e7e1928b86ccf584cdd6c38b9da190c991e48183879786c994c0c5828a81d8eeddbf8debe691ada5959ea796aa8f9ab0b379bcba74243d73f8b187928fbeb2648d755c818e6635dc6d659f8ac0cb9f40a89b8d9a864c9dad9456d9c08f738b48d223425f5564477c5c695963435d6f7f5b492f7b236b76683825445f273c262a4d4a547f446a4733583f2c0e0a62711e4d7d5f686758400216064d1b4f487873735e6d726f6b3f577c7840716579002d00 + flags: 0 + UnityEditor.ShaderGraph.ToggleSettings: + value: 18135d1527590858060c032302276919051e1a26296a7c243f3c187fa0e92708f0e220e0e22d09352a0bed30017c5b2be01f0c47b40219221f1ded0b12eb1f0127cc0bcc18c41a5e910d0edbc85193e0dadadbf8e8f9e8ced7dba5e0b6aaaca4dbfeabfef4eae1 + flags: 0 vcSharedLogLevel: value: 0d5e400f0650 flags: 0 @@ -15,8 +33,7 @@ EditorUserSettings: m_SemanticMergeMode: 2 m_VCShowFailedCheckout: 1 m_VCOverwriteFailedCheckoutAssets: 1 - m_VCOverlayIcons: 1 + m_VCProjectOverlayIcons: 1 + m_VCHierarchyOverlayIcons: 1 + m_VCOtherOverlayIcons: 1 m_VCAllowAsyncUpdate: 0 - m_AssetPipelineMode2: 1 - m_CacheServerMode: 0 - m_CacheServers: [] 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 7f1d3e043e0..0c6a11084d5 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 @@ -15,10 +15,12 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { sealed partial class DecalSubTarget : HDSubTarget, ILegacyTarget, IRequiresData { - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Decal/ShaderGraph/DecalPass.template"; - public DecalSubTarget() => displayName = "Decal"; + // TODO: remove this line + public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Decal/ShaderGraph/DecalPass.template"; + + protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Decal/ShaderGraph/DecalPass.template"; protected override string subTargetAssetGuid => "3ec927dfcb5d60e4883b2c224857b6c2"; protected override string customInspector => "Rendering.HighDefinition.DecalGUI"; protected override string renderType => HDRenderTypeTags.Opaque.ToString(); @@ -575,6 +577,7 @@ static class Descriptors }; } #endregion + // protected override IncludeCollection subShaderIncludes => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.hlsl"; #region Includes static class DecalIncludes 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 5c70bd5e45d..f908a20ca51 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 @@ -15,13 +15,16 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { sealed partial class EyeSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData { - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Eye/ShaderGraph/EyePass.template"; + public EyeSubTarget() => displayName = "Eye"; + + // TODO: remove this line + public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Eye/ShaderGraph/EyePass.template"; + + protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Eye/ShaderGraph/EyePass.template"; protected override string customInspector => "Rendering.HighDefinition.EyeGUI"; protected override string subTargetAssetGuid => "864e4e09d6293cf4d98457f740bb3301"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Eye; - public EyeSubTarget() => displayName = "Eye"; - EyeData m_EyeData; EyeData IRequiresData.data @@ -312,6 +315,7 @@ static class EyeBlockMasks }; } #endregion + protected override string subShaderInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl"; #region Includes static class EyeIncludes 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 e108633cb23..c5def643dbd 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 @@ -15,10 +15,12 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { sealed partial class FabricSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData { - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Fabric/ShaderGraph/FabricPass.template"; - public FabricSubTarget() => displayName = "Fabric"; + // TODO: remove this line + public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Fabric/ShaderGraph/FabricPass.template"; + + protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Fabric/ShaderGraph/FabricPass.template"; protected override string subTargetAssetGuid => "74f1a4749bab90d429ac01d094be0aeb"; // FabricSubTarget.cs protected override string customInspector => "Rendering.HighDefinition.FabricGUI"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Fabric; @@ -485,6 +487,8 @@ static class FabricDefines } #endregion + protected override string subShaderInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; + #region Includes static class FabricIncludes { 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 3af25e2b8cf..40df7d5a92e 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 @@ -15,13 +15,16 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { sealed partial class HairSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData { - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Hair/ShaderGraph/HairPass.template"; + public HairSubTarget() => displayName = "Hair"; + + // TODO: remove this line + public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Hair/ShaderGraph/HairPass.template"; + + protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Hair/ShaderGraph/HairPass.template"; protected override string customInspector => "Rendering.HighDefinition.HairGUI"; protected override string subTargetAssetGuid => "7e681cc79dd8e6c46ba1e8412d519e26"; // HairSubTarget.cs protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Hair; - public HairSubTarget() => displayName = "Hair"; - HairData m_HairData; HairData IRequiresData.data @@ -647,6 +650,7 @@ static class HairDefines }; } #endregion + protected override string subShaderInclude => CoreIncludes.kHair; #region Includes static class HairIncludes @@ -686,13 +690,19 @@ static class HairIncludes { CoreIncludes.kLighting, IncludeLocation.Pregraph }, { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, { CoreIncludes.kHair, IncludeLocation.Pregraph }, + // { postLightLoopIncludes, IncludeLocation.Pregraph }, { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, { CoreIncludes.CoreUtility }, { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, + // { postDecalIncludes, IncludeLocation.Pregraph }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, }; } + + // public override IncludeCollection postLightLoopIncludes => { CoreIncludes.kHair, ""}; + // public override IncludeCollection postDecalIncludes => new IncludeCollection { ""}; + #endregion } } 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..1bb13c9c32f 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 @@ -15,14 +15,18 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { sealed partial class HDLitSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData { - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; - public HDLitSubTarget() => displayName = "Lit"; + // TODO: remove this line + public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; + + protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; protected override string customInspector => "Rendering.HighDefinition.HDLitGUI"; protected override string subTargetAssetGuid => "caab952c840878340810cca27417971c"; // HDLitSubTarget.cs protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; + protected override bool supportDistortion => true; + HDLitData m_LitData; HDLitData IRequiresData.data @@ -47,7 +51,6 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); - AddDistortionFields(ref context); bool hasRefraction = (systemData.surfaceType == SurfaceType.Transparent && systemData.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction && litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None); @@ -95,7 +98,6 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) // Vertex base.GetActiveBlocks(ref context); - AddDistortionBlocks(ref context); AddNormalBlocks(ref context); // Common @@ -970,6 +972,8 @@ static class LitKeywords } #endregion + protected override string subShaderInclude => CoreIncludes.kLit; + #region Includes static class LitIncludes { 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 ae99d35dc01..fd7b12baa1b 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 @@ -46,6 +46,7 @@ protected virtual int ComputeMaterialNeedsUpdateHash() protected abstract string subTargetAssetGuid { get; } protected abstract string renderType { get; } protected abstract string renderQueue { get; } + protected abstract string templatePath { get; } public virtual string identifier => GetType().Name; 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..56fefa5ba0f 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 @@ -63,6 +63,8 @@ protected override int ComputeMaterialNeedsUpdateHash() return hash; } + protected override bool supportsLighting => true; + public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); 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 93acb78b7ad..3b605c740f2 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 @@ -35,9 +35,84 @@ protected override string renderQueue get => HDRenderQueue.GetShaderTagValue(HDRenderQueue.ChangeType(systemData.renderingPass, systemData.sortPriority, systemData.alphaTest)); } + protected virtual bool supportForward => false; + protected virtual bool supportsLighting => false; + protected virtual bool supportDistortion => false; + protected virtual bool supportRaytracing => false; + protected virtual bool supportPathtracing => false; + + // TODO: put this method as sealed when the new pass system is done + protected override IEnumerable EnumerateSubShaders() + { + yield return PostProcessSubShader(GetSubShaderDescriptor()); + if (supportRaytracing || supportPathtracing) + yield return PostProcessSubShader(GetRaytracingSubShaderDescriptor()); + } + + protected virtual SubShaderDescriptor GetSubShaderDescriptor() + { + return new SubShaderDescriptor + { + generatesPreview = true, + passes = GetPasses() + }; + + PassCollection GetPasses() + { + var passes = new PassCollection + { + // Common "surface" passes + // distortionPass, + // ShadowCaster, + // META, + // SceneSelection, + // MotionVector + }; + + // if (supportForward) + // passes.Add(); + if (supportDistortion) + passes.Add(distortionPass); + + return passes; + } + } + + // TODO: remove ? + SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor descriptor) + { + if (String.IsNullOrEmpty(descriptor.pipelineTag)) + descriptor.pipelineTag = HDRenderPipeline.k_ShaderTagName; + + return descriptor; + } + + protected virtual SubShaderDescriptor GetRaytracingSubShaderDescriptor() + { + return new SubShaderDescriptor + { + pipelineTag = HDRenderPipeline.k_ShaderTagName, + generatesPreview = true, + }; + + // PassCollection GetPasses() + // { + // var passes = new PassCollection + // { + // // TODO + // // Common "surface" raytracing passes + // }; + + // return passes; + // } + } + public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); + + if (supportDistortion) + AddDistortionFields(ref context); // Common properties between all "surface" master nodes (everything except decal right now) @@ -87,6 +162,9 @@ protected void AddDistortionFields(ref TargetFieldContext context) public override void GetActiveBlocks(ref TargetActiveBlockContext context) { + if (supportDistortion) + AddDistortionBlocks(ref context); + // Common block between all "surface" master nodes // Vertex context.AddBlock(BlockFields.VertexDescription.Position); @@ -189,5 +267,161 @@ public override void ProcessPreviewMaterial(Material material) HDLitGUI.SetupMaterialKeywordsAndPass(material); } + + // Common passes for all "surface" targets + + // protected virtual void EnumeratePassesForSubShader + + // public static PassDescriptor META = new PassDescriptor() + // { + // // Definition + // displayName = "META", + // referenceName = "SHADERPASS_LIGHT_TRANSPORT", + // lightMode = "META", + // useInPreview = false, + + // // Template + // passTemplatePath = templatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Block Mask + // validPixelBlocks = UnlitBlockMasks.FragmentDefault, + + // // Collections + // structs = CoreStructCollections.Default, + // requiredFields = new FieldCollection(){ CoreRequiredFields.Meta, HDFields.SubShader.Unlit }, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = CoreRenderStates.Meta, + // pragmas = CorePragmas.DotsInstancedInV2Only, + // keywords = CoreKeywords.HDBase, + // includes = UnlitIncludes.Meta, + // }; + + // public static PassDescriptor ShadowCaster = new PassDescriptor() + // { + // // Definition + // displayName = "ShadowCaster", + // referenceName = "SHADERPASS_SHADOWS", + // lightMode = "ShadowCaster", + // useInPreview = false, + + // // Template + // passTemplatePath = templatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Block Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, + + // // Collections + // structs = CoreStructCollections.Default, + // requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = CoreRenderStates.ShadowCaster, + // pragmas = CorePragmas.DotsInstancedInV2Only, + // keywords = CoreKeywords.HDBase, + // includes = UnlitIncludes.DepthOnly, + // }; + + // public static PassDescriptor SceneSelection = new PassDescriptor() + // { + // // Definition + // displayName = "SceneSelectionPass", + // referenceName = "SHADERPASS_DEPTH_ONLY", + // lightMode = "SceneSelectionPass", + // useInPreview = false, + + // // Template + // passTemplatePath = templatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Block Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, + + // // Collections + // structs = CoreStructCollections.Default, + // requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = UnlitRenderStates.SceneSelection, + // pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, + // defines = CoreDefines.SceneSelection, + // keywords = CoreKeywords.HDBase, + // includes = UnlitIncludes.DepthOnly, + // }; + + protected PassDescriptor distortionPass => new PassDescriptor() + { + // Definition + displayName = "DistortionVectors", + referenceName = "SHADERPASS_DISTORTION", + lightMode = "DistortionVectors", + useInPreview = true, + + // Template + passTemplatePath = templatePath, + sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // Port mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = FragmentDistortion, + + // Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = new RenderStateCollection + { + { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, + { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, + { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, + { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, + { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, + { RenderState.ZWrite(ZWrite.Off) }, + { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, + { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, + { RenderState.Stencil(new StencilDescriptor() { + WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, + Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, + Comp = "Always", + Pass = "Replace", + }) }, + }, + pragmas = CorePragmas.DotsInstancedInV1AndV2, + defines = CoreDefines.ShaderGraphRaytracingHigh, + keywords = CoreKeywords.HDBase, + includes = GenerateDistortionIncludes(), + }; + + IncludeCollection GenerateDistortionIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportsLighting) + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(subShaderInclude, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportsLighting) + { + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(postDecalsIncludes); + } + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph); + + return includes; + } + + protected abstract string subShaderInclude { get; } + protected virtual IncludeCollection postDecalsIncludes => null; + protected virtual IncludeCollection postGraphIncludes => null; + + public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.Distortion, + HDBlockFields.SurfaceDescription.DistortionBlur, + }; } } \ 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 2d94430967f..dd4835f7088 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 @@ -18,13 +18,17 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph // or let inputs (eg mask?) follow invalid values ? Lit does that (let them free running). sealed partial class StackLitSubTarget : LightingSubTarget, ILegacyTarget, IRequiresData { - const string kAssetGuid = "5f7ba34a143e67647b202a662748dae3"; - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/StackLit/ShaderGraph/StackLitPass.template"; + public StackLitSubTarget() => displayName = "StackLit"; + + // TODO: remove this line + public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/StackLit/ShaderGraph/StackLitPass.template"; + + protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/StackLit/ShaderGraph/StackLitPass.template"; protected override string customInspector => "Rendering.HighDefinition.StackLitGUI"; protected override string subTargetAssetGuid => "5f7ba34a143e67647b202a662748dae3"; // StackLitSubTarget.cs protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_StackLit; - public StackLitSubTarget() => displayName = "StackLit"; + protected override bool supportDistortion => true; StackLitData m_StackLitData; @@ -159,7 +163,6 @@ protected override IEnumerable EnumerateSubShaders() public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); - AddDistortionFields(ref context); // StackLit specific properties context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(StackLitSubTarget.StackLitPasses.MotionVectors)); @@ -287,7 +290,6 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) { base.GetActiveBlocks(ref context); AddNormalBlocks(ref context); - AddDistortionBlocks(ref context); // Common context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); @@ -995,6 +997,7 @@ static class StackLitPragmas }; } #endregion + protected override string subShaderInclude => CoreIncludes.kStackLit; #region Includes static class StackLitIncludes 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 index a88c6f67f9e..d2df57a2481 100644 --- 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 @@ -76,6 +76,7 @@ void UpgradeHDUnlitMasterNode(HDUnlitMasterNode1 hdUnlitMasterNode, out Dictiona builtinData.alphaToMask = hdUnlitMasterNode.m_AlphaToMask; builtinData.addPrecomputedVelocity = hdUnlitMasterNode.m_AddPrecomputedVelocity; + unlitData.distortionOnly = hdUnlitMasterNode.m_DistortionOnly; unlitData.enableShadowMatte = hdUnlitMasterNode.m_EnableShadowMatte; target.customEditorGUI = hdUnlitMasterNode.m_OverrideEnabled ? hdUnlitMasterNode.m_ShaderGUIOverride : ""; 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 2fbcf29e1fa..9acb85495f8 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 @@ -15,17 +15,23 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { sealed partial class HDUnlitSubTarget : SurfaceSubTarget, ILegacyTarget, IRequiresData { + public HDUnlitSubTarget() => displayName = "Unlit"; + + + // TODO: remove this line + public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template"; + // Templates // TODO: Why do the raytracing passes use the template for the pipeline agnostic Unlit master node? // TODO: This should be resolved so we can delete the second pass template static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template"; - static string raytracingPassTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/UnlitPass.template"; + protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Unlit; protected override string renderType => HDRenderTypeTags.HDUnlitShader.ToString(); protected override string subTargetAssetGuid => "4516595d40fa52047a77940183dc8e74"; // HDUnlitSubTarget protected override string customInspector => "Rendering.HighDefinition.HDUnlitGUI"; - public HDUnlitSubTarget() => displayName = "Unlit"; + protected override bool supportDistortion => true; HDUnlitData m_UnlitData; @@ -41,16 +47,26 @@ public HDUnlitData unlitData set => m_UnlitData = value; } - protected override IEnumerable EnumerateSubShaders() + protected override SubShaderDescriptor GetSubShaderDescriptor() { - yield return SubShaders.Unlit; - yield return SubShaders.UnlitRaytracing; + if (unlitData.distortionOnly) + { + return new SubShaderDescriptor + { + generatesPreview = true, + passes = new PassCollection{ distortionPass } + }; + // TODO + } + else + { + return base.GetSubShaderDescriptor(); + } } public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); - AddDistortionFields(ref context); // Unlit specific properties context.AddField(HDFields.EnableShadowMatte, unlitData.enableShadowMatte); @@ -60,7 +76,6 @@ public override void GetFields(ref TargetFieldContext context) public override void GetActiveBlocks(ref TargetActiveBlockContext context) { base.GetActiveBlocks(ref context); - AddDistortionBlocks(ref context); // Unlit specific blocks context.AddBlock(HDBlockFields.SurfaceDescription.ShadowTint, unlitData.enableShadowMatte); @@ -108,7 +123,7 @@ static class SubShaders { UnlitPasses.SceneSelection }, { UnlitPasses.DepthForwardOnly }, { UnlitPasses.MotionVectors }, - { UnlitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, + // { UnlitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, { UnlitPasses.ForwardOnly }, }, }; @@ -262,32 +277,6 @@ static class UnlitPasses includes = UnlitIncludes.MotionVectors, }; - public static PassDescriptor Distortion = new PassDescriptor() - { - // Definition - displayName = "DistortionVectors", - referenceName = "SHADERPASS_DISTORTION", - lightMode = "DistortionVectors", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = UnlitBlockMasks.FragmentDistortion, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.Distortion, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = UnlitIncludes.Distortion, - }; - public static PassDescriptor ForwardOnly = new PassDescriptor() { // Definition @@ -325,7 +314,7 @@ static class UnlitPasses useInPreview = false, // Template - passTemplatePath = raytracingPassTemplatePath, + passTemplatePath = passTemplatePath, sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, // Block Mask @@ -350,7 +339,7 @@ static class UnlitPasses useInPreview = false, // Template - passTemplatePath = raytracingPassTemplatePath, + passTemplatePath = passTemplatePath, sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, // Block Mask @@ -375,7 +364,7 @@ static class UnlitPasses useInPreview = false, // Template - passTemplatePath = raytracingPassTemplatePath, + passTemplatePath = passTemplatePath, sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, // Block Mask @@ -400,7 +389,7 @@ static class UnlitPasses useInPreview = false, // Template - passTemplatePath = raytracingPassTemplatePath, + passTemplatePath = passTemplatePath, sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, // Block Mask @@ -425,7 +414,7 @@ static class UnlitPasses useInPreview = false, // Template - passTemplatePath = raytracingPassTemplatePath, + passTemplatePath = passTemplatePath, sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, // Block Mask @@ -528,25 +517,6 @@ static class UnlitRenderStates Pass = "Replace", }) }, }; - - public static RenderStateCollection Distortion = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, - { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, - { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, - { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.Off) }, - { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, - { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, - Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, - Comp = "Always", - Pass = "Replace", - }) }, - }; } #endregion @@ -593,6 +563,7 @@ static class UnlitKeywords }; } #endregion + protected override string subShaderInclude => CoreIncludes.kUnlit; #region Includes static class UnlitIncludes From bdf5717d6cd3fed62b32e6b58ea12585f9d85907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Thu, 28 May 2020 14:41:09 +0200 Subject: [PATCH 12/30] Revert assets --- .../ProjectSettings/GraphicsSettings.asset | 2 +- .../UserSettings/EditorUserSettings.asset | 25 +++---------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/TestProjects/HDRP_Tests/ProjectSettings/GraphicsSettings.asset b/TestProjects/HDRP_Tests/ProjectSettings/GraphicsSettings.asset index dd90c191192..ca9dc00be0e 100644 --- a/TestProjects/HDRP_Tests/ProjectSettings/GraphicsSettings.asset +++ b/TestProjects/HDRP_Tests/ProjectSettings/GraphicsSettings.asset @@ -35,7 +35,7 @@ GraphicsSettings: m_PreloadedShaders: [] m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} - m_CustomRenderPipeline: {fileID: 11400000, guid: d7fe5f39d2c099a4ea1f1f610af309d7, + m_CustomRenderPipeline: {fileID: 11400000, guid: 8650072ee85219341b65a263bf871815, type: 2} m_TransparencySortMode: 0 m_TransparencySortAxis: {x: 0, y: 0, z: 1} diff --git a/TestProjects/HDRP_Tests/UserSettings/EditorUserSettings.asset b/TestProjects/HDRP_Tests/UserSettings/EditorUserSettings.asset index 2a64524a099..62e82ff008a 100644 --- a/TestProjects/HDRP_Tests/UserSettings/EditorUserSettings.asset +++ b/TestProjects/HDRP_Tests/UserSettings/EditorUserSettings.asset @@ -5,24 +5,6 @@ EditorUserSettings: m_ObjectHideFlags: 0 serializedVersion: 4 m_ConfigSettings: - RecentlyUsedScenePath-0: - value: 224247031146467c1f0f1c2a19206b1505030b651f2b233e283a526afadf1b2ceae224a6be6c6f6e0631e4350a30043bdf0f1a03d40a1e081907f3095cd01e5d04cb11d103 - flags: 0 - RecentlyUsedScenePath-1: - value: 224247031146467c1f0f1c2a19206b1505030b651f2b233e283a5262fadf1939f6e224e0e6362c736853bf6e3b0b0f33fb1e362fff181e04031af4011fb1051d18d101 - flags: 0 - RecentlyUsedScenePath-2: - value: 224247031146466f08031c6d046d4a1e1f0301 - flags: 0 - ShaderGraph.SubWindow: - value: 18135939215a0a5004000b0e15254b524c030a3f2964643d120d1230e9e93a3fd6e826abbd2e2d293c4ead313b08042de6030a0afa240c0d020be94c4ba65e435d8715fa32c70d15d11612dacc11fee5d3c5d1fe9ab1b7968e93e2ffcbc3e7e2f0b3ffe0e8b0be9af9f6afffff8e85dd8390e39d9f8899daa7 - flags: 0 - UnityEditor.ShaderGraph.FloatingWindowsLayout2: - value: 181344140043005e1a220d3b1f364b524c0c5a27130c293326201334cee5322ca0bd30e8eb293a707b0fd0180b3d0a36fc0d3d04e649500d1002ee0b5dbd1d2c27c00ad113cb1e10e41f1addc80993b982839aba94a9eae7f6d0b2fbeeffe0ecf4fd8afdacbbf9d4e8f5a8e7e1928b86ccf584cdd6c38b9da190c991e48183879786c994c0c5828a81d8eeddbf8debe691ada5959ea796aa8f9ab0b379bcba74243d73f8b187928fbeb2648d755c818e6635dc6d659f8ac0cb9f40a89b8d9a864c9dad9456d9c08f738b48d223425f5564477c5c695963435d6f7f5b492f7b236b76683825445f273c262a4d4a547f446a4733583f2c0e0a62711e4d7d5f686758400216064d1b4f487873735e6d726f6b3f577c7840716579002d00 - flags: 0 - UnityEditor.ShaderGraph.ToggleSettings: - value: 18135d1527590858060c032302276919051e1a26296a7c243f3c187fa0e92708f0e220e0e22d09352a0bed30017c5b2be01f0c47b40219221f1ded0b12eb1f0127cc0bcc18c41a5e910d0edbc85193e0dadadbf8e8f9e8ced7dba5e0b6aaaca4dbfeabfef4eae1 - flags: 0 vcSharedLogLevel: value: 0d5e400f0650 flags: 0 @@ -33,7 +15,8 @@ EditorUserSettings: m_SemanticMergeMode: 2 m_VCShowFailedCheckout: 1 m_VCOverwriteFailedCheckoutAssets: 1 - m_VCProjectOverlayIcons: 1 - m_VCHierarchyOverlayIcons: 1 - m_VCOtherOverlayIcons: 1 + m_VCOverlayIcons: 1 m_VCAllowAsyncUpdate: 0 + m_AssetPipelineMode2: 1 + m_CacheServerMode: 0 + m_CacheServers: [] From 78ac3d00bcc987194ce56247b45cfbde8b7403ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Thu, 28 May 2020 19:38:42 +0200 Subject: [PATCH 13/30] Started to factorize passes for Unlit & fix distortion only in the inspector UI --- .../ShaderGraph/DistortionPropertyBlock.cs | 9 +- .../Material/ShaderGraph/HDShaderPasses.cs | 352 ++++++++++++++++++ .../ShaderGraph/HDShaderPasses.cs.meta | 11 + .../Material/ShaderGraph/LightingSubTarget.cs | 2 +- .../Material/ShaderGraph/SurfaceSubTarget.cs | 234 +++++++----- .../HDUnlitDistortionPropertyBlock.cs | 3 +- .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 14 +- .../Editor/ShaderGraph/HDTarget.cs | 3 + 8 files changed, 525 insertions(+), 103 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs create mode 100644 com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs.meta 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 index 603e4d4da87..2a908b507f7 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DistortionPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/DistortionPropertyBlock.cs @@ -20,8 +20,13 @@ class DistortionPropertyBlock : SubTargetPropertyBlock 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); + if (builtinData.distortion) + { + context.globalIndentLevel++; + AddProperty(distortionBlendModeText, () => builtinData.distortionMode, (newValue) => builtinData.distortionMode = newValue); + AddProperty(distortionDepthTestText, () => builtinData.distortionDepthTest, (newValue) => builtinData.distortionDepthTest = newValue); + context.globalIndentLevel--; + } } } } \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs new file mode 100644 index 00000000000..e379cb519d3 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -0,0 +1,352 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.Rendering.HighDefinition; +using UnityEditor.ShaderGraph; +using UnityEditor.ShaderGraph.Internal; + +namespace UnityEditor.Rendering.HighDefinition.ShaderGraph +{ + static class HDShaderPasses + { +#region Distortion Pass + + public static PassDescriptor GenerateDistortionPass(bool supportsLighting) + { + return new PassDescriptor + { + // Definition + displayName = "DistortionVectors", + referenceName = "SHADERPASS_DISTORTION", + lightMode = "DistortionVectors", + useInPreview = true, + + // Template + // passTemplatePath = templatePath, + sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // Port mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = FragmentDistortion, + + // Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = new RenderStateCollection + { + { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, + { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, + { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, + { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, + { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, + { RenderState.ZWrite(ZWrite.Off) }, + { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, + { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, + { RenderState.Stencil(new StencilDescriptor() { + WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, + Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, + Comp = "Always", + Pass = "Replace", + }) }, + }, + pragmas = CorePragmas.DotsInstancedInV1AndV2, + defines = CoreDefines.ShaderGraphRaytracingHigh, + keywords = CoreKeywords.HDBase, + includes = GenerateDistortionIncludes(), + }; + + IncludeCollection GenerateDistortionIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportsLighting) + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportsLighting) + { + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph); + + return includes; + } + } + + public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.Distortion, + HDBlockFields.SurfaceDescription.DistortionBlur, + }; + +#endregion + +#region Scene Selection Pass + + public static PassDescriptor GenerateSceneSelectionPass() + { + return new PassDescriptor + { + // Definition + displayName = "SceneSelectionPass", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "SceneSelectionPass", + useInPreview = false, + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = FragmentSceneSelection, + + // Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = CoreRenderStates.SceneSelection, + pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, + defines = CoreDefines.SceneSelection, + keywords = CoreKeywords.HDBase, + includes = SceneSelectionIncludes, + }; + } + + public static BlockFieldDescriptor[] FragmentSceneSelection = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.DepthOffset, + }; + + public static IncludeCollection SceneSelectionIncludes = new IncludeCollection + { + { CoreIncludes.CorePregraph }, + { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, + { CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph }, + { CoreIncludes.CoreUtility }, + // We don't need decals for scene selection ? + // { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, + // { kLitDecalData, IncludeLocation.Pregraph }, + { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, + { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, + }; + +#endregion + +#region Shadow Caster Pass + + static public PassDescriptor GenerateShadowCasterPass(bool supportsLighting) + { + return new PassDescriptor() + { + // Definition + displayName = "ShadowCaster", + referenceName = "SHADERPASS_SHADOWS", + lightMode = "ShadowCaster", + useInPreview = false, + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = FragmentShadowCaster, + + // Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = CoreRenderStates.ShadowCaster, + pragmas = CorePragmas.DotsInstancedInV2Only, + keywords = CoreKeywords.HDBase, + includes = GenerateShadowCasterIncludes(), + }; + + IncludeCollection GenerateShadowCasterIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportsLighting) + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportsLighting) + { + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); + + return includes; + } + } + + public static BlockFieldDescriptor[] FragmentShadowCaster = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, + HDBlockFields.SurfaceDescription.DepthOffset, + }; + +#endregion + +#region META pass + + public static PassDescriptor GenerateMETAPass(bool supportsLighting) + { + return new PassDescriptor + { + // Definition + displayName = "META", + referenceName = "SHADERPASS_LIGHT_TRANSPORT", + lightMode = "META", + useInPreview = false, + + // Port Mask + validPixelBlocks = FragmentMeta, + + // Collections + structs = CoreStructCollections.Default, + requiredFields = CoreRequiredFields.Meta, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = CoreRenderStates.Meta, + pragmas = CorePragmas.DotsInstancedInV1AndV2, + defines = CoreDefines.ShaderGraphRaytracingHigh, + keywords = CoreKeywords.HDBase, + includes = GenerateMETAIncludes(), + }; + + IncludeCollection GenerateMETAIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportsLighting) + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportsLighting) + { + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph); + + return includes; + } + } + + public static BlockFieldDescriptor[] FragmentMeta = new BlockFieldDescriptor[] + { + // TODO: this will probably break with unlit / other target that does not support all of these fields + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalWS, + BlockFields.SurfaceDescription.NormalOS, + HDBlockFields.SurfaceDescription.BentNormal, + HDBlockFields.SurfaceDescription.Tangent, + HDBlockFields.SurfaceDescription.SubsurfaceMask, + HDBlockFields.SurfaceDescription.Thickness, + HDBlockFields.SurfaceDescription.DiffusionProfileHash, + HDBlockFields.SurfaceDescription.IridescenceMask, + HDBlockFields.SurfaceDescription.IridescenceThickness, + BlockFields.SurfaceDescription.Specular, + HDBlockFields.SurfaceDescription.CoatMask, + BlockFields.SurfaceDescription.Metallic, + BlockFields.SurfaceDescription.Emission, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Occlusion, + HDBlockFields.SurfaceDescription.SpecularOcclusion, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.Anisotropy, + HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, + HDBlockFields.SurfaceDescription.SpecularAAThreshold, + HDBlockFields.SurfaceDescription.RefractionIndex, + HDBlockFields.SurfaceDescription.RefractionColor, + HDBlockFields.SurfaceDescription.RefractionDistance, + }; + +#endregion + +#region Depth Forward Only + + public static PassDescriptor GenerateDepthForwardOnly(bool supportsLighting) + { + return new PassDescriptor + { + // Definition + displayName = "DepthForwardOnly", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "DepthForwardOnly", + useInPreview = true, + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = FragmentDepthMotionVectors, + + // Collections + structs = CoreStructCollections.Default, + requiredFields = GenerateRequiredFields(), + fieldDependencies = CoreFieldDependencies.Default, + renderStates = CoreRenderStates.DepthOnly, + pragmas = CorePragmas.DotsInstancedInV2Only, + defines = CoreDefines.DepthMotionVectors, + keywords = CoreKeywords.DepthMotionVectorsNoNormal, + includes = GenerateIncludes(), + }; + + FieldCollection GenerateRequiredFields() + { + return new FieldCollection() + { + HDStructFields.AttributesMesh.normalOS, + HDStructFields.AttributesMesh.tangentOS, + HDStructFields.AttributesMesh.uv0, + HDStructFields.AttributesMesh.uv1, + HDStructFields.AttributesMesh.color, + HDStructFields.AttributesMesh.uv2, + HDStructFields.AttributesMesh.uv3, + HDStructFields.FragInputs.tangentToWorld, + HDStructFields.FragInputs.positionRWS, + HDStructFields.FragInputs.texCoord1, + HDStructFields.FragInputs.texCoord2, + HDStructFields.FragInputs.texCoord3, + HDStructFields.FragInputs.color, + }; + } + + IncludeCollection GenerateIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportsLighting) + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportsLighting) + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); + + return includes; + } + } + + public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.DepthOffset, + }; + +#endregion + + } +} \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs.meta b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs.meta new file mode 100644 index 00000000000..90e8be024fd --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7a33cf036ff73864fa9001a7e267d4a3 +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/LightingSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/LightingSubTarget.cs index f8a1e80a34f..6d6db1b5775 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 @@ -63,7 +63,7 @@ protected override int ComputeMaterialNeedsUpdateHash() return hash; } - protected override bool supportsLighting => true; + protected override bool supportLighting => true; public override void GetFields(ref TargetFieldContext context) { 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 3b605c740f2..7aac0341517 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 @@ -36,11 +36,15 @@ protected override string renderQueue } protected virtual bool supportForward => false; - protected virtual bool supportsLighting => false; + protected virtual bool supportLighting => false; protected virtual bool supportDistortion => false; protected virtual bool supportRaytracing => false; protected virtual bool supportPathtracing => false; + protected abstract string subShaderInclude { get; } + protected virtual string postDecalsIncludes => null; + protected virtual string postGraphIncludes => null; + // TODO: put this method as sealed when the new pass system is done protected override IEnumerable EnumerateSubShaders() { @@ -62,36 +66,26 @@ PassCollection GetPasses() var passes = new PassCollection { // Common "surface" passes - // distortionPass, - // ShadowCaster, - // META, - // SceneSelection, + HDShaderPasses.GenerateSceneSelectionPass(), + HDShaderPasses.GenerateShadowCasterPass(supportLighting), + HDShaderPasses.GenerateMETAPass(supportLighting), // MotionVector }; - - // if (supportForward) + + if (supportForward) + passes.Add(HDShaderPasses.GenerateDepthForwardOnly(supportLighting)); // passes.Add(); if (supportDistortion) - passes.Add(distortionPass); + passes.Add(HDShaderPasses.GenerateDistortionPass(supportLighting), new FieldCondition(HDFields.TransparentDistortion, true)); return passes; } } - // TODO: remove ? - SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor descriptor) - { - if (String.IsNullOrEmpty(descriptor.pipelineTag)) - descriptor.pipelineTag = HDRenderPipeline.k_ShaderTagName; - - return descriptor; - } - protected virtual SubShaderDescriptor GetRaytracingSubShaderDescriptor() { return new SubShaderDescriptor { - pipelineTag = HDRenderPipeline.k_ShaderTagName, generatesPreview = true, }; @@ -107,6 +101,47 @@ protected virtual SubShaderDescriptor GetRaytracingSubShaderDescriptor() // } } + SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor) + { + if (String.IsNullOrEmpty(subShaderDescriptor.pipelineTag)) + subShaderDescriptor.pipelineTag = HDRenderPipeline.k_ShaderTagName; + + var passes = subShaderDescriptor.passes.ToArray(); + PassCollection finalPasses = new PassCollection(); + for (int i = 0; i < passes.Length; i++) + { + var passDescriptor = passes[i].descriptor; + passDescriptor.passTemplatePath = templatePath; + passDescriptor.sharedTemplateDirectory = HDTarget.sharedTemplateDirectory; + + IncludeCollection finalIncludes = new IncludeCollection(); + var includeList = passDescriptor.includes.Select(i => i.descriptor).ToList(); + + + // Replace include placeholders if necessary: + foreach (var include in passDescriptor.includes) + { + if (include.descriptor.value == CoreIncludes.kPassPlaceholder) + include.descriptor.value = subShaderInclude; + if (include.descriptor.value == CoreIncludes.kPostDecalsPlaceholder) + include.descriptor.value = postDecalsIncludes; + if (include.descriptor.value == CoreIncludes.kPostGraphPlaceholder) + include.descriptor.value = postGraphIncludes; + + if (!String.IsNullOrEmpty(include.descriptor.value)) + finalIncludes.Add(include.descriptor.value, include.descriptor.location, include.fieldConditions); + } + + passDescriptor.includes = finalIncludes; + + finalPasses.Add(passDescriptor, passes[i].fieldConditions); + } + + subShaderDescriptor.passes = finalPasses; + + return subShaderDescriptor; + } + public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); @@ -350,78 +385,101 @@ public override void ProcessPreviewMaterial(Material material) // includes = UnlitIncludes.DepthOnly, // }; - protected PassDescriptor distortionPass => new PassDescriptor() - { - // Definition - displayName = "DistortionVectors", - referenceName = "SHADERPASS_DISTORTION", - lightMode = "DistortionVectors", - useInPreview = true, - - // Template - passTemplatePath = templatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FragmentDistortion, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, - { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, - { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, - { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.Off) }, - { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, - { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, - { RenderState.Stencil(new StencilDescriptor() { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, - Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, - Comp = "Always", - Pass = "Replace", - }) }, - }, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = GenerateDistortionIncludes(), - }; - - IncludeCollection GenerateDistortionIncludes() - { - var includes = new IncludeCollection(); - - includes.Add(CoreIncludes.CorePregraph); - if (supportsLighting) - includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); - includes.Add(subShaderInclude, IncludeLocation.Pregraph); - includes.Add(CoreIncludes.CoreUtility); - if (supportsLighting) - { - includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); - includes.Add(postDecalsIncludes); - } - includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); - includes.Add(CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph); + // protected PassDescriptor sceneSelectionPass => new PassDescriptor() + // { + // // Definition + // displayName = "SceneSelectionPass", + // referenceName = "SHADERPASS_DEPTH_ONLY", + // lightMode = "SceneSelectionPass", + // useInPreview = false, - return includes; - } + // // Template + // passTemplatePath = templatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - protected abstract string subShaderInclude { get; } - protected virtual IncludeCollection postDecalsIncludes => null; - protected virtual IncludeCollection postGraphIncludes => null; + // // Block Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Distortion, - HDBlockFields.SurfaceDescription.DistortionBlur, - }; + // // Collections + // structs = CoreStructCollections.Default, + // requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = UnlitRenderStates.SceneSelection, + // pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, + // defines = CoreDefines.SceneSelection, + // keywords = CoreKeywords.HDBase, + // includes = UnlitIncludes.DepthOnly, + // }; + + // protected PassDescriptor distortionPass => new PassDescriptor() + // { + // // Definition + // displayName = "DistortionVectors", + // referenceName = "SHADERPASS_DISTORTION", + // lightMode = "DistortionVectors", + // useInPreview = true, + + // // Template + // passTemplatePath = templatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = FragmentDistortion, + + // // Collections + // structs = CoreStructCollections.Default, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = new RenderStateCollection + // { + // { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, + // { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, + // { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, + // { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, + // { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, + // { RenderState.ZWrite(ZWrite.Off) }, + // { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, + // { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, + // { RenderState.Stencil(new StencilDescriptor() { + // WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, + // Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, + // Comp = "Always", + // Pass = "Replace", + // }) }, + // }, + // pragmas = CorePragmas.DotsInstancedInV1AndV2, + // defines = CoreDefines.ShaderGraphRaytracingHigh, + // keywords = CoreKeywords.HDBase, + // includes = GenerateDistortionIncludes(), + // }; + + // IncludeCollection GenerateDistortionIncludes() + // { + // var includes = new IncludeCollection(); + + // includes.Add(CoreIncludes.CorePregraph); + // if (supportsLighting) + // includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + // includes.Add(subShaderInclude, IncludeLocation.Pregraph); + // includes.Add(CoreIncludes.CoreUtility); + // if (supportsLighting) + // { + // includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + // includes.Add(postDecalsIncludes); + // } + // includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + // includes.Add(CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph); + + // return includes; + // } + + // public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] + // { + // BlockFields.SurfaceDescription.Alpha, + // BlockFields.SurfaceDescription.AlphaClipThreshold, + // HDBlockFields.SurfaceDescription.Distortion, + // HDBlockFields.SurfaceDescription.DistortionBlur, + // }; } } \ No newline at end of file diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs index b52e23c356c..badd39fbf27 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs @@ -20,8 +20,9 @@ class HDUnlitDistortionPropertyBlock : DistortionPropertyBlock protected override void CreatePropertyGUI() { - AddProperty(distortionOnlyText, () => unlitData.distortionOnly, (newValue) => unlitData.distortionOnly = newValue); base.CreatePropertyGUI(); + if (builtinData.distortion) + AddProperty(distortionOnlyText, () => unlitData.distortionOnly, (newValue) => unlitData.distortionOnly = newValue, 1); } } } \ No newline at end of file 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 d3b19263f85..cb8a86985d1 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 @@ -31,6 +31,7 @@ sealed partial class HDUnlitSubTarget : SurfaceSubTarget, ILegacyTarget, IRequir protected override string customInspector => "Rendering.HighDefinition.HDUnlitGUI"; protected override bool supportDistortion => true; + protected override bool supportForward => true; HDUnlitData m_UnlitData; @@ -48,14 +49,13 @@ public HDUnlitData unlitData protected override SubShaderDescriptor GetSubShaderDescriptor() { - if (unlitData.distortionOnly) + if (unlitData.distortionOnly && builtinData.distortion) { return new SubShaderDescriptor { generatesPreview = true, - passes = new PassCollection{ distortionPass } + passes = new PassCollection{ { HDShaderPasses.GenerateDistortionPass(false), new FieldCondition(HDFields.TransparentDistortion, true) } } }; - // TODO } else { @@ -448,14 +448,6 @@ static class UnlitBlockMasks BlockFields.SurfaceDescription.AlphaClipThreshold, }; - public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Distortion, - HDBlockFields.SurfaceDescription.DistortionBlur, - }; - public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] { BlockFields.SurfaceDescription.BaseColor, 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 a39cc2460f5..29920c6ec49 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs @@ -970,6 +970,9 @@ static class CoreIncludes // Public Pregraph Misc public const string kShaderGraphFunctions = "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderGraphFunctions.hlsl"; public const string kDecalUtilities = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"; + public const string kPassPlaceholder = "Pass Include Placeholder, replace me !"; + public const string kPostDecalsPlaceholder = "After Decal Include Placeholder, replace me !"; + public const string kPostGraphPlaceholder = "After Graph Include Placeholder, replace me !"; // Public Postgraph Pass public const string kPassLightTransport = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl"; From a3272d6cbcd7f1a67bfdc963668d1401b0064db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Fri, 29 May 2020 16:34:37 +0200 Subject: [PATCH 14/30] Shared all non DXR passes between shaders --- .../Eye/ShaderGraph/EyeSubTarget.Migration.cs | 2 +- .../Material/Eye/ShaderGraph/EyeSubTarget.cs | 584 ++++---- .../ShaderGraph/FabricSubTarget.Migration.cs | 2 +- .../Fabric/ShaderGraph/FabricSubTarget.cs | 910 ++++++------ .../ShaderGraph/HairSubTarget.Migration.cs | 2 +- .../Hair/ShaderGraph/HairSubTarget.cs | 1222 ++++++++--------- .../ShaderGraph/HDLitSubTarget.Migration.cs | 2 +- .../Lit/ShaderGraph/HDLitSubTarget.cs | 531 +++---- .../Material/ShaderGraph/HDShaderPasses.cs | 537 +++++++- .../Material/ShaderGraph/LightingSubTarget.cs | 6 + .../ShaderGraph/SurfaceOptionPropertyBlock.cs | 2 +- .../Material/ShaderGraph/SurfaceSubTarget.cs | 221 +-- .../StackLitSubTarget.Migration.cs | 2 +- .../StackLit/ShaderGraph/StackLitSubTarget.cs | 2 - .../ShaderGraph/HDUnlitSubTarget.Migration.cs | 6 +- .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 1008 +++++++------- .../ShaderGraph/HDSubShaderUtilities.cs | 6 +- .../Editor/ShaderGraph/HDTarget.cs | 2 +- .../ShaderGraph/TargetData/SystemData.cs | 4 +- 19 files changed, 2674 insertions(+), 2377 deletions(-) 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 index c3e7a09fc60..e9535f74d4a 100644 --- 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 @@ -29,7 +29,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary "Rendering.HighDefinition.EyeGUI"; protected override string subTargetAssetGuid => "864e4e09d6293cf4d98457f740bb3301"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Eye; + protected override string subShaderInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl"; EyeData m_EyeData; @@ -39,17 +40,11 @@ public EyeData eyeData set => m_EyeData = value; } - protected override IEnumerable EnumerateSubShaders() - { - yield return SubShaders.Eye; - } - public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); // Eye specific properties - context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(EyeSubTarget.EyePasses.MotionVectors)); 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); @@ -76,294 +71,293 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); } -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Eye = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { EyePasses.ShadowCaster }, - { EyePasses.META }, - { EyePasses.SceneSelection }, - { EyePasses.DepthForwardOnly }, - { EyePasses.MotionVectors }, - { EyePasses.ForwardOnly }, - }, - }; - } -#endregion - -#region Passes - public static class EyePasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validPixelBlocks = EyeBlockMasks.FragmentMETA, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = EyeIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = EyeBlockMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.BlendShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = EyeIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = EyeBlockMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.SceneSelection, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = EyeIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = EyeBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = EyeIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = EyeBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = EyeIncludes.MotionVectors, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = EyeBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Forward, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = EyeIncludes.ForwardOnly, - }; - } -#endregion - -#region BlockMasks - static class EyeBlockMasks - { - public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - HDBlockFields.SurfaceDescription.IrisNormal, - BlockFields.SurfaceDescription.Smoothness, - HDBlockFields.SurfaceDescription.IOR, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.Mask, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - }; - - public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - HDBlockFields.SurfaceDescription.IrisNormal, - BlockFields.SurfaceDescription.Smoothness, - HDBlockFields.SurfaceDescription.IOR, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.Mask, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - } -#endregion - protected override string subShaderInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl"; - -#region Includes - static class EyeIncludes - { - const string kEye = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl"; - - public static IncludeCollection Common = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { kEye, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { kEye, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - } -#endregion +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Eye = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { EyePasses.ShadowCaster }, +// { EyePasses.META }, +// { EyePasses.SceneSelection }, +// { EyePasses.DepthForwardOnly }, +// { EyePasses.MotionVectors }, +// { EyePasses.ForwardOnly }, +// }, +// }; +// } +// #endregion + +// #region Passes +// public static class EyePasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validPixelBlocks = EyeBlockMasks.FragmentMETA, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = EyeIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = EyeBlockMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.BlendShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = EyeIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = EyeBlockMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.SceneSelection, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = EyeIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = EyeBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = EyeIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = EyeBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = EyeIncludes.MotionVectors, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = EyeBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Forward, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = EyeIncludes.ForwardOnly, +// }; +// } +// #endregion + +// #region BlockMasks +// static class EyeBlockMasks +// { +// public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// HDBlockFields.SurfaceDescription.IrisNormal, +// BlockFields.SurfaceDescription.Smoothness, +// HDBlockFields.SurfaceDescription.IOR, +// BlockFields.SurfaceDescription.Occlusion, +// HDBlockFields.SurfaceDescription.Mask, +// HDBlockFields.SurfaceDescription.DiffusionProfileHash, +// HDBlockFields.SurfaceDescription.SubsurfaceMask, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// }; + +// public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// HDBlockFields.SurfaceDescription.IrisNormal, +// BlockFields.SurfaceDescription.Smoothness, +// HDBlockFields.SurfaceDescription.IOR, +// BlockFields.SurfaceDescription.Occlusion, +// HDBlockFields.SurfaceDescription.Mask, +// HDBlockFields.SurfaceDescription.DiffusionProfileHash, +// HDBlockFields.SurfaceDescription.SubsurfaceMask, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.BakedGI, +// HDBlockFields.SurfaceDescription.BakedBackGI, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; +// } +// #endregion + +// #region Includes +// static class EyeIncludes +// { +// const string kEye = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl"; + +// public static IncludeCollection Common = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { kEye, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; + +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { kEye, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; +// } +// #endregion } } 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 b84fd2e2086..09282613ec4 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 @@ -27,7 +27,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary "74f1a4749bab90d429ac01d094be0aeb"; // FabricSubTarget.cs protected override string customInspector => "Rendering.HighDefinition.FabricGUI"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Fabric; + protected override string subShaderInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; FabricData m_FabricData; @@ -39,18 +40,11 @@ public FabricData fabricData set => m_FabricData = value; } - protected override IEnumerable EnumerateSubShaders() - { - yield return SubShaders.Fabric; - yield return SubShaders.FabricRaytracing; - } - public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); // Fabric specific properties - context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(FabricSubTarget.FabricPasses.MotionVectors)); 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); @@ -85,457 +79,455 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); } -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Fabric = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { FabricPasses.ShadowCaster }, - { FabricPasses.META }, - { FabricPasses.SceneSelection }, - { FabricPasses.DepthForwardOnly }, - { FabricPasses.MotionVectors }, - { FabricPasses.ForwardOnly }, - }, - }; - - public static SubShaderDescriptor FabricRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { FabricPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion - -#region Passes - public static class FabricPasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validPixelBlocks = FabricBlockMasks.FragmentMETA, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = FabricIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.BlendShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = FabricIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.ShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = FabricIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = FabricIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = FabricIncludes.MotionVectors, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Forward, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = FabricIncludes.ForwardOnly, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingIndirect, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingSubSurface = new PassDescriptor() - { - //Definition - displayName = "SubSurfaceDXR", - referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", - lightMode = "SubSurfaceDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - //Port mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingSubSurface }, - }; - } -#endregion - -#region BlockMasks - static class FabricBlockMasks - { - public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.Anisotropy, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - }; - - public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - HDBlockFields.SurfaceDescription.BentNormal, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.Anisotropy, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - } -#endregion - -#region Defines - static class FabricDefines - { - public static DefineCollection RaytracingForwardIndirect = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingGBuffer = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - }; - } -#endregion - - protected override string subShaderInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; - -#region Includes - static class FabricIncludes - { - const string kFabric = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; - - public static IncludeCollection Common = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { kFabric, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { kFabric, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - } -#endregion +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Fabric = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { FabricPasses.ShadowCaster }, +// { FabricPasses.META }, +// { FabricPasses.SceneSelection }, +// { FabricPasses.DepthForwardOnly }, +// { FabricPasses.MotionVectors }, +// { FabricPasses.ForwardOnly }, +// }, +// }; + +// public static SubShaderDescriptor FabricRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { FabricPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion + +// #region Passes +// public static class FabricPasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validPixelBlocks = FabricBlockMasks.FragmentMETA, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = FabricIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.BlendShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = FabricIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.ShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = FabricIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = FabricIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = FabricIncludes.MotionVectors, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Forward, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = FabricIncludes.ForwardOnly, +// }; + +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingIndirect, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingIndirect }, +// }; + +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingVisibility }, +// }; + +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingForward }, +// }; + +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RayTracingGBuffer }, +// }; + +// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() +// { +// //Definition +// displayName = "SubSurfaceDXR", +// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", +// lightMode = "SubSurfaceDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// //Port mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingSubSurface }, +// }; +// } +// #endregion + +// #region BlockMasks +// static class FabricBlockMasks +// { +// public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Specular, +// HDBlockFields.SurfaceDescription.DiffusionProfileHash, +// HDBlockFields.SurfaceDescription.SubsurfaceMask, +// HDBlockFields.SurfaceDescription.Thickness, +// HDBlockFields.SurfaceDescription.Tangent, +// HDBlockFields.SurfaceDescription.Anisotropy, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// }; + +// public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// HDBlockFields.SurfaceDescription.BentNormal, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Specular, +// HDBlockFields.SurfaceDescription.DiffusionProfileHash, +// HDBlockFields.SurfaceDescription.SubsurfaceMask, +// HDBlockFields.SurfaceDescription.Thickness, +// HDBlockFields.SurfaceDescription.Tangent, +// HDBlockFields.SurfaceDescription.Anisotropy, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.BakedGI, +// HDBlockFields.SurfaceDescription.BakedBackGI, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; +// } +// #endregion + +// #region Defines +// static class FabricDefines +// { +// public static DefineCollection RaytracingForwardIndirect = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingGBuffer = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// }; +// } +// #endregion + +// #region Includes +// static class FabricIncludes +// { +// const string kFabric = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; + +// public static IncludeCollection Common = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { kFabric, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; + +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { kFabric, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; +// } +// #endregion } } 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 index 6fb353b4447..0504bcc8352 100644 --- 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 @@ -29,7 +29,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary "Rendering.HighDefinition.HairGUI"; protected override string subTargetAssetGuid => "7e681cc79dd8e6c46ba1e8412d519e26"; // HairSubTarget.cs protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Hair; + protected override string subShaderInclude => CoreIncludes.kHair; HairData m_HairData; @@ -39,12 +40,6 @@ public HairData hairData set => m_HairData = value; } - protected override IEnumerable EnumerateSubShaders() - { - yield return SubShaders.Hair; - yield return SubShaders.HairRaytracing; - } - public override void GetFields(ref TargetFieldContext context) { // TODO: move this elsewhere: @@ -54,7 +49,6 @@ public override void GetFields(ref TargetFieldContext context) base.GetFields(ref context); // Hair specific properties: - context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(HairSubTarget.HairPasses.MotionVectors)); 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)); @@ -95,614 +89,610 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL blockList.AddPropertyBlock(new HairAdvancedOptionsPropertyBlock(hairData)); } -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Hair = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { HairPasses.ShadowCaster }, - { HairPasses.META }, - { HairPasses.SceneSelection }, - { HairPasses.DepthForwardOnly }, - { HairPasses.MotionVectors }, - { HairPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, - { HairPasses.TransparentDepthPrepass, new FieldCondition(HDFields.TransparentDepthPrePass, true) }, - { HairPasses.ForwardOnly }, - { HairPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, - }, - }; - - public static SubShaderDescriptor HairRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { HairPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion - -#region Passes - public static class HairPasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validPixelBlocks = HairBlockMasks.FragmentMETA, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentShadowCaster, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.BlendShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.SceneSelection, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = HairRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = HairIncludes.MotionVectors, - }; - - public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPrepass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPrepass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentTransparentDepthPrepass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPrePostPass, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.TransparentDepthPrepass, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor TransparentBackface = new PassDescriptor() - { - // Definition - displayName = "TransparentBackface", - referenceName = "SHADERPASS_FORWARD", - lightMode = "TransparentBackface", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentTransparentBackface, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentBackface, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = HairIncludes.ForwardOnly, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.ForwardColorMask, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = HairIncludes.ForwardOnly, - }; - - public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPostpass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPostpass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentTransparentDepthPostpass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPrePostPass, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingIndirect, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingForwardIndirect, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingSubSurface = new PassDescriptor() - { - //Definition - displayName = "SubSurfaceDXR", - referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", - lightMode = "SubSurfaceDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingSubSurface }, - }; - } -#endregion - -#region BlockMasks - static class HairBlockMasks - { - public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - }; - - public static BlockFieldDescriptor[] FragmentShadowCaster = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentTransparentBackface = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - } -#endregion - -#region RenderStates - static class HairRenderStates - { - public static RenderStateCollection MotionVectors = new RenderStateCollection - { - { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, - Ref = CoreRenderStates.Uniforms.stencilRefMV, - Comp = "Always", - Pass = "Replace", - }) }, - }; - } -#endregion - -#region Defines - static class HairDefines - { - public static DefineCollection RaytracingForwardIndirect = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingGBuffer = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - }; - } -#endregion - protected override string subShaderInclude => CoreIncludes.kHair; - -#region Includes - static class HairIncludes - { - public static IncludeCollection Common = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kHair, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { CoreIncludes.kHair, IncludeLocation.Pregraph }, - // { postLightLoopIncludes, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - // { postDecalIncludes, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - } - - // public override IncludeCollection postLightLoopIncludes => { CoreIncludes.kHair, ""}; - // public override IncludeCollection postDecalIncludes => new IncludeCollection { ""}; - -#endregion +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Hair = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { HairPasses.ShadowCaster }, +// { HairPasses.META }, +// { HairPasses.SceneSelection }, +// { HairPasses.DepthForwardOnly }, +// { HairPasses.MotionVectors }, +// { HairPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, +// { HairPasses.TransparentDepthPrepass, new FieldCondition(HDFields.TransparentDepthPrePass, true) }, +// { HairPasses.ForwardOnly }, +// { HairPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, +// }, +// }; + +// public static SubShaderDescriptor HairRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { HairPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion + +// #region Passes +// public static class HairPasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validPixelBlocks = HairBlockMasks.FragmentMETA, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentShadowCaster, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.BlendShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.SceneSelection, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = HairRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = HairIncludes.MotionVectors, +// }; + +// public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPrepass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPrepass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentTransparentDepthPrepass, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPrePostPass, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.TransparentDepthPrepass, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor TransparentBackface = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentBackface", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "TransparentBackface", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentTransparentBackface, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitMinimal, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentBackface, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = HairIncludes.ForwardOnly, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.ForwardColorMask, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = HairIncludes.ForwardOnly, +// }; + +// public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPostpass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPostpass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentTransparentDepthPostpass, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPrePostPass, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingIndirect, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingIndirect }, +// }; + +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingVisibility }, +// }; + +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingForwardIndirect, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingForward }, +// }; + +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RayTracingGBuffer }, +// }; + +// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() +// { +// //Definition +// displayName = "SubSurfaceDXR", +// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", +// lightMode = "SubSurfaceDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingSubSurface }, +// }; +// } +// #endregion + +// #region BlockMasks +// static class HairBlockMasks +// { +// public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// HDBlockFields.SurfaceDescription.BentNormal, +// HDBlockFields.SurfaceDescription.HairStrandDirection, +// HDBlockFields.SurfaceDescription.Transmittance, +// HDBlockFields.SurfaceDescription.RimTransmissionIntensity, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// HDBlockFields.SurfaceDescription.SpecularTint, +// HDBlockFields.SurfaceDescription.SpecularShift, +// HDBlockFields.SurfaceDescription.SecondarySpecularTint, +// HDBlockFields.SurfaceDescription.SecondarySmoothness, +// HDBlockFields.SurfaceDescription.SecondarySpecularShift, +// }; + +// public static BlockFieldDescriptor[] FragmentShadowCaster = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentBackface = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// HDBlockFields.SurfaceDescription.BentNormal, +// HDBlockFields.SurfaceDescription.HairStrandDirection, +// HDBlockFields.SurfaceDescription.Transmittance, +// HDBlockFields.SurfaceDescription.RimTransmissionIntensity, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// HDBlockFields.SurfaceDescription.SpecularTint, +// HDBlockFields.SurfaceDescription.SpecularShift, +// HDBlockFields.SurfaceDescription.SecondarySpecularTint, +// HDBlockFields.SurfaceDescription.SecondarySmoothness, +// HDBlockFields.SurfaceDescription.SecondarySpecularShift, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// HDBlockFields.SurfaceDescription.BentNormal, +// HDBlockFields.SurfaceDescription.HairStrandDirection, +// HDBlockFields.SurfaceDescription.Transmittance, +// HDBlockFields.SurfaceDescription.RimTransmissionIntensity, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// HDBlockFields.SurfaceDescription.SpecularTint, +// HDBlockFields.SurfaceDescription.SpecularShift, +// HDBlockFields.SurfaceDescription.SecondarySpecularTint, +// HDBlockFields.SurfaceDescription.SecondarySmoothness, +// HDBlockFields.SurfaceDescription.SecondarySpecularShift, +// HDBlockFields.SurfaceDescription.BakedGI, +// HDBlockFields.SurfaceDescription.BakedBackGI, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; +// } +// #endregion + +// #region RenderStates +// static class HairRenderStates +// { +// public static RenderStateCollection MotionVectors = new RenderStateCollection +// { +// { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, +// Ref = CoreRenderStates.Uniforms.stencilRefMV, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; +// } +// #endregion + +// #region Defines +// static class HairDefines +// { +// public static DefineCollection RaytracingForwardIndirect = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingGBuffer = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// }; +// } +// #endregion + +// #region Includes +// static class HairIncludes +// { +// public static IncludeCollection Common = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kHair, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; + +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { CoreIncludes.kHair, IncludeLocation.Pregraph }, +// // { postLightLoopIncludes, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// // { postDecalIncludes, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; +// } + +// #endregion } } 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 dd889cfe8de..3284f827b38 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 @@ -101,7 +101,7 @@ void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary HDShaderUtils.ShaderID.SG_Lit; protected override bool supportDistortion => true; + protected override bool supportForward => false; + protected override string postDecalsInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; HDLitData m_LitData; @@ -41,11 +43,17 @@ public HDLitData litData set => m_LitData = value; } - // Iterate over the sub passes available in the shader - protected override IEnumerable EnumerateSubShaders() + protected override SubShaderDescriptor GetSubShaderDescriptor() { - yield return SubShaders.Lit; - yield return SubShaders.LitRaytracing; + var descriptor = base.GetSubShaderDescriptor(); + + // TODO: move these passes in HDShaderPasses + descriptor.passes.Add(LitPasses.DepthOnly); + descriptor.passes.Add(LitPasses.GBuffer); + descriptor.passes.Add(LitPasses.Forward); + descriptor.passes.Add(LitPasses.RayTracingPrepass); + + return descriptor; } public override void GetFields(ref TargetFieldContext context) @@ -55,8 +63,6 @@ public override void GetFields(ref TargetFieldContext context) bool hasRefraction = (systemData.surfaceType == SurfaceType.Transparent && systemData.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction && litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None); // Lit specific properties - context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(HDLitSubTarget.LitPasses.MotionVectors)); - context.AddField(HDFields.DotsProperties, context.hasDotsProperties); // Material @@ -69,9 +75,6 @@ public override void GetFields(ref TargetFieldContext context) (litData.materialType == HDLitData.MaterialType.Translucent)); context.AddField(HDFields.Translucent, litData.materialType == HDLitData.MaterialType.Translucent); - context.AddField(HDFields.DoubleSidedFlip, systemData.doubleSidedMode == DoubleSidedMode.FlippedNormals && !context.pass.Equals(HDLitSubTarget.LitPasses.MotionVectors)); - context.AddField(HDFields.DoubleSidedMirror, systemData.doubleSidedMode == DoubleSidedMode.MirroredNormals && !context.pass.Equals(HDLitSubTarget.LitPasses.MotionVectors)); - // Refraction context.AddField(HDFields.Refraction, hasRefraction); context.AddField(HDFields.RefractionBox, hasRefraction && litData.refractionModel == ScreenSpaceRefraction.RefractionModel.Box); @@ -150,54 +153,54 @@ protected override int ComputeMaterialNeedsUpdateHash() return hash; } -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Lit = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { LitPasses.ShadowCaster }, - { LitPasses.META }, - { LitPasses.SceneSelection }, - { LitPasses.DepthOnly }, - { LitPasses.GBuffer }, - { LitPasses.MotionVectors }, - { LitPasses.DistortionVectors, new FieldCondition(HDFields.TransparentDistortion, true) }, - { LitPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, - { LitPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, true), - new FieldCondition(HDFields.DisableSSRTransparent, true) }}, - { LitPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, true), - new FieldCondition(HDFields.DisableSSRTransparent, false) }}, - { LitPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, false), - new FieldCondition(HDFields.DisableSSRTransparent, false) }}, - { LitPasses.Forward }, - { LitPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, - { LitPasses.RayTracingPrepass, new FieldCondition(HDFields.RayTracing, true) }, - }, - }; - - public static SubShaderDescriptor LitRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { LitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { LitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { LitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { LitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { LitPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, - { LitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Lit = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { LitPasses.ShadowCaster }, +// { LitPasses.META }, +// { LitPasses.SceneSelection }, +// { LitPasses.DepthOnly }, +// { LitPasses.GBuffer }, +// { LitPasses.MotionVectors }, +// { LitPasses.DistortionVectors, new FieldCondition(HDFields.TransparentDistortion, true) }, +// { LitPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, +// { LitPasses.TransparentDepthPrepass, new FieldCondition[]{ +// new FieldCondition(HDFields.TransparentDepthPrePass, true), +// new FieldCondition(HDFields.DisableSSRTransparent, true) }}, +// { LitPasses.TransparentDepthPrepass, new FieldCondition[]{ +// new FieldCondition(HDFields.TransparentDepthPrePass, true), +// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, +// { LitPasses.TransparentDepthPrepass, new FieldCondition[]{ +// new FieldCondition(HDFields.TransparentDepthPrePass, false), +// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, +// { LitPasses.Forward }, +// { LitPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, +// { LitPasses.RayTracingPrepass, new FieldCondition(HDFields.RayTracing, true) }, +// }, +// }; + +// public static SubShaderDescriptor LitRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { LitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { LitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { LitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { LitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { LitPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, +// { LitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion #region Passes public static class LitPasses @@ -231,83 +234,83 @@ public static class LitPasses virtualTextureFeedback = true, }; - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validPixelBlocks = LitBlockMasks.FragmentMeta, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentShadowCaster, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.BlendShadowCaster, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentSceneSelection, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.SceneSelection, - pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.DepthOnly, - }; + // public static PassDescriptor META = new PassDescriptor() + // { + // // Definition + // displayName = "META", + // referenceName = "SHADERPASS_LIGHT_TRANSPORT", + // lightMode = "META", + // useInPreview = false, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port Mask + // validPixelBlocks = LitBlockMasks.FragmentMeta, + + // // Collections + // structs = CoreStructCollections.Default, + // requiredFields = CoreRequiredFields.Meta, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = CoreRenderStates.Meta, + // pragmas = CorePragmas.DotsInstancedInV1AndV2, + // defines = CoreDefines.ShaderGraphRaytracingHigh, + // keywords = CoreKeywords.HDBase, + // includes = LitIncludes.Meta, + // }; + + // public static PassDescriptor ShadowCaster = new PassDescriptor() + // { + // // Definition + // displayName = "ShadowCaster", + // referenceName = "SHADERPASS_SHADOWS", + // lightMode = "ShadowCaster", + // useInPreview = false, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentShadowCaster, + + // // Collections + // structs = CoreStructCollections.Default, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = CoreRenderStates.BlendShadowCaster, + // pragmas = CorePragmas.DotsInstancedInV1AndV2, + // defines = CoreDefines.ShaderGraphRaytracingHigh, + // keywords = CoreKeywords.HDBase, + // includes = LitIncludes.DepthOnly, + // }; + + // public static PassDescriptor SceneSelection = new PassDescriptor() + // { + // // Definition + // displayName = "SceneSelectionPass", + // referenceName = "SHADERPASS_DEPTH_ONLY", + // lightMode = "SceneSelectionPass", + // useInPreview = false, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentSceneSelection, + + // // Collections + // structs = CoreStructCollections.Default, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = CoreRenderStates.SceneSelection, + // pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, + // defines = CoreDefines.SceneSelection, + // keywords = CoreKeywords.HDBase, + // includes = LitIncludes.DepthOnly, + // }; public static PassDescriptor DepthOnly = new PassDescriptor() { @@ -336,111 +339,111 @@ public static class LitPasses includes = LitIncludes.DepthOnly, }; - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = LitKeywords.DepthMotionVectors, - includes = LitIncludes.MotionVectors, - }; - - public static PassDescriptor DistortionVectors = new PassDescriptor() - { - // Definition - displayName = "DistortionVectors", - referenceName = "SHADERPASS_DISTORTION", - lightMode = "DistortionVectors", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDistortion, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = LitRenderStates.Distortion, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.Distortion, - }; - - public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPrepass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPrepass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentTransparentDepthPrepass, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = LitRenderStates.TransparentDepthPrePostPass, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.TransparentDepthPrepass, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.DepthOnly, - }; - - public static PassDescriptor TransparentBackface = new PassDescriptor() - { - // Definition - displayName = "TransparentBackface", - referenceName = "SHADERPASS_FORWARD", - lightMode = "TransparentBackface", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentTransparentBackface, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentBackface, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = LitIncludes.Forward, - }; + // public static PassDescriptor MotionVectors = new PassDescriptor() + // { + // // Definition + // displayName = "MotionVectors", + // referenceName = "SHADERPASS_MOTION_VECTORS", + // lightMode = "MotionVectors", + // useInPreview = false, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentDepthMotionVectors, + + // // Collections + // structs = CoreStructCollections.Default, + // requiredFields = CoreRequiredFields.LitFull, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = CoreRenderStates.MotionVectors, + // pragmas = CorePragmas.DotsInstancedInV1AndV2, + // defines = CoreDefines.ShaderGraphRaytracingHigh, + // keywords = LitKeywords.DepthMotionVectors, + // includes = LitIncludes.MotionVectors, + // }; + + // public static PassDescriptor DistortionVectors = new PassDescriptor() + // { + // // Definition + // displayName = "DistortionVectors", + // referenceName = "SHADERPASS_DISTORTION", + // lightMode = "DistortionVectors", + // useInPreview = true, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentDistortion, + + // // Collections + // structs = CoreStructCollections.Default, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = LitRenderStates.Distortion, + // pragmas = CorePragmas.DotsInstancedInV1AndV2, + // defines = CoreDefines.ShaderGraphRaytracingHigh, + // keywords = CoreKeywords.HDBase, + // includes = LitIncludes.Distortion, + // }; + + // public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() + // { + // // Definition + // displayName = "TransparentDepthPrepass", + // referenceName = "SHADERPASS_DEPTH_ONLY", + // lightMode = "TransparentDepthPrepass", + // useInPreview = true, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentTransparentDepthPrepass, + + // // Collections + // structs = CoreStructCollections.Default, + // requiredFields = CoreRequiredFields.LitFull, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = LitRenderStates.TransparentDepthPrePostPass, + // pragmas = CorePragmas.DotsInstancedInV1AndV2, + // defines = CoreDefines.TransparentDepthPrepass, + // keywords = CoreKeywords.HDBase, + // includes = LitIncludes.DepthOnly, + // }; + + // public static PassDescriptor TransparentBackface = new PassDescriptor() + // { + // // Definition + // displayName = "TransparentBackface", + // referenceName = "SHADERPASS_FORWARD", + // lightMode = "TransparentBackface", + // useInPreview = true, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentTransparentBackface, + + // // Collections + // structs = CoreStructCollections.Default, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = CoreRenderStates.TransparentBackface, + // pragmas = CorePragmas.DotsInstancedInV1AndV2, + // defines = CoreDefines.Forward, + // keywords = CoreKeywords.Forward, + // includes = LitIncludes.Forward, + // }; public static PassDescriptor Forward = new PassDescriptor() { @@ -471,31 +474,31 @@ public static class LitPasses virtualTextureFeedback = true, }; - public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPostpass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPostpass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentTransparentDepthPostpass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPrePostPass, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.DepthOnly, - }; + // public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() + // { + // // Definition + // displayName = "TransparentDepthPostpass", + // referenceName = "SHADERPASS_DEPTH_ONLY", + // lightMode = "TransparentDepthPostpass", + // useInPreview = true, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentTransparentDepthPostpass, + + // // Collections + // structs = CoreStructCollections.Default, + // fieldDependencies = CoreFieldDependencies.Default, + // renderStates = CoreRenderStates.TransparentDepthPrePostPass, + // pragmas = CorePragmas.DotsInstancedInV1AndV2, + // defines = CoreDefines.ShaderGraphRaytracingHigh, + // keywords = CoreKeywords.HDBase, + // includes = LitIncludes.DepthOnly, + // }; public static PassDescriptor RayTracingPrepass = new PassDescriptor() { diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index e379cb519d3..c03e2c23e2a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -12,7 +12,7 @@ static class HDShaderPasses { #region Distortion Pass - public static PassDescriptor GenerateDistortionPass(bool supportsLighting) + public static PassDescriptor GenerateDistortionPass(bool supportLighting) { return new PassDescriptor { @@ -33,7 +33,16 @@ public static PassDescriptor GenerateDistortionPass(bool supportsLighting) // Collections structs = CoreStructCollections.Default, fieldDependencies = CoreFieldDependencies.Default, - renderStates = new RenderStateCollection + renderStates = GenerateRenderState(), + pragmas = CorePragmas.DotsInstancedInV1AndV2, + defines = CoreDefines.ShaderGraphRaytracingHigh, + keywords = CoreKeywords.HDBase, + includes = GenerateIncludes(), + }; + + RenderStateCollection GenerateRenderState() + { + return new RenderStateCollection { { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, @@ -48,24 +57,20 @@ public static PassDescriptor GenerateDistortionPass(bool supportsLighting) Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, Comp = "Always", Pass = "Replace", - }) }, - }, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = GenerateDistortionIncludes(), - }; + }) } + }; + } - IncludeCollection GenerateDistortionIncludes() + IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); includes.Add(CoreIncludes.CorePregraph); - if (supportsLighting) + if (supportLighting) includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); includes.Add(CoreIncludes.CoreUtility); - if (supportsLighting) + if (supportLighting) { includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); @@ -89,7 +94,7 @@ IncludeCollection GenerateDistortionIncludes() #region Scene Selection Pass - public static PassDescriptor GenerateSceneSelectionPass() + public static PassDescriptor GenerateSceneSelection() { return new PassDescriptor { @@ -138,7 +143,7 @@ public static PassDescriptor GenerateSceneSelectionPass() #region Shadow Caster Pass - static public PassDescriptor GenerateShadowCasterPass(bool supportsLighting) + static public PassDescriptor GenerateShadowCaster(bool supportLighting) { return new PassDescriptor() { @@ -158,19 +163,19 @@ static public PassDescriptor GenerateShadowCasterPass(bool supportsLighting) renderStates = CoreRenderStates.ShadowCaster, pragmas = CorePragmas.DotsInstancedInV2Only, keywords = CoreKeywords.HDBase, - includes = GenerateShadowCasterIncludes(), + includes = GenerateIncludes(), }; - IncludeCollection GenerateShadowCasterIncludes() + IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); includes.Add(CoreIncludes.CorePregraph); - if (supportsLighting) + if (supportLighting) includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); includes.Add(CoreIncludes.CoreUtility); - if (supportsLighting) + if (supportLighting) { includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); @@ -194,7 +199,7 @@ IncludeCollection GenerateShadowCasterIncludes() #region META pass - public static PassDescriptor GenerateMETAPass(bool supportsLighting) + public static PassDescriptor GenerateMETA(bool supportLighting) { return new PassDescriptor { @@ -215,19 +220,19 @@ public static PassDescriptor GenerateMETAPass(bool supportsLighting) pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = CoreDefines.ShaderGraphRaytracingHigh, keywords = CoreKeywords.HDBase, - includes = GenerateMETAIncludes(), + includes = GenerateIncludes(), }; - IncludeCollection GenerateMETAIncludes() + IncludeCollection GenerateIncludes() { var includes = new IncludeCollection(); includes.Add(CoreIncludes.CorePregraph); - if (supportsLighting) + if (supportLighting) includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); includes.Add(CoreIncludes.CoreUtility); - if (supportsLighting) + if (supportLighting) { includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); @@ -274,7 +279,7 @@ IncludeCollection GenerateMETAIncludes() #region Depth Forward Only - public static PassDescriptor GenerateDepthForwardOnly(bool supportsLighting) + public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting) { return new PassDescriptor { @@ -286,7 +291,7 @@ public static PassDescriptor GenerateDepthForwardOnly(bool supportsLighting) // Port Mask validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FragmentDepthMotionVectors, + validPixelBlocks = FragmentDepthOnlyVectors, // Collections structs = CoreStructCollections.Default, @@ -294,7 +299,7 @@ public static PassDescriptor GenerateDepthForwardOnly(bool supportsLighting) fieldDependencies = CoreFieldDependencies.Default, renderStates = CoreRenderStates.DepthOnly, pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, + defines = supportLighting ? CoreDefines.DepthMotionVectors : null, keywords = CoreKeywords.DepthMotionVectorsNoNormal, includes = GenerateIncludes(), }; @@ -324,11 +329,11 @@ IncludeCollection GenerateIncludes() var includes = new IncludeCollection(); includes.Add(CoreIncludes.CorePregraph); - if (supportsLighting) + if (supportLighting) includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); includes.Add(CoreIncludes.CoreUtility); - if (supportsLighting) + if (supportLighting) includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); @@ -337,12 +342,486 @@ IncludeCollection GenerateIncludes() } } - public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] + public static BlockFieldDescriptor[] FragmentDepthOnlyVectors = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.DepthOffset, + }; + +#endregion + +#region Motion Vectors + + public static PassDescriptor GenerateMotionVectors(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "MotionVectors", + referenceName = "SHADERPASS_MOTION_VECTORS", + lightMode = "MotionVectors", + useInPreview = false, + + // Block Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = FragmentMotionVectors, + + // Collections + structs = CoreStructCollections.Default, + requiredFields = MotionVectorRequiredFields, + renderStates = GenerateRenderState(), + fieldDependencies = CoreFieldDependencies.Default, + pragmas = CorePragmas.DotsInstancedInV2Only, + keywords = GenerateKeywords(), + includes = GenerateIncludes(), + }; + + RenderStateCollection GenerateRenderState() + { + var renderState = CoreRenderStates.MotionVectors; + + if (!supportLighting) + { + renderState.Add(RenderState.ColorMask("ColorMask [_ColorMaskNormal] 1")); + renderState.Add(RenderState.ColorMask("ColorMask 0 2")); + } + + return renderState; + } + + KeywordCollection GenerateKeywords() + { + var keywords = new KeywordCollection + { + { CoreKeywords.HDBase }, + { CoreKeywordDescriptors.WriteMsaaDepth }, + { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, + }; + + if (supportLighting) + keywords.Add(CoreKeywordDescriptors.WriteNormalBuffer); + + return keywords; + } + + IncludeCollection GenerateIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportLighting) + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportLighting) + { + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph); + + return includes; + } + } + + static FieldCollection MotionVectorRequiredFields = new FieldCollection() + { + HDStructFields.AttributesMesh.normalOS, + HDStructFields.AttributesMesh.tangentOS, + HDStructFields.AttributesMesh.uv0, + HDStructFields.AttributesMesh.uv1, + HDStructFields.AttributesMesh.color, + HDStructFields.AttributesMesh.uv2, + HDStructFields.AttributesMesh.uv3, + HDStructFields.FragInputs.tangentToWorld, + HDStructFields.FragInputs.positionRWS, + HDStructFields.FragInputs.texCoord1, + HDStructFields.FragInputs.texCoord2, + HDStructFields.FragInputs.texCoord3, + HDStructFields.FragInputs.color, + }; + + public static BlockFieldDescriptor[] FragmentMotionVectors = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalWS, + BlockFields.SurfaceDescription.NormalOS, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.DepthOffset, + }; + +#endregion + +#region Forward Only + + public static PassDescriptor GenereateForwardOnlyPass(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "ForwardOnly", + referenceName = supportLighting ? "SHADERPASS_FORWARD" : "SHADERPASS_FORWARD_UNLIT", + lightMode = "ForwardOnly", + useInPreview = true, + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = FragmentForwardOnly, + + // Collections + structs = CoreStructCollections.Default, + requiredFields = ForwardOnlyFields, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = CoreRenderStates.Forward, + pragmas = CorePragmas.DotsInstancedInV2Only, + defines = supportLighting ? CoreDefines.Forward : null, + keywords = CoreKeywords.Forward, + includes = GenerateIncludes(), + }; + + IncludeCollection GenerateIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportLighting) + { + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kLighting, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); + if (supportLighting) + includes.Add(CoreIncludes.kLightLoop, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportLighting) + { + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + if (supportLighting) + includes.Add(CoreIncludes.kPassForward, IncludeLocation.Postgraph); + else + includes.Add(CoreIncludes.kPassForwardUnlit, IncludeLocation.Postgraph); + + return includes; + } + } + + public static BlockFieldDescriptor[] FragmentForwardOnly = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + HDBlockFields.SurfaceDescription.SpecularOcclusion, + BlockFields.SurfaceDescription.NormalTS, + HDBlockFields.SurfaceDescription.BentNormal, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Occlusion, + BlockFields.SurfaceDescription.Specular, + HDBlockFields.SurfaceDescription.DiffusionProfileHash, + HDBlockFields.SurfaceDescription.SubsurfaceMask, + HDBlockFields.SurfaceDescription.Thickness, + HDBlockFields.SurfaceDescription.Tangent, + HDBlockFields.SurfaceDescription.Anisotropy, + BlockFields.SurfaceDescription.Emission, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.BakedGI, + HDBlockFields.SurfaceDescription.BakedBackGI, + HDBlockFields.SurfaceDescription.DepthOffset, + }; + + public static FieldCollection ForwardOnlyFields = new FieldCollection() + { + HDStructFields.AttributesMesh.normalOS, + HDStructFields.AttributesMesh.tangentOS, + HDStructFields.AttributesMesh.uv0, + HDStructFields.AttributesMesh.uv1, + HDStructFields.AttributesMesh.color, + HDStructFields.AttributesMesh.uv2, + HDStructFields.AttributesMesh.uv3, + HDStructFields.FragInputs.tangentToWorld, + HDStructFields.FragInputs.positionRWS, + HDStructFields.FragInputs.texCoord1, + HDStructFields.FragInputs.texCoord2, + HDStructFields.FragInputs.texCoord3, + HDStructFields.FragInputs.color, + }; + +#endregion + +#region Back then front pass + + public static PassDescriptor GenerateBackThenFront(bool supportLighting, string forwardPassInclude = CoreIncludes.kPassForward) + { + return new PassDescriptor + { + // Definition + displayName = "TransparentBackface", + referenceName = supportLighting ? "SHADERPASS_FORWARD" : "SHADERPASS_FORWARD_UNLIT", + lightMode = "TransparentBackface", + useInPreview = true, + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = FragmentBackThenFront, + + // Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = CoreRenderStates.TransparentBackface, + pragmas = CorePragmas.DotsInstancedInV1AndV2, + defines = CoreDefines.Forward, + keywords = CoreKeywords.Forward, + includes = GenerateIncludes(), + }; + + IncludeCollection GenerateIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportLighting) + { + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kLighting, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); + if (supportLighting) + includes.Add(CoreIncludes.kLightLoop, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportLighting) + { + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + if (supportLighting) + includes.Add(CoreIncludes.kPassForward, IncludeLocation.Postgraph); + else + includes.Add(CoreIncludes.kPassForwardUnlit, IncludeLocation.Postgraph); + + return includes; + } + } + + public static BlockFieldDescriptor[] FragmentBackThenFront = new BlockFieldDescriptor[] { + BlockFields.SurfaceDescription.BaseColor, BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalWS, + BlockFields.SurfaceDescription.NormalOS, + HDBlockFields.SurfaceDescription.BentNormal, + HDBlockFields.SurfaceDescription.Tangent, + HDBlockFields.SurfaceDescription.SubsurfaceMask, + HDBlockFields.SurfaceDescription.Thickness, + HDBlockFields.SurfaceDescription.DiffusionProfileHash, + HDBlockFields.SurfaceDescription.IridescenceMask, + HDBlockFields.SurfaceDescription.IridescenceThickness, + BlockFields.SurfaceDescription.Specular, + HDBlockFields.SurfaceDescription.CoatMask, + BlockFields.SurfaceDescription.Metallic, + BlockFields.SurfaceDescription.Emission, BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Occlusion, + HDBlockFields.SurfaceDescription.SpecularOcclusion, BlockFields.SurfaceDescription.Alpha, BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.Anisotropy, + HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, + HDBlockFields.SurfaceDescription.SpecularAAThreshold, + HDBlockFields.SurfaceDescription.RefractionIndex, + HDBlockFields.SurfaceDescription.RefractionColor, + HDBlockFields.SurfaceDescription.RefractionDistance, + HDBlockFields.SurfaceDescription.DepthOffset, + }; + +#endregion + +#region Transparent Depth Prepass + + public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLighting, string forwardPassInclude = CoreIncludes.kPassForward) + { + return new PassDescriptor + { + // Definition + displayName = "TransparentDepthPrepass", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "TransparentDepthPrepass", + useInPreview = true, + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = FragmentTransparentDepthPrepass, + + // Collections + structs = CoreStructCollections.Default, + requiredFields = TransparentDepthPrepassFields, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = GenerateRenderState(), + pragmas = CorePragmas.DotsInstancedInV1AndV2, + defines = GenerateDefines(), + keywords = CoreKeywords.HDBase, + includes = GenerateIncludes(), + }; + + DefineCollection GenerateDefines() + { + var defines = new DefineCollection{ { RayTracingNode.GetRayTracingKeyword(), 0 } }; + + if (supportLighting) + defines.Add(CoreKeywordDescriptors.WriteNormalBufferDefine, 1, new FieldCondition(HDFields.DisableSSRTransparent, false)); + + return defines; + } + + RenderStateCollection GenerateRenderState() + { + var renderState = new RenderStateCollection + { + { RenderState.Blend(Blend.One, Blend.Zero) }, + { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, + { RenderState.ZWrite(ZWrite.On) }, + { RenderState.Stencil(new StencilDescriptor() + { + WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDepth, + Ref = CoreRenderStates.Uniforms.stencilRefDepth, + Comp = "Always", + Pass = "Replace", + }) }, + }; + + if (!supportLighting) + { + renderState.Add(RenderState.ColorMask("ColorMask [_ColorMaskNormal]")); + renderState.Add(RenderState.ColorMask("ColorMask 0 1")); + } + + return renderState; + } + + IncludeCollection GenerateIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportLighting) + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportLighting) + { + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); + + return includes; + } + } + + public static FieldCollection TransparentDepthPrepassFields = new FieldCollection() + { + HDStructFields.AttributesMesh.normalOS, + HDStructFields.AttributesMesh.tangentOS, + HDStructFields.AttributesMesh.uv0, + HDStructFields.AttributesMesh.uv1, + HDStructFields.AttributesMesh.color, + HDStructFields.AttributesMesh.uv2, + HDStructFields.AttributesMesh.uv3, + HDStructFields.FragInputs.tangentToWorld, + HDStructFields.FragInputs.positionRWS, + HDStructFields.FragInputs.texCoord1, + HDStructFields.FragInputs.texCoord2, + HDStructFields.FragInputs.texCoord3, + HDStructFields.FragInputs.color, + }; + + public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.Alpha, + HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, + HDBlockFields.SurfaceDescription.DepthOffset, + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalWS, + BlockFields.SurfaceDescription.NormalOS, + BlockFields.SurfaceDescription.Smoothness, + }; + +#endregion + +#region Transparent Depth Postpass + + public static PassDescriptor GenerateTransparentDepthPostpass(bool supportLighting, string forwardPassInclude = CoreIncludes.kPassForward) + { + return new PassDescriptor + { + // Definition + displayName = "TransparentDepthPostpass", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "TransparentDepthPostpass", + useInPreview = true, + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = FragmentTransparentDepthPostpass, + + // Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = GenerateRenderState(), + pragmas = CorePragmas.DotsInstancedInV1AndV2, + defines = CoreDefines.ShaderGraphRaytracingHigh, + keywords = CoreKeywords.HDBase, + includes = GenerateIncludes(), + }; + + IncludeCollection GenerateIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportLighting) + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportLighting) + { + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); + + return includes; + } + + RenderStateCollection GenerateRenderState() + { + var renderState = new RenderStateCollection + { + { RenderState.Blend(Blend.One, Blend.Zero) }, + { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, + { RenderState.ZWrite(ZWrite.On) }, + { RenderState.ColorMask("ColorMask 0") }, + }; + + return renderState; + } + } + + public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.Alpha, + HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, HDBlockFields.SurfaceDescription.DepthOffset, }; 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 6d6db1b5775..ea4704e7e95 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 @@ -64,6 +64,8 @@ protected override int ComputeMaterialNeedsUpdateHash() } protected override bool supportLighting => true; + // All lit sub targets are forward only except Lit so we set it as default here + protected override bool supportForward => true; public override void GetFields(ref TargetFieldContext context) { @@ -93,6 +95,10 @@ public override void GetFields(ref TargetFieldContext context) context.AddField(HDFields.SpecularOcclusionFromAO, lightingData.specularOcclusionMode == SpecularOcclusionMode.FromAO); context.AddField(HDFields.SpecularOcclusionFromAOBentNormal, lightingData.specularOcclusionMode == SpecularOcclusionMode.FromAOAndBentNormal); context.AddField(HDFields.SpecularOcclusionCustom, lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom); + + // Double Sided + context.AddField(HDFields.DoubleSidedFlip, systemData.doubleSidedMode == DoubleSidedMode.FlippedNormals && context.pass.referenceName != "SHADERPASS_MOTION_VECTORS"); + context.AddField(HDFields.DoubleSidedMirror, systemData.doubleSidedMode == DoubleSidedMode.MirroredNormals && context.pass.referenceName != "SHADERPASS_MOTION_VECTORS"); } public override void GetActiveBlocks(ref TargetActiveBlockContext context) 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 6ef3e38dc30..ff7940fc93e 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 @@ -61,7 +61,7 @@ protected override void CreatePropertyGUI() 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(zWriteEnableText, () => systemData.transparentZWrite, (newValue) => systemData.transparentZWrite = 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); 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 7aac0341517..52c7802a9ed 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 @@ -42,8 +42,9 @@ protected override string renderQueue protected virtual bool supportPathtracing => false; protected abstract string subShaderInclude { get; } - protected virtual string postDecalsIncludes => null; - protected virtual string postGraphIncludes => null; + protected virtual string postDecalsInclude => null; + // Maybe we should rename it custom forward pass include ? + // protected virtual string postGraphInclude => null; // TODO: put this method as sealed when the new pass system is done protected override IEnumerable EnumerateSubShaders() @@ -66,18 +67,31 @@ PassCollection GetPasses() var passes = new PassCollection { // Common "surface" passes - HDShaderPasses.GenerateSceneSelectionPass(), - HDShaderPasses.GenerateShadowCasterPass(supportLighting), - HDShaderPasses.GenerateMETAPass(supportLighting), - // MotionVector + HDShaderPasses.GenerateSceneSelection(), + HDShaderPasses.GenerateShadowCaster(supportLighting), + HDShaderPasses.GenerateMETA(supportLighting), + HDShaderPasses.GenerateMotionVectors(supportLighting), + { HDShaderPasses.GenerateBackThenFront(supportLighting), new FieldCondition(HDFields.TransparentBackFace, true)}, + { HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ + new FieldCondition(HDFields.TransparentDepthPrePass, true), + new FieldCondition(HDFields.DisableSSRTransparent, true) }}, + { HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ + new FieldCondition(HDFields.TransparentDepthPrePass, true), + new FieldCondition(HDFields.DisableSSRTransparent, false) }}, + { HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ + new FieldCondition(HDFields.TransparentDepthPrePass, false), + new FieldCondition(HDFields.DisableSSRTransparent, false) }}, + { HDShaderPasses.GenerateTransparentDepthPostpass(supportLighting), new FieldCondition(HDFields.TransparentDepthPostPass, true) }, }; if (supportForward) - passes.Add(HDShaderPasses.GenerateDepthForwardOnly(supportLighting)); - // passes.Add(); + { + passes.Add(HDShaderPasses.GenerateDepthForwardOnlyPass(supportLighting)); + passes.Add(HDShaderPasses.GenereateForwardOnlyPass(supportLighting)); + } if (supportDistortion) passes.Add(HDShaderPasses.GenerateDistortionPass(supportLighting), new FieldCondition(HDFields.TransparentDistortion, true)); - + return passes; } } @@ -124,9 +138,7 @@ SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor if (include.descriptor.value == CoreIncludes.kPassPlaceholder) include.descriptor.value = subShaderInclude; if (include.descriptor.value == CoreIncludes.kPostDecalsPlaceholder) - include.descriptor.value = postDecalsIncludes; - if (include.descriptor.value == CoreIncludes.kPostGraphPlaceholder) - include.descriptor.value = postGraphIncludes; + include.descriptor.value = postDecalsInclude; if (!String.IsNullOrEmpty(include.descriptor.value)) finalIncludes.Add(include.descriptor.value, include.descriptor.location, include.fieldConditions); @@ -150,6 +162,7 @@ public override void GetFields(ref TargetFieldContext context) AddDistortionFields(ref context); // Common properties between all "surface" master nodes (everything except decal right now) + context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && context.pass.referenceName != "SHADERPASS_MOTION_VECTORS"); // Blend Mode context.AddField(Fields.BlendAdd, systemData.surfaceType != SurfaceType.Opaque && systemData.blendMode == BlendMode.Additive); @@ -277,7 +290,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera systemData.blendMode, systemData.sortPriority, builtinData.alphaToMask, - systemData.zWrite, + systemData.transparentZWrite, systemData.transparentCullMode, systemData.zTest, builtinData.backThenFrontRendering, @@ -290,196 +303,18 @@ 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 : 0); 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); + material.SetFloat(kTransparentZWrite, systemData.transparentZWrite ? 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); } - - // Common passes for all "surface" targets - - // protected virtual void EnumeratePassesForSubShader - - // public static PassDescriptor META = new PassDescriptor() - // { - // // Definition - // displayName = "META", - // referenceName = "SHADERPASS_LIGHT_TRANSPORT", - // lightMode = "META", - // useInPreview = false, - - // // Template - // passTemplatePath = templatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Block Mask - // validPixelBlocks = UnlitBlockMasks.FragmentDefault, - - // // Collections - // structs = CoreStructCollections.Default, - // requiredFields = new FieldCollection(){ CoreRequiredFields.Meta, HDFields.SubShader.Unlit }, - // fieldDependencies = CoreFieldDependencies.Default, - // renderStates = CoreRenderStates.Meta, - // pragmas = CorePragmas.DotsInstancedInV2Only, - // keywords = CoreKeywords.HDBase, - // includes = UnlitIncludes.Meta, - // }; - - // public static PassDescriptor ShadowCaster = new PassDescriptor() - // { - // // Definition - // displayName = "ShadowCaster", - // referenceName = "SHADERPASS_SHADOWS", - // lightMode = "ShadowCaster", - // useInPreview = false, - - // // Template - // passTemplatePath = templatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Block Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - - // // Collections - // structs = CoreStructCollections.Default, - // requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - // fieldDependencies = CoreFieldDependencies.Default, - // renderStates = CoreRenderStates.ShadowCaster, - // pragmas = CorePragmas.DotsInstancedInV2Only, - // keywords = CoreKeywords.HDBase, - // includes = UnlitIncludes.DepthOnly, - // }; - - // public static PassDescriptor SceneSelection = new PassDescriptor() - // { - // // Definition - // displayName = "SceneSelectionPass", - // referenceName = "SHADERPASS_DEPTH_ONLY", - // lightMode = "SceneSelectionPass", - // useInPreview = false, - - // // Template - // passTemplatePath = templatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Block Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - - // // Collections - // structs = CoreStructCollections.Default, - // requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - // fieldDependencies = CoreFieldDependencies.Default, - // renderStates = UnlitRenderStates.SceneSelection, - // pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - // defines = CoreDefines.SceneSelection, - // keywords = CoreKeywords.HDBase, - // includes = UnlitIncludes.DepthOnly, - // }; - - // protected PassDescriptor sceneSelectionPass => new PassDescriptor() - // { - // // Definition - // displayName = "SceneSelectionPass", - // referenceName = "SHADERPASS_DEPTH_ONLY", - // lightMode = "SceneSelectionPass", - // useInPreview = false, - - // // Template - // passTemplatePath = templatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Block Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - - // // Collections - // structs = CoreStructCollections.Default, - // requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - // fieldDependencies = CoreFieldDependencies.Default, - // renderStates = UnlitRenderStates.SceneSelection, - // pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - // defines = CoreDefines.SceneSelection, - // keywords = CoreKeywords.HDBase, - // includes = UnlitIncludes.DepthOnly, - // }; - - // protected PassDescriptor distortionPass => new PassDescriptor() - // { - // // Definition - // displayName = "DistortionVectors", - // referenceName = "SHADERPASS_DISTORTION", - // lightMode = "DistortionVectors", - // useInPreview = true, - - // // Template - // passTemplatePath = templatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Port mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = FragmentDistortion, - - // // Collections - // structs = CoreStructCollections.Default, - // fieldDependencies = CoreFieldDependencies.Default, - // renderStates = new RenderStateCollection - // { - // { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, - // { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, - // { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, - // { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, - // { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - // { RenderState.ZWrite(ZWrite.Off) }, - // { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, - // { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, - // { RenderState.Stencil(new StencilDescriptor() { - // WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, - // Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, - // Comp = "Always", - // Pass = "Replace", - // }) }, - // }, - // pragmas = CorePragmas.DotsInstancedInV1AndV2, - // defines = CoreDefines.ShaderGraphRaytracingHigh, - // keywords = CoreKeywords.HDBase, - // includes = GenerateDistortionIncludes(), - // }; - - // IncludeCollection GenerateDistortionIncludes() - // { - // var includes = new IncludeCollection(); - - // includes.Add(CoreIncludes.CorePregraph); - // if (supportsLighting) - // includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); - // includes.Add(subShaderInclude, IncludeLocation.Pregraph); - // includes.Add(CoreIncludes.CoreUtility); - // if (supportsLighting) - // { - // includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); - // includes.Add(postDecalsIncludes); - // } - // includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); - // includes.Add(CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph); - - // return includes; - // } - - // public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] - // { - // BlockFields.SurfaceDescription.Alpha, - // BlockFields.SurfaceDescription.AlphaClipThreshold, - // HDBlockFields.SurfaceDescription.Distortion, - // HDBlockFields.SurfaceDescription.DistortionBlur, - // }; } } \ 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 index 037704dec73..17601e59676 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 @@ -27,7 +27,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary + sealed partial class HDUnlitSubTarget : ILegacyTarget { public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) { @@ -39,7 +39,7 @@ void UpgradeUnlitMasterNode(UnlitMasterNode1 unlitMasterNode, out Dictionary + sealed partial class HDUnlitSubTarget : SurfaceSubTarget, IRequiresData { public HDUnlitSubTarget() => displayName = "Unlit"; - // TODO: remove this line public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template"; @@ -33,6 +32,8 @@ sealed partial class HDUnlitSubTarget : SurfaceSubTarget, ILegacyTarget, IRequir protected override bool supportDistortion => true; protected override bool supportForward => true; + protected override string subShaderInclude => CoreIncludes.kUnlit; + HDUnlitData m_UnlitData; HDUnlitData IRequiresData.data @@ -108,508 +109,507 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera HDSubShaderUtilities.AddStencilShaderProperties(collector, systemData, null); } -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Unlit = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { UnlitPasses.ShadowCaster }, - { UnlitPasses.META }, - { UnlitPasses.SceneSelection }, - { UnlitPasses.DepthForwardOnly }, - { UnlitPasses.MotionVectors }, - // { UnlitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, - { UnlitPasses.ForwardOnly }, - }, - }; - - public static SubShaderDescriptor UnlitRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { UnlitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion - -#region Passes - static class UnlitPasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validPixelBlocks = UnlitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ CoreRequiredFields.Meta, HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = UnlitIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.ShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = UnlitIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.SceneSelection, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = UnlitIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.DepthForwardOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = UnlitKeywords.DepthMotionVectors, - includes = UnlitIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ CoreRequiredFields.PositionRWS, HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = UnlitRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = UnlitKeywords.DepthMotionVectors, - includes = UnlitIncludes.MotionVectors, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD_UNLIT", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = UnlitBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Forward, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = UnlitKeywords.Forward, - includes = UnlitIncludes.ForwardOnly, - - virtualTextureFeedback = true, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = UnlitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = UnlitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - includes = CoreIncludes.Raytracing, - keywords = CoreKeywords.RaytracingVisiblity, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = UnlitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = UnlitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBase, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingPathTracing = new PassDescriptor() - { - //Definition - displayName = "PathTracingDXR", - referenceName = "SHADERPASS_PATH_TRACING", - lightMode = "PathTracingDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = UnlitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.HDBaseNoCrossFade, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingPathTracing }, - }; - } -#endregion - -#region BlockMasks - static class UnlitBlockMasks - { - public static BlockFieldDescriptor[] FragmentDefault = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - BlockFields.SurfaceDescription.Emission, - }; - - public static BlockFieldDescriptor[] FragmentOnlyAlpha = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - }; - - public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - BlockFields.SurfaceDescription.Emission, - HDBlockFields.SurfaceDescription.ShadowTint, - }; - } -#endregion - -#region RenderStates - static class UnlitRenderStates - { - public static RenderStateCollection SceneSelection = new RenderStateCollection - { - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.ColorMask("ColorMask 0") }, - }; - - // Caution: When using MSAA we have normal and depth buffer bind. - // Unlit objects need to NOT write in normal buffer (or write 0) - Disable color mask for this RT - // Note: ShaderLab doesn't allow to have a variable on the second parameter of ColorMask - // - When MSAA: disable target 1 (normal buffer) - // - When no MSAA: disable target 0 (normal buffer) and 1 (unused) - public static RenderStateCollection DepthForwardOnly = new RenderStateCollection - { - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.ColorMask("ColorMask [_ColorMaskNormal]") }, - { RenderState.ColorMask("ColorMask 0 1") }, - { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDepth, - Ref = CoreRenderStates.Uniforms.stencilRefDepth, - Comp = "Always", - Pass = "Replace", - }) }, - }; - - // Caution: When using MSAA we have motion vector, normal and depth buffer bind. - // Mean unlit object need to not write in it (or write 0) - Disable color mask for this RT - // This is not a problem in no MSAA mode as there is no buffer bind - public static RenderStateCollection MotionVectors = new RenderStateCollection - { - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.ColorMask("ColorMask [_ColorMaskNormal] 1") }, - { RenderState.ColorMask("ColorMask 0 2") }, - { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, - Ref = CoreRenderStates.Uniforms.stencilRefMV, - Comp = "Always", - Pass = "Replace", - }) }, - }; - } - #endregion - -#region Defines - static class UnlitDefines - { - public static DefineCollection RaytracingForward = new DefineCollection - { - { RayTracingNode.GetRayTracingKeyword(), 0 }, - }; - - public static DefineCollection RaytracingIndirect = new DefineCollection - { - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - public static DefineCollection RaytracingVisibility = new DefineCollection - { - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - public static DefineCollection RaytracingGBuffer = new DefineCollection - { - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - } -#endregion - -#region Keywords - static class UnlitKeywords - { - public static KeywordCollection DepthMotionVectors = new KeywordCollection - { - { CoreKeywords.HDBase }, - { CoreKeywordDescriptors.WriteMsaaDepth }, - { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, - }; - - public static KeywordCollection Forward = new KeywordCollection - { - { CoreKeywords.HDBase }, - { CoreKeywordDescriptors.DebugDisplay }, - { CoreKeywordDescriptors.Shadow, new FieldCondition(HDFields.EnableShadowMatte, true) }, - }; - } -#endregion - protected override string subShaderInclude => CoreIncludes.kUnlit; - -#region Includes - static class UnlitIncludes - { - const string kPassForwardUnlit = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"; +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Unlit = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { UnlitPasses.ShadowCaster }, +// { UnlitPasses.META }, +// { UnlitPasses.SceneSelection }, +// { UnlitPasses.DepthForwardOnly }, +// { UnlitPasses.MotionVectors }, +// // { UnlitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, +// { UnlitPasses.ForwardOnly }, +// }, +// }; + +// public static SubShaderDescriptor UnlitRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { UnlitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion + +// #region Passes +// static class UnlitPasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Block Mask +// validPixelBlocks = UnlitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ CoreRequiredFields.Meta, HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = UnlitIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Block Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.ShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = UnlitIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Block Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.SceneSelection, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = UnlitIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Block Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.DepthForwardOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = UnlitKeywords.DepthMotionVectors, +// includes = UnlitIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Block Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ CoreRequiredFields.PositionRWS, HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = UnlitRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = UnlitKeywords.DepthMotionVectors, +// includes = UnlitIncludes.MotionVectors, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD_UNLIT", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Block Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = UnlitBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Forward, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = UnlitKeywords.Forward, +// includes = UnlitIncludes.ForwardOnly, + +// virtualTextureFeedback = true, +// }; + +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Block Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = UnlitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingIndirect }, +// }; + +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Block Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = UnlitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// includes = CoreIncludes.Raytracing, +// keywords = CoreKeywords.RaytracingVisiblity, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingVisibility }, +// }; + +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Block Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = UnlitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingForward }, +// }; + +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Block Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = UnlitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBase, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RayTracingGBuffer }, +// }; + +// public static PassDescriptor RaytracingPathTracing = new PassDescriptor() +// { +// //Definition +// displayName = "PathTracingDXR", +// referenceName = "SHADERPASS_PATH_TRACING", +// lightMode = "PathTracingDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Block Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = UnlitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.HDBaseNoCrossFade, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingPathTracing }, +// }; +// } +// #endregion + +// #region BlockMasks +// static class UnlitBlockMasks +// { +// public static BlockFieldDescriptor[] FragmentDefault = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// BlockFields.SurfaceDescription.Emission, +// }; + +// public static BlockFieldDescriptor[] FragmentOnlyAlpha = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// }; + +// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// BlockFields.SurfaceDescription.Emission, +// HDBlockFields.SurfaceDescription.ShadowTint, +// }; +// } +// #endregion + +// #region RenderStates +// static class UnlitRenderStates +// { +// public static RenderStateCollection SceneSelection = new RenderStateCollection +// { +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.ColorMask("ColorMask 0") }, +// }; + +// // Caution: When using MSAA we have normal and depth buffer bind. +// // Unlit objects need to NOT write in normal buffer (or write 0) - Disable color mask for this RT +// // Note: ShaderLab doesn't allow to have a variable on the second parameter of ColorMask +// // - When MSAA: disable target 1 (normal buffer) +// // - When no MSAA: disable target 0 (normal buffer) and 1 (unused) +// public static RenderStateCollection DepthForwardOnly = new RenderStateCollection +// { +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.ColorMask("ColorMask [_ColorMaskNormal]") }, +// { RenderState.ColorMask("ColorMask 0 1") }, +// { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDepth, +// Ref = CoreRenderStates.Uniforms.stencilRefDepth, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// // Caution: When using MSAA we have motion vector, normal and depth buffer bind. +// // Mean unlit object need to not write in it (or write 0) - Disable color mask for this RT +// // This is not a problem in no MSAA mode as there is no buffer bind +// public static RenderStateCollection MotionVectors = new RenderStateCollection +// { +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.ColorMask("ColorMask [_ColorMaskNormal] 1") }, +// { RenderState.ColorMask("ColorMask 0 2") }, +// { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, +// Ref = CoreRenderStates.Uniforms.stencilRefMV, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; +// } +// #endregion + +// #region Defines +// static class UnlitDefines +// { +// public static DefineCollection RaytracingForward = new DefineCollection +// { +// { RayTracingNode.GetRayTracingKeyword(), 0 }, +// }; + +// public static DefineCollection RaytracingIndirect = new DefineCollection +// { +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingVisibility = new DefineCollection +// { +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingGBuffer = new DefineCollection +// { +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; +// } +// #endregion + +// #region Keywords +// static class UnlitKeywords +// { +// public static KeywordCollection DepthMotionVectors = new KeywordCollection +// { +// { CoreKeywords.HDBase }, +// { CoreKeywordDescriptors.WriteMsaaDepth }, +// { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, +// }; + +// public static KeywordCollection Forward = new KeywordCollection +// { +// { CoreKeywords.HDBase }, +// { CoreKeywordDescriptors.DebugDisplay }, +// { CoreKeywordDescriptors.Shadow, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// }; +// } +// #endregion + +// #region Includes +// static class UnlitIncludes +// { +// const string kPassForwardUnlit = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"; - public static IncludeCollection Meta = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection Distortion = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kHDShadow, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kPunctualLightCommon, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { CoreIncludes.kHDShadowLoop, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, - { kPassForwardUnlit, IncludeLocation.Postgraph }, - }; - } -#endregion +// public static IncludeCollection Meta = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection Distortion = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kHDShadow, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kPunctualLightCommon, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kHDShadowLoop, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { kPassForwardUnlit, IncludeLocation.Postgraph }, +// }; +// } +// #endregion } } diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs index 29bd385271b..79c27f0e9cb 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs @@ -111,7 +111,7 @@ public static void AddStencilShaderProperties(PropertyCollector collector, Syste public static void AddBlendingStatesShaderProperties( PropertyCollector collector, SurfaceType surface, BlendMode blend, int sortingPriority, - bool alphaToMask, bool zWrite, TransparentCullMode transparentCullMode, CompareFunction zTest, + bool alphaToMask, bool transparentZWrite, TransparentCullMode transparentCullMode, CompareFunction zTest, bool backThenFrontRendering, bool fogOnTransparent) { collector.AddFloatProperty("_SurfaceType", (int)surface); @@ -123,8 +123,8 @@ public static void AddBlendingStatesShaderProperties( collector.AddFloatProperty("_AlphaSrcBlend", 1.0f); collector.AddFloatProperty("_AlphaDstBlend", 0.0f); collector.AddToggleProperty("_AlphaToMask", alphaToMask); - collector.AddToggleProperty(kZWrite, (surface == SurfaceType.Transparent) ? zWrite : true); - collector.AddToggleProperty(kTransparentZWrite, zWrite); + collector.AddToggleProperty(kZWrite, (surface == SurfaceType.Transparent) ? transparentZWrite : true); + collector.AddToggleProperty(kTransparentZWrite, transparentZWrite); collector.AddFloatProperty("_CullMode", (int)CullMode.Back); collector.AddIntProperty(kTransparentSortPriority, sortingPriority); collector.AddToggleProperty(kEnableFogOnTransparent, fogOnTransparent); 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 29920c6ec49..61af8a9295a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs @@ -972,7 +972,6 @@ static class CoreIncludes public const string kDecalUtilities = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/DecalUtilities.hlsl"; public const string kPassPlaceholder = "Pass Include Placeholder, replace me !"; public const string kPostDecalsPlaceholder = "After Decal Include Placeholder, replace me !"; - public const string kPostGraphPlaceholder = "After Graph Include Placeholder, replace me !"; // Public Postgraph Pass public const string kPassLightTransport = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl"; @@ -981,6 +980,7 @@ static class CoreIncludes public const string kDisortionVectors = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDistortion.hlsl"; public const string kPassForward = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl"; public const string kStandardLit = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.hlsl"; + public const string kPassForwardUnlit = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"; public static IncludeCollection CorePregraph = new IncludeCollection { 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 639a49cd148..152f6e272e4 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 @@ -50,8 +50,8 @@ public CompareFunction zTest } [SerializeField] - bool m_ZWrite = true; - public bool zWrite + bool m_ZWrite = false; + public bool transparentZWrite { get => m_ZWrite; set => m_ZWrite = value; From 057773817727c4a3ff14841487d33fb189b56e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Fri, 29 May 2020 19:36:58 +0200 Subject: [PATCH 15/30] Fixed unlit depth prepass --- .../Material/ShaderGraph/HDShaderPasses.cs | 56 ++++++++++++++----- .../Material/ShaderGraph/SurfaceSubTarget.cs | 26 ++++++--- .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 23 +++++++- 3 files changed, 80 insertions(+), 25 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index c03e2c23e2a..d81828f433e 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -94,7 +94,7 @@ IncludeCollection GenerateIncludes() #region Scene Selection Pass - public static PassDescriptor GenerateSceneSelection() + public static PassDescriptor GenerateSceneSelection(bool supportLighting) { return new PassDescriptor { @@ -115,8 +115,28 @@ public static PassDescriptor GenerateSceneSelection() pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, defines = CoreDefines.SceneSelection, keywords = CoreKeywords.HDBase, - includes = SceneSelectionIncludes, + includes = GenerateIncludes(), }; + + IncludeCollection GenerateIncludes() + { + var includes = new IncludeCollection(); + + includes.Add(CoreIncludes.CorePregraph); + if (supportLighting) + includes.Add(CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.CoreUtility); + if (supportLighting) + { + includes.Add(CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph); + } + includes.Add(CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); + + return includes; + } } public static BlockFieldDescriptor[] FragmentSceneSelection = new BlockFieldDescriptor[] @@ -126,19 +146,6 @@ public static PassDescriptor GenerateSceneSelection() HDBlockFields.SurfaceDescription.DepthOffset, }; - public static IncludeCollection SceneSelectionIncludes = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - // We don't need decals for scene selection ? - // { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - // { kLitDecalData, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - #endregion #region Shadow Caster Pass @@ -374,6 +381,7 @@ public static PassDescriptor GenerateMotionVectors(bool supportLighting) requiredFields = MotionVectorRequiredFields, renderStates = GenerateRenderState(), fieldDependencies = CoreFieldDependencies.Default, + defines = supportLighting ? CoreDefines.DepthMotionVectors : null, pragmas = CorePragmas.DotsInstancedInV2Only, keywords = GenerateKeywords(), includes = GenerateIncludes(), @@ -520,6 +528,8 @@ IncludeCollection GenerateIncludes() BlockFields.SurfaceDescription.BaseColor, HDBlockFields.SurfaceDescription.SpecularOcclusion, BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalOS, + BlockFields.SurfaceDescription.NormalWS, HDBlockFields.SurfaceDescription.BentNormal, BlockFields.SurfaceDescription.Smoothness, BlockFields.SurfaceDescription.Occlusion, @@ -535,6 +545,11 @@ IncludeCollection GenerateIncludes() HDBlockFields.SurfaceDescription.BakedGI, HDBlockFields.SurfaceDescription.BakedBackGI, HDBlockFields.SurfaceDescription.DepthOffset, + HDBlockFields.SurfaceDescription.ShadowTint, // Unlit only field + // Eye fields + HDBlockFields.SurfaceDescription.IrisNormal, + HDBlockFields.SurfaceDescription.IOR, + HDBlockFields.SurfaceDescription.Mask, }; public static FieldCollection ForwardOnlyFields = new FieldCollection() @@ -574,6 +589,7 @@ public static PassDescriptor GenerateBackThenFront(bool supportLighting, string // Collections structs = CoreStructCollections.Default, + requiredFields = CoreRequiredFields.LitMinimal, fieldDependencies = CoreFieldDependencies.Default, renderStates = CoreRenderStates.TransparentBackface, pragmas = CorePragmas.DotsInstancedInV1AndV2, @@ -641,6 +657,16 @@ IncludeCollection GenerateIncludes() HDBlockFields.SurfaceDescription.RefractionColor, HDBlockFields.SurfaceDescription.RefractionDistance, HDBlockFields.SurfaceDescription.DepthOffset, + // Hair only + HDBlockFields.SurfaceDescription.HairStrandDirection, + HDBlockFields.SurfaceDescription.Transmittance, + HDBlockFields.SurfaceDescription.RimTransmissionIntensity, + HDBlockFields.SurfaceDescription.SpecularTint, + HDBlockFields.SurfaceDescription.SpecularShift, + HDBlockFields.SurfaceDescription.SecondarySpecularTint, + HDBlockFields.SurfaceDescription.SecondarySmoothness, + HDBlockFields.SurfaceDescription.SecondarySpecularShift, + }; #endregion 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 52c7802a9ed..66bcba1cab4 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 @@ -67,22 +67,30 @@ PassCollection GetPasses() var passes = new PassCollection { // Common "surface" passes - HDShaderPasses.GenerateSceneSelection(), + HDShaderPasses.GenerateSceneSelection(supportLighting), HDShaderPasses.GenerateShadowCaster(supportLighting), HDShaderPasses.GenerateMETA(supportLighting), HDShaderPasses.GenerateMotionVectors(supportLighting), { HDShaderPasses.GenerateBackThenFront(supportLighting), new FieldCondition(HDFields.TransparentBackFace, true)}, - { HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ + { HDShaderPasses.GenerateTransparentDepthPostpass(supportLighting), new FieldCondition(HDFields.TransparentDepthPostPass, true) }, + }; + + if (supportLighting) + { + passes.Add(HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ new FieldCondition(HDFields.TransparentDepthPrePass, true), - new FieldCondition(HDFields.DisableSSRTransparent, true) }}, - { HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ + new FieldCondition(HDFields.DisableSSRTransparent, true) }); + passes.Add(HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ new FieldCondition(HDFields.TransparentDepthPrePass, true), - new FieldCondition(HDFields.DisableSSRTransparent, false) }}, - { HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ + new FieldCondition(HDFields.DisableSSRTransparent, false) }); + passes.Add(HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ new FieldCondition(HDFields.TransparentDepthPrePass, false), - new FieldCondition(HDFields.DisableSSRTransparent, false) }}, - { HDShaderPasses.GenerateTransparentDepthPostpass(supportLighting), new FieldCondition(HDFields.TransparentDepthPostPass, true) }, - }; + new FieldCondition(HDFields.DisableSSRTransparent, false) }); + } + else + { + passes.Add(HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition(HDFields.TransparentDepthPrePass, true)); + } if (supportForward) { 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 731c5f4c1c2..232017431a2 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 @@ -60,7 +60,28 @@ protected override SubShaderDescriptor GetSubShaderDescriptor() } else { - return base.GetSubShaderDescriptor(); + var descriptor = base.GetSubShaderDescriptor(); + + // We need to add includes for shadow matte as it's a special case (Lighting includes in an unlit pass) + var forwardUnlit = descriptor.passes.FirstOrDefault(p => p.descriptor.lightMode == "ForwardOnly"); + + forwardUnlit.descriptor.includes.Add(CoreIncludes.kHDShadow, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true)); + forwardUnlit.descriptor.includes.Add(CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true)); + forwardUnlit.descriptor.includes.Add(CoreIncludes.kPunctualLightCommon, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true)); + forwardUnlit.descriptor.includes.Add(CoreIncludes.kHDShadowLoop, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true)); + + // { CoreIncludes.CorePregraph }, +// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kHDShadow, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kPunctualLightCommon, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { CoreIncludes.kHDShadowLoop, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, +// { kPassForwardUnlit, IncludeLocation.Postgraph }, + + + return descriptor; } } From 28fa70e42846e3dfdde9bfb9ffc7e83f6ee2d852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 3 Jun 2020 12:52:45 +0200 Subject: [PATCH 16/30] Fix lot of issues with shared render passes --- .../Material/Eye/ShaderGraph/EyePass.template | 10 ++- .../Material/Eye/ShaderGraph/EyeSubTarget.cs | 1 + .../Fabric/ShaderGraph/FabricSubTarget.cs | 1 + .../Hair/ShaderGraph/HairSubTarget.cs | 1 + .../Lit/ShaderGraph/HDLitSubTarget.cs | 1 + .../Material/ShaderGraph/HDShaderPasses.cs | 62 +++++++------------ .../Material/ShaderGraph/SurfaceSubTarget.cs | 6 ++ .../StackLit/ShaderGraph/StackLitSubTarget.cs | 1 + .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 1 + .../Editor/ShaderGraph/HDFields.cs | 1 + 10 files changed, 45 insertions(+), 40 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyePass.template b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyePass.template index fb462570346..1cc6e8fbd65 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyePass.template +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyePass.template @@ -250,7 +250,10 @@ Pass // Perform alpha test very early to save performance (a killed pixel will not sample textures) // TODO: split graph evaluation to grab just alpha dependencies first? tricky.. #ifdef _ALPHATEST_ON - $DoAlphaTest: DoAlphaTest(surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold); + $DoAlphaTest: GENERIC_ALPHA_TEST(surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold); + $DoAlphaTestPrepass: GENERIC_ALPHA_TEST(surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdDepthPrepass); + $DoAlphaTestPostpass: GENERIC_ALPHA_TEST(surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdDepthPostpass); + $DoAlphaTestShadow: GENERIC_ALPHA_TEST(surfaceDescription.Alpha, surfaceDescription.AlphaClipThresholdShadow); #endif $DepthOffset: ApplyDepthOffsetPositionInput(V, surfaceDescription.DepthOffset, GetViewForwardDir(), GetWorldToHClipMatrix(), posInput); @@ -264,7 +267,10 @@ Pass #ifdef _ALPHATEST_ON // Used for sharpening by alpha to mask - $DoAlphaTest: builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold; + $DoAlphaTest: builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThreshold; + $DoAlphaTestPrepass: builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThresholdDepthPrepass; + $DoAlphaTestPostpass: builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThresholdDepthPostpass; + $DoAlphaTestShadow: builtinData.alphaClipTreshold = surfaceDescription.AlphaClipThresholdShadow; #endif // override sampleBakedGI: 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 96f68529592..e2e1f368ea4 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 @@ -25,6 +25,7 @@ sealed partial class EyeSubTarget : LightingSubTarget, ILegacyTarget, IRequiresD protected override string subTargetAssetGuid => "864e4e09d6293cf4d98457f740bb3301"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Eye; protected override string subShaderInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl"; + protected override FieldDescriptor subShaderField => HDFields.SubShader.Eye; EyeData m_EyeData; 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 e9b3e3bb13f..e833bfc07af 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 @@ -25,6 +25,7 @@ sealed partial class FabricSubTarget : LightingSubTarget, ILegacyTarget, IRequir protected override string customInspector => "Rendering.HighDefinition.FabricGUI"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Fabric; protected override string subShaderInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; + protected override FieldDescriptor subShaderField => HDFields.SubShader.Fabric; FabricData m_FabricData; 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 a1c5d541bf8..2c233f27db6 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 @@ -25,6 +25,7 @@ sealed partial class HairSubTarget : LightingSubTarget, ILegacyTarget, IRequires protected override string subTargetAssetGuid => "7e681cc79dd8e6c46ba1e8412d519e26"; // HairSubTarget.cs protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Hair; protected override string subShaderInclude => CoreIncludes.kHair; + protected override FieldDescriptor subShaderField => HDFields.SubShader.Hair; HairData m_HairData; 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 66a80a77ef0..18a6080a14c 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 @@ -28,6 +28,7 @@ sealed partial class HDLitSubTarget : LightingSubTarget, ILegacyTarget, IRequire protected override bool supportDistortion => true; protected override bool supportForward => false; protected override string postDecalsInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; + protected override FieldDescriptor subShaderField => HDFields.SubShader.Lit; HDLitData m_LitData; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index d81828f433e..b9301bb5282 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -171,6 +171,7 @@ static public PassDescriptor GenerateShadowCaster(bool supportLighting) pragmas = CorePragmas.DotsInstancedInV2Only, keywords = CoreKeywords.HDBase, includes = GenerateIncludes(), + requiredFields = supportLighting ? null : UnlitFieldCollection, }; IncludeCollection GenerateIncludes() @@ -194,6 +195,11 @@ IncludeCollection GenerateIncludes() } } + public static FieldCollection UnlitFieldCollection = new FieldCollection + { + HDFields.SubShader.Unlit, + }; + public static BlockFieldDescriptor[] FragmentShadowCaster = new BlockFieldDescriptor[] { BlockFields.SurfaceDescription.Alpha, @@ -253,7 +259,7 @@ IncludeCollection GenerateIncludes() public static BlockFieldDescriptor[] FragmentMeta = new BlockFieldDescriptor[] { - // TODO: this will probably break with unlit / other target that does not support all of these fields + // TODO: We want to only put common fields here, not target specific. BlockFields.SurfaceDescription.BaseColor, BlockFields.SurfaceDescription.NormalTS, BlockFields.SurfaceDescription.NormalWS, @@ -280,6 +286,8 @@ IncludeCollection GenerateIncludes() HDBlockFields.SurfaceDescription.RefractionIndex, HDBlockFields.SurfaceDescription.RefractionColor, HDBlockFields.SurfaceDescription.RefractionDistance, + // Eye fields + HDBlockFields.SurfaceDescription.IrisNormal, }; #endregion @@ -378,7 +386,7 @@ public static PassDescriptor GenerateMotionVectors(bool supportLighting) // Collections structs = CoreStructCollections.Default, - requiredFields = MotionVectorRequiredFields, + requiredFields = CoreRequiredFields.LitFull, renderStates = GenerateRenderState(), fieldDependencies = CoreFieldDependencies.Default, defines = supportLighting ? CoreDefines.DepthMotionVectors : null, @@ -436,23 +444,6 @@ IncludeCollection GenerateIncludes() } } - static FieldCollection MotionVectorRequiredFields = new FieldCollection() - { - HDStructFields.AttributesMesh.normalOS, - HDStructFields.AttributesMesh.tangentOS, - HDStructFields.AttributesMesh.uv0, - HDStructFields.AttributesMesh.uv1, - HDStructFields.AttributesMesh.color, - HDStructFields.AttributesMesh.uv2, - HDStructFields.AttributesMesh.uv3, - HDStructFields.FragInputs.tangentToWorld, - HDStructFields.FragInputs.positionRWS, - HDStructFields.FragInputs.texCoord1, - HDStructFields.FragInputs.texCoord2, - HDStructFields.FragInputs.texCoord3, - HDStructFields.FragInputs.color, - }; - public static BlockFieldDescriptor[] FragmentMotionVectors = new BlockFieldDescriptor[] { BlockFields.SurfaceDescription.NormalTS, @@ -484,7 +475,7 @@ public static PassDescriptor GenereateForwardOnlyPass(bool supportLighting) // Collections structs = CoreStructCollections.Default, - requiredFields = ForwardOnlyFields, + requiredFields = CoreRequiredFields.LitFull, fieldDependencies = CoreFieldDependencies.Default, renderStates = CoreRenderStates.Forward, pragmas = CorePragmas.DotsInstancedInV2Only, @@ -550,23 +541,15 @@ IncludeCollection GenerateIncludes() HDBlockFields.SurfaceDescription.IrisNormal, HDBlockFields.SurfaceDescription.IOR, HDBlockFields.SurfaceDescription.Mask, - }; - - public static FieldCollection ForwardOnlyFields = new FieldCollection() - { - HDStructFields.AttributesMesh.normalOS, - HDStructFields.AttributesMesh.tangentOS, - HDStructFields.AttributesMesh.uv0, - HDStructFields.AttributesMesh.uv1, - HDStructFields.AttributesMesh.color, - HDStructFields.AttributesMesh.uv2, - HDStructFields.AttributesMesh.uv3, - HDStructFields.FragInputs.tangentToWorld, - HDStructFields.FragInputs.positionRWS, - HDStructFields.FragInputs.texCoord1, - HDStructFields.FragInputs.texCoord2, - HDStructFields.FragInputs.texCoord3, - HDStructFields.FragInputs.color, + // Hair only + HDBlockFields.SurfaceDescription.HairStrandDirection, + HDBlockFields.SurfaceDescription.Transmittance, + HDBlockFields.SurfaceDescription.RimTransmissionIntensity, + HDBlockFields.SurfaceDescription.SpecularTint, + HDBlockFields.SurfaceDescription.SpecularShift, + HDBlockFields.SurfaceDescription.SecondarySpecularTint, + HDBlockFields.SurfaceDescription.SecondarySmoothness, + HDBlockFields.SurfaceDescription.SecondarySpecularShift, }; #endregion @@ -657,6 +640,10 @@ IncludeCollection GenerateIncludes() HDBlockFields.SurfaceDescription.RefractionColor, HDBlockFields.SurfaceDescription.RefractionDistance, HDBlockFields.SurfaceDescription.DepthOffset, + // Eye fields + HDBlockFields.SurfaceDescription.IrisNormal, + HDBlockFields.SurfaceDescription.IOR, + HDBlockFields.SurfaceDescription.Mask, // Hair only HDBlockFields.SurfaceDescription.HairStrandDirection, HDBlockFields.SurfaceDescription.Transmittance, @@ -666,7 +653,6 @@ IncludeCollection GenerateIncludes() HDBlockFields.SurfaceDescription.SecondarySpecularTint, HDBlockFields.SurfaceDescription.SecondarySmoothness, HDBlockFields.SurfaceDescription.SecondarySpecularShift, - }; #endregion 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 66bcba1cab4..206a79da712 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 @@ -43,6 +43,7 @@ protected override string renderQueue protected abstract string subShaderInclude { get; } protected virtual string postDecalsInclude => null; + protected abstract FieldDescriptor subShaderField { get; } // Maybe we should rename it custom forward pass include ? // protected virtual string postGraphInclude => null; @@ -152,6 +153,11 @@ SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor finalIncludes.Add(include.descriptor.value, include.descriptor.location, include.fieldConditions); } + if (passDescriptor.requiredFields == null) + passDescriptor.requiredFields = new FieldCollection(); + + passDescriptor.requiredFields.Add(subShaderField); + passDescriptor.includes = finalIncludes; finalPasses.Add(passDescriptor, passes[i].fieldConditions); 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 84123057180..001196416b2 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 @@ -27,6 +27,7 @@ sealed partial class StackLitSubTarget : LightingSubTarget, ILegacyTarget, IRequ protected override string customInspector => "Rendering.HighDefinition.StackLitGUI"; protected override string subTargetAssetGuid => "5f7ba34a143e67647b202a662748dae3"; // StackLitSubTarget.cs protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_StackLit; + protected override FieldDescriptor subShaderField => HDFields.SubShader.StackLit; protected override bool supportDistortion => true; 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 232017431a2..2b54fec7ab9 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 @@ -31,6 +31,7 @@ sealed partial class HDUnlitSubTarget : SurfaceSubTarget, IRequiresData true; protected override bool supportForward => true; + protected override FieldDescriptor subShaderField => HDFields.SubShader.Unlit; protected override string subShaderInclude => CoreIncludes.kUnlit; diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDFields.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDFields.cs index fae9db2cf7a..5d02ce31990 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDFields.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDFields.cs @@ -177,6 +177,7 @@ public struct SubShader public static FieldDescriptor StackLit = new FieldDescriptor(kSubShader, "StackLit SubShader", ""); public static FieldDescriptor Unlit = new FieldDescriptor(kSubShader, "Unlit SubShader", ""); public static FieldDescriptor Hair = new FieldDescriptor(kSubShader, "Hair SubShader", ""); + public static FieldDescriptor Eye = new FieldDescriptor(kSubShader, "Eye SubShader", ""); } #endregion From c3ed72ead8c7d5c6ec9a9f0fe9e40b4b5f1a16f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 3 Jun 2020 18:50:22 +0200 Subject: [PATCH 17/30] Moved SSS property to target specific and converted all ray tracing passes --- .../Material/Eye/ShaderGraph/EyeData.cs | 8 + .../Eye/ShaderGraph/EyeSubTarget.Migration.cs | 6 +- .../Material/Eye/ShaderGraph/EyeSubTarget.cs | 12 +- .../EyeSurfaceOptionPropertyBlock.cs | 2 +- .../Material/Fabric/ShaderGraph/FabricData.cs | 8 + .../ShaderGraph/FabricSubTarget.Migration.cs | 8 +- .../Fabric/ShaderGraph/FabricSubTarget.cs | 21 +- .../FabricSurfaceOptionPropertyBlock.cs | 2 +- .../Hair/ShaderGraph/HairSubTarget.cs | 6 +- .../ShaderGraph/HDLitSubTarget.Migration.cs | 1 - .../Lit/ShaderGraph/HDLitSubTarget.cs | 43 +- .../LitSurfaceOptionPropertyBlock.cs | 7 +- .../Material/ShaderGraph/HDShaderPasses.cs | 388 +++++++++++++++++- .../Material/ShaderGraph/LightingSubTarget.cs | 17 +- .../Material/ShaderGraph/SurfaceSubTarget.cs | 32 +- .../StackLit/ShaderGraph/StackLitData.cs | 8 + .../StackLitSubTarget.Migration.cs | 6 +- .../StackLit/ShaderGraph/StackLitSubTarget.cs | 11 +- .../StackLitSurfaceOptionPropertyBlock.cs | 2 +- .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 76 ++-- .../ShaderGraph/HDSubShaderUtilities.cs | 4 +- .../ShaderGraph/TargetData/LightingData.cs | 8 - 22 files changed, 557 insertions(+), 119 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeData.cs index 3ffb915a28b..c8db2ed1406 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeData.cs @@ -19,5 +19,13 @@ public MaterialType materialType get => m_MaterialType; set => m_MaterialType = value; } + + [SerializeField] + bool m_SubsurfaceScattering = false; + public bool subsurfaceScattering + { + get => m_SubsurfaceScattering; + set => m_SubsurfaceScattering = value; + } } } 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 index 85a87f745ce..cea67ba99e1 100644 --- 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 @@ -47,8 +47,8 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl"; protected override FieldDescriptor subShaderField => HDFields.SubShader.Eye; + protected override bool supportRaytracing => false; + protected override bool requireSplitLighting => eyeData.subsurfaceScattering; + EyeData m_EyeData; EyeData IRequiresData.data @@ -48,7 +51,7 @@ public override void GetFields(ref TargetFieldContext context) // Eye specific properties 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); + context.AddField(HDFields.SubsurfaceScattering, eyeData.subsurfaceScattering && systemData.surfaceType != SurfaceType.Transparent); context.AddField(HDFields.DoAlphaTest, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold)); } @@ -62,8 +65,8 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); context.AddBlock(HDBlockFields.SurfaceDescription.IOR); context.AddBlock(HDBlockFields.SurfaceDescription.Mask); - context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, lightingData.subsurfaceScattering); - context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, lightingData.subsurfaceScattering); + context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, eyeData.subsurfaceScattering); + context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, eyeData.subsurfaceScattering); } protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) @@ -72,6 +75,9 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); } + protected override int ComputeMaterialNeedsUpdateHash() + => base.ComputeMaterialNeedsUpdateHash() * 23 + eyeData.subsurfaceScattering.GetHashCode(); + // #region SubShaders // static class SubShaders // { diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSurfaceOptionPropertyBlock.cs index 2e23349ff3f..65825148798 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSurfaceOptionPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSurfaceOptionPropertyBlock.cs @@ -33,7 +33,7 @@ protected override void CreatePropertyGUI() base.CreatePropertyGUI(); // Eye specific properties: - AddProperty(subsurfaceEnableText, () => lightingData.subsurfaceScattering, (newValue) => lightingData.subsurfaceScattering = newValue); + AddProperty(subsurfaceEnableText, () => eyeData.subsurfaceScattering, (newValue) => eyeData.subsurfaceScattering = newValue); } } } 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 1cd2953ef3c..87384581322 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 @@ -35,5 +35,13 @@ public bool transmission get => m_Transmission; set => m_Transmission = value; } + + [SerializeField] + bool m_SubsurfaceScattering = false; + public bool subsurfaceScattering + { + get => m_SubsurfaceScattering; + set => m_SubsurfaceScattering = 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 d7bbccca7ae..81d21ffec66 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 @@ -45,8 +45,8 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary HDShaderUtils.ShaderID.SG_Fabric; protected override string subShaderInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; protected override FieldDescriptor subShaderField => HDFields.SubShader.Fabric; + protected override bool requireSplitLighting => fabricData.subsurfaceScattering; FabricData m_FabricData; @@ -41,6 +42,16 @@ public FabricData fabricData set => m_FabricData = value; } + protected override SubShaderDescriptor GetRaytracingSubShaderDescriptor() + { + var descriptor = base.GetRaytracingSubShaderDescriptor(); + + if (fabricData.subsurfaceScattering) + descriptor.passes.Add(FabricPasses.RaytracingSubSurface); + + return descriptor; + } + public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); @@ -48,7 +59,7 @@ public override void GetFields(ref TargetFieldContext context) // Fabric specific properties 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.SubsurfaceScattering, fabricData.subsurfaceScattering && systemData.surfaceType != SurfaceType.Transparent); context.AddField(HDFields.Transmission, fabricData.transmission); context.AddField(HDFields.DoAlphaTest, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold)); context.AddField(HDFields.EnergyConservingSpecular, fabricData.energyConservingSpecular); @@ -61,8 +72,8 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) // Fabric specific blocks context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); context.AddBlock(BlockFields.SurfaceDescription.Specular); - context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, lightingData.subsurfaceScattering || fabricData.transmission); - context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, lightingData.subsurfaceScattering); + context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, fabricData.subsurfaceScattering || fabricData.transmission); + context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, fabricData.subsurfaceScattering); context.AddBlock(HDBlockFields.SurfaceDescription.Thickness, fabricData.transmission); // Fabric Silk @@ -79,6 +90,10 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL blockList.AddPropertyBlock(new AdvancedOptionsPropertyBlock()); } + protected override int ComputeMaterialNeedsUpdateHash() + => base.ComputeMaterialNeedsUpdateHash() * 23 + fabricData.subsurfaceScattering.GetHashCode(); + + #region SubShaders static class SubShaders { diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSurfaceOptionPropertyBlock.cs index 6702e6a50fa..706ab693062 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSurfaceOptionPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSurfaceOptionPropertyBlock.cs @@ -34,7 +34,7 @@ protected override void CreatePropertyGUI() // Fabric specific properties: AddProperty(energyConservingSpecularColorText, () => fabricData.energyConservingSpecular, (newValue) => fabricData.energyConservingSpecular = newValue); - AddProperty(subsurfaceEnableText, () => lightingData.subsurfaceScattering, (newValue) => lightingData.subsurfaceScattering = newValue); + AddProperty(subsurfaceEnableText, () => fabricData.subsurfaceScattering, (newValue) => fabricData.subsurfaceScattering = newValue); AddProperty(transmissionEnableText, () => fabricData.transmission, (newValue) => fabricData.transmission = newValue); } } 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 2d628d88bd4..be96222727f 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 @@ -26,6 +26,8 @@ sealed partial class HairSubTarget : LightingSubTarget, ILegacyTarget, IRequires protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Hair; protected override string subShaderInclude => CoreIncludes.kHair; protected override FieldDescriptor subShaderField => HDFields.SubShader.Hair; + protected override bool requireSplitLighting => false; + HairData m_HairData; @@ -43,10 +45,6 @@ public HairData hairData public override void GetFields(ref TargetFieldContext 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: 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 195de840076..51936e8a0b8 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 @@ -139,7 +139,6 @@ void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary { - public HDLitSubTarget() => displayName = "Lit"; - - // TODO: remove this line - public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; - - protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; - protected override string customInspector => "Rendering.HighDefinition.HDLitGUI"; - protected override string subTargetAssetGuid => "caab952c840878340810cca27417971c"; // HDLitSubTarget.cs - protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; - - protected override bool supportDistortion => true; - protected override bool supportForward => false; - protected override string postDecalsInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; - protected override FieldDescriptor subShaderField => HDFields.SubShader.Lit; - HDLitData m_LitData; HDLitData IRequiresData.data @@ -44,6 +29,24 @@ public HDLitData litData set => m_LitData = value; } + public HDLitSubTarget() => displayName = "Lit"; + + // TODO: remove this line when all the passes are moved to HDPasses + public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; + + protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; + protected override string customInspector => "Rendering.HighDefinition.HDLitGUI"; + protected override string subTargetAssetGuid => "caab952c840878340810cca27417971c"; // HDLitSubTarget.cs + protected override string postDecalsInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; + protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; + protected override FieldDescriptor subShaderField => HDFields.SubShader.Lit; + + // SubShader features + protected override bool supportDistortion => true; + protected override bool supportForward => false; + protected override bool supportPathtracing => true; + protected override bool requireSplitLighting => litData.materialType == HDLitData.MaterialType.SubsurfaceScattering; + protected override SubShaderDescriptor GetSubShaderDescriptor() { var descriptor = base.GetSubShaderDescriptor(); @@ -57,6 +60,16 @@ protected override SubShaderDescriptor GetSubShaderDescriptor() return descriptor; } + protected override SubShaderDescriptor GetRaytracingSubShaderDescriptor() + { + var descriptor = base.GetRaytracingSubShaderDescriptor(); + + if (litData.materialType == HDLitData.MaterialType.SubsurfaceScattering) + descriptor.passes.Add(LitPasses.RaytracingSubSurface); + + return descriptor; + } + public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs index 02a5bee5051..874cc46fcc9 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/LitSurfaceOptionPropertyBlock.cs @@ -29,12 +29,7 @@ public LitSurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features feature 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(materialIDText, () => litData.materialType, (newValue) => litData.materialType = newValue); AddProperty(rayTracingText, () => litData.rayTracing, (newValue) => litData.rayTracing = newValue); base.CreatePropertyGUI(); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index b9301bb5282..737a1217d57 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -556,7 +556,7 @@ IncludeCollection GenerateIncludes() #region Back then front pass - public static PassDescriptor GenerateBackThenFront(bool supportLighting, string forwardPassInclude = CoreIncludes.kPassForward) + public static PassDescriptor GenerateBackThenFront(bool supportLighting) { return new PassDescriptor { @@ -659,7 +659,7 @@ IncludeCollection GenerateIncludes() #region Transparent Depth Prepass - public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLighting, string forwardPassInclude = CoreIncludes.kPassForward) + public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLighting) { return new PassDescriptor { @@ -772,7 +772,7 @@ IncludeCollection GenerateIncludes() #region Transparent Depth Postpass - public static PassDescriptor GenerateTransparentDepthPostpass(bool supportLighting, string forwardPassInclude = CoreIncludes.kPassForward) + public static PassDescriptor GenerateTransparentDepthPostpass(bool supportLighting) { return new PassDescriptor { @@ -837,6 +837,388 @@ RenderStateCollection GenerateRenderState() HDBlockFields.SurfaceDescription.DepthOffset, }; +#endregion + +#region Raytracing Indirect + + public static PassDescriptor GenerateRaytracingIndirect(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "IndirectDXR", + referenceName = "SHADERPASS_RAYTRACING_INDIRECT", + lightMode = "IndirectDXR", + useInPreview = false, + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = RaytracingIndirectFragment, + + // Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + pragmas = CorePragmas.RaytracingBasic, + defines = supportLighting ? GenerateDefines() : null, + keywords = CoreKeywords.RaytracingIndirect, + includes = CoreIncludes.Raytracing, + requiredFields = new FieldCollection(){ HDFields.ShaderPass.RaytracingIndirect }, + }; + + DefineCollection GenerateDefines() + { + return new DefineCollection + { + { CoreKeywordDescriptors.Shadow, 0 }, + { RayTracingNode.GetRayTracingKeyword(), 1 }, + { CoreKeywordDescriptors.HasLightloop, 1 }, + }; + } + } + + public static BlockFieldDescriptor[] RaytracingIndirectFragment = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalWS, + BlockFields.SurfaceDescription.NormalOS, + HDBlockFields.SurfaceDescription.BentNormal, + HDBlockFields.SurfaceDescription.Tangent, + HDBlockFields.SurfaceDescription.SubsurfaceMask, + HDBlockFields.SurfaceDescription.Thickness, + HDBlockFields.SurfaceDescription.DiffusionProfileHash, + HDBlockFields.SurfaceDescription.IridescenceMask, + HDBlockFields.SurfaceDescription.IridescenceThickness, + BlockFields.SurfaceDescription.Specular, + HDBlockFields.SurfaceDescription.CoatMask, + BlockFields.SurfaceDescription.Metallic, + BlockFields.SurfaceDescription.Emission, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Occlusion, + HDBlockFields.SurfaceDescription.SpecularOcclusion, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.Anisotropy, + HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, + HDBlockFields.SurfaceDescription.SpecularAAThreshold, + HDBlockFields.SurfaceDescription.RefractionIndex, + HDBlockFields.SurfaceDescription.RefractionColor, + HDBlockFields.SurfaceDescription.RefractionDistance, + HDBlockFields.SurfaceDescription.BakedGI, + HDBlockFields.SurfaceDescription.BakedBackGI, + HDBlockFields.SurfaceDescription.DepthOffset, + //Hair blocks: + HDBlockFields.SurfaceDescription.SpecularTint, + HDBlockFields.SurfaceDescription.SpecularShift, + HDBlockFields.SurfaceDescription.SecondarySpecularTint, + HDBlockFields.SurfaceDescription.SecondarySmoothness, + HDBlockFields.SurfaceDescription.SecondarySpecularShift, + HDBlockFields.SurfaceDescription.HairStrandDirection, + HDBlockFields.SurfaceDescription.Transmittance, + HDBlockFields.SurfaceDescription.RimTransmissionIntensity, + }; + +#endregion + +#region Raytracing Visibility + + public static PassDescriptor GenerateRaytracingVisibility(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "VisibilityDXR", + referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", + lightMode = "VisibilityDXR", + useInPreview = false, + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = RaytracingVisibilityFragment, + + // Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + pragmas = CorePragmas.RaytracingBasic, + defines = supportLighting ? RaytracingVisibilityDefines : null, + keywords = CoreKeywords.RaytracingVisiblity, + requiredFields = new FieldCollection(){ HDFields.ShaderPass.RaytracingVisibility }, + includes = CoreIncludes.Raytracing, + }; + } + + public static DefineCollection RaytracingVisibilityDefines = new DefineCollection + { + { RayTracingNode.GetRayTracingKeyword(), 1 }, + }; + + // TODO: we might want to share this with all ray tracing passes + public static BlockFieldDescriptor[] RaytracingVisibilityFragment = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalWS, + BlockFields.SurfaceDescription.NormalOS, + HDBlockFields.SurfaceDescription.BentNormal, + HDBlockFields.SurfaceDescription.Tangent, + HDBlockFields.SurfaceDescription.SubsurfaceMask, + HDBlockFields.SurfaceDescription.Thickness, + HDBlockFields.SurfaceDescription.DiffusionProfileHash, + HDBlockFields.SurfaceDescription.IridescenceMask, + HDBlockFields.SurfaceDescription.IridescenceThickness, + BlockFields.SurfaceDescription.Specular, + HDBlockFields.SurfaceDescription.CoatMask, + BlockFields.SurfaceDescription.Metallic, + BlockFields.SurfaceDescription.Emission, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Occlusion, + HDBlockFields.SurfaceDescription.SpecularOcclusion, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.Anisotropy, + HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, + HDBlockFields.SurfaceDescription.SpecularAAThreshold, + HDBlockFields.SurfaceDescription.RefractionIndex, + HDBlockFields.SurfaceDescription.RefractionColor, + HDBlockFields.SurfaceDescription.RefractionDistance, + HDBlockFields.SurfaceDescription.BakedGI, + HDBlockFields.SurfaceDescription.BakedBackGI, + HDBlockFields.SurfaceDescription.DepthOffset, + //Hair blocks: + HDBlockFields.SurfaceDescription.SpecularTint, + HDBlockFields.SurfaceDescription.SpecularShift, + HDBlockFields.SurfaceDescription.SecondarySpecularTint, + HDBlockFields.SurfaceDescription.SecondarySmoothness, + HDBlockFields.SurfaceDescription.SecondarySpecularShift, + HDBlockFields.SurfaceDescription.HairStrandDirection, + HDBlockFields.SurfaceDescription.Transmittance, + HDBlockFields.SurfaceDescription.RimTransmissionIntensity, + }; + +#endregion + +#region Raytracing Forward + + public static PassDescriptor GenerateRaytracingForward(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "ForwardDXR", + referenceName = "SHADERPASS_RAYTRACING_FORWARD", + lightMode = "ForwardDXR", + useInPreview = false, + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = RaytracingForwardFragment, + + // Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + pragmas = CorePragmas.RaytracingBasic, + defines = supportLighting ? RaytracingForwardDefines : null, + keywords = CoreKeywords.RaytracingGBufferForward, + includes = CoreIncludes.Raytracing, + requiredFields = new FieldCollection(){ HDFields.ShaderPass.RaytracingForward }, + }; + } + + public static DefineCollection RaytracingForwardDefines = new DefineCollection + { + { CoreKeywordDescriptors.Shadow, 0 }, + { RayTracingNode.GetRayTracingKeyword(), 0 }, + { CoreKeywordDescriptors.HasLightloop, 1 }, + }; + + public static BlockFieldDescriptor[] RaytracingForwardFragment = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalWS, + BlockFields.SurfaceDescription.NormalOS, + HDBlockFields.SurfaceDescription.BentNormal, + HDBlockFields.SurfaceDescription.Tangent, + HDBlockFields.SurfaceDescription.SubsurfaceMask, + HDBlockFields.SurfaceDescription.Thickness, + HDBlockFields.SurfaceDescription.DiffusionProfileHash, + HDBlockFields.SurfaceDescription.IridescenceMask, + HDBlockFields.SurfaceDescription.IridescenceThickness, + BlockFields.SurfaceDescription.Specular, + HDBlockFields.SurfaceDescription.CoatMask, + BlockFields.SurfaceDescription.Metallic, + BlockFields.SurfaceDescription.Emission, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Occlusion, + HDBlockFields.SurfaceDescription.SpecularOcclusion, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.Anisotropy, + HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, + HDBlockFields.SurfaceDescription.SpecularAAThreshold, + HDBlockFields.SurfaceDescription.RefractionIndex, + HDBlockFields.SurfaceDescription.RefractionColor, + HDBlockFields.SurfaceDescription.RefractionDistance, + HDBlockFields.SurfaceDescription.BakedGI, + HDBlockFields.SurfaceDescription.BakedBackGI, + HDBlockFields.SurfaceDescription.DepthOffset, + //Hair blocks: + HDBlockFields.SurfaceDescription.SpecularTint, + HDBlockFields.SurfaceDescription.SpecularShift, + HDBlockFields.SurfaceDescription.SecondarySpecularTint, + HDBlockFields.SurfaceDescription.SecondarySmoothness, + HDBlockFields.SurfaceDescription.SecondarySpecularShift, + HDBlockFields.SurfaceDescription.HairStrandDirection, + HDBlockFields.SurfaceDescription.Transmittance, + HDBlockFields.SurfaceDescription.RimTransmissionIntensity, + }; + +#endregion + +#region Raytracing GBuffer + + public static PassDescriptor GenerateRaytracingGBuffer(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "GBufferDXR", + referenceName = "SHADERPASS_RAYTRACING_GBUFFER", + lightMode = "GBufferDXR", + useInPreview = false, + + // Port Mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = RaytracingGBufferFragment, + + // Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + pragmas = CorePragmas.RaytracingBasic, + defines = supportLighting ? RaytracingGBufferDefines : null, + keywords = CoreKeywords.RaytracingGBufferForward, + includes = CoreIncludes.Raytracing, + requiredFields = new FieldCollection(){ HDFields.ShaderPass.RayTracingGBuffer }, + }; + } + + public static DefineCollection RaytracingGBufferDefines = new DefineCollection + { + { CoreKeywordDescriptors.Shadow, 0 }, + { RayTracingNode.GetRayTracingKeyword(), 1 }, + }; + + public static BlockFieldDescriptor[] RaytracingGBufferFragment = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalWS, + BlockFields.SurfaceDescription.NormalOS, + HDBlockFields.SurfaceDescription.BentNormal, + HDBlockFields.SurfaceDescription.Tangent, + HDBlockFields.SurfaceDescription.SubsurfaceMask, + HDBlockFields.SurfaceDescription.Thickness, + HDBlockFields.SurfaceDescription.DiffusionProfileHash, + HDBlockFields.SurfaceDescription.IridescenceMask, + HDBlockFields.SurfaceDescription.IridescenceThickness, + BlockFields.SurfaceDescription.Specular, + HDBlockFields.SurfaceDescription.CoatMask, + BlockFields.SurfaceDescription.Metallic, + BlockFields.SurfaceDescription.Emission, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Occlusion, + HDBlockFields.SurfaceDescription.SpecularOcclusion, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.Anisotropy, + HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, + HDBlockFields.SurfaceDescription.SpecularAAThreshold, + HDBlockFields.SurfaceDescription.RefractionIndex, + HDBlockFields.SurfaceDescription.RefractionColor, + HDBlockFields.SurfaceDescription.RefractionDistance, + HDBlockFields.SurfaceDescription.BakedGI, + HDBlockFields.SurfaceDescription.BakedBackGI, + HDBlockFields.SurfaceDescription.DepthOffset, + //Hair blocks: + HDBlockFields.SurfaceDescription.SpecularTint, + HDBlockFields.SurfaceDescription.SpecularShift, + HDBlockFields.SurfaceDescription.SecondarySpecularTint, + HDBlockFields.SurfaceDescription.SecondarySmoothness, + HDBlockFields.SurfaceDescription.SecondarySpecularShift, + HDBlockFields.SurfaceDescription.HairStrandDirection, + HDBlockFields.SurfaceDescription.Transmittance, + HDBlockFields.SurfaceDescription.RimTransmissionIntensity, + }; + +#endregion + +#region Path Tracing + + public static PassDescriptor GeneratePathTracing(bool supportLighting) + { + return new PassDescriptor + { + //Definition + displayName = "PathTracingDXR", + referenceName = "SHADERPASS_PATH_TRACING", + lightMode = "PathTracingDXR", + useInPreview = false, + + //Port mask + validVertexBlocks = CoreBlockMasks.Vertex, + validPixelBlocks = PathTracingFragment, + + //Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + pragmas = CorePragmas.RaytracingBasic, + defines = supportLighting ? RaytracingPathTracingDefines : null, + keywords = CoreKeywords.HDBaseNoCrossFade, + includes = CoreIncludes.Raytracing, + requiredFields = new FieldCollection(){ HDFields.ShaderPass.RaytracingPathTracing }, + }; + } + + public static DefineCollection RaytracingPathTracingDefines = new DefineCollection + { + { CoreKeywordDescriptors.Shadow, 0 }, + { RayTracingNode.GetRayTracingKeyword(), 0 }, + { CoreKeywordDescriptors.HasLightloop, 1 }, + }; + + public static BlockFieldDescriptor[] PathTracingFragment = new BlockFieldDescriptor[] + { + BlockFields.SurfaceDescription.BaseColor, + BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalWS, + BlockFields.SurfaceDescription.NormalOS, + HDBlockFields.SurfaceDescription.BentNormal, + HDBlockFields.SurfaceDescription.Tangent, + HDBlockFields.SurfaceDescription.SubsurfaceMask, + HDBlockFields.SurfaceDescription.Thickness, + HDBlockFields.SurfaceDescription.DiffusionProfileHash, + HDBlockFields.SurfaceDescription.IridescenceMask, + HDBlockFields.SurfaceDescription.IridescenceThickness, + BlockFields.SurfaceDescription.Specular, + HDBlockFields.SurfaceDescription.CoatMask, + BlockFields.SurfaceDescription.Metallic, + BlockFields.SurfaceDescription.Emission, + BlockFields.SurfaceDescription.Smoothness, + BlockFields.SurfaceDescription.Occlusion, + HDBlockFields.SurfaceDescription.SpecularOcclusion, + BlockFields.SurfaceDescription.Alpha, + BlockFields.SurfaceDescription.AlphaClipThreshold, + HDBlockFields.SurfaceDescription.Anisotropy, + HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, + HDBlockFields.SurfaceDescription.SpecularAAThreshold, + HDBlockFields.SurfaceDescription.RefractionIndex, + HDBlockFields.SurfaceDescription.RefractionColor, + HDBlockFields.SurfaceDescription.RefractionDistance, + HDBlockFields.SurfaceDescription.BakedGI, + HDBlockFields.SurfaceDescription.BakedBackGI, + HDBlockFields.SurfaceDescription.DepthOffset, + }; + #endregion } 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 ea4704e7e95..31213980252 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 @@ -23,6 +23,12 @@ LightingData IRequiresData.data set => m_LightingData = value; } + public LightingData lightingData + { + get => m_LightingData; + set => m_LightingData = value; + } + protected override string renderQueue { get @@ -35,12 +41,6 @@ protected override string renderQueue protected override string renderType => HDRenderTypeTags.HDLitShader.ToString(); - public LightingData lightingData - { - get => m_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); @@ -57,7 +57,6 @@ protected override int ComputeMaterialNeedsUpdateHash() 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; @@ -67,6 +66,8 @@ protected override int ComputeMaterialNeedsUpdateHash() // All lit sub targets are forward only except Lit so we set it as default here protected override bool supportForward => true; + protected abstract bool requireSplitLighting { get; } + public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); @@ -131,7 +132,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera base.CollectShaderProperties(collector, generationMode); // Add all shader properties required by the inspector - HDSubShaderUtilities.AddStencilShaderProperties(collector, systemData, lightingData); + HDSubShaderUtilities.AddStencilShaderProperties(collector, systemData, lightingData, requireSplitLighting); } } } \ 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 a72b82e9ff7..3eac5b7bcd9 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 @@ -38,8 +38,8 @@ protected override string renderQueue protected virtual bool supportForward => false; protected virtual bool supportLighting => false; protected virtual bool supportDistortion => false; - protected virtual bool supportRaytracing => false; protected virtual bool supportPathtracing => false; + protected virtual bool supportRaytracing => true; protected abstract string subShaderInclude { get; } protected virtual string postDecalsInclude => null; @@ -109,19 +109,29 @@ protected virtual SubShaderDescriptor GetRaytracingSubShaderDescriptor() { return new SubShaderDescriptor { - generatesPreview = true, + generatesPreview = false, + passes = GetPasses(), }; - // PassCollection GetPasses() - // { - // var passes = new PassCollection - // { - // // TODO - // // Common "surface" raytracing passes - // }; + PassCollection GetPasses() + { + var passes = new PassCollection(); + + if (supportRaytracing) + { + // Common "surface" raytracing passes + passes.Add(HDShaderPasses.GenerateRaytracingIndirect(supportLighting)); + passes.Add(HDShaderPasses.GenerateRaytracingVisibility(supportLighting)); + passes.Add(HDShaderPasses.GenerateRaytracingForward(supportLighting)); + passes.Add(HDShaderPasses.GenerateRaytracingGBuffer(supportLighting)); + passes.Add(HDShaderPasses.GenerateRaytracingGBuffer(supportLighting)); + }; + + if (supportPathtracing) + passes.Add(HDShaderPasses.GeneratePathTracing(supportLighting)); - // return passes; - // } + return passes; + } } SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor) 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 c028789ad15..c8029fb8398 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 @@ -273,5 +273,13 @@ public bool transmission get => m_Transmission; set => m_Transmission = value; } + + [SerializeField] + bool m_SubsurfaceScattering = false; + public bool subsurfaceScattering + { + get => m_SubsurfaceScattering; + set => m_SubsurfaceScattering = 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 39d966e3b26..be4df5bc9e0 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,10 +47,10 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary HDFields.SubShader.StackLit; protected override bool supportDistortion => true; + protected override bool requireSplitLighting => stackLitData.subsurfaceScattering; StackLitData m_StackLitData; @@ -45,6 +46,7 @@ public StackLitData stackLitData set => m_StackLitData = value; } + // TODO stacklit share pass protected override IEnumerable EnumerateSubShaders() { yield return SubShaders.StackLit; @@ -177,7 +179,7 @@ public override void GetFields(ref TargetFieldContext context) // FindSlot(CoatMaskSlotId).value == 1.0f), context.AddField(HDFields.CoatNormal, stackLitData.coatNormal && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.CoatNormal)); context.AddField(HDFields.Iridescence, stackLitData.iridescence); - context.AddField(HDFields.SubsurfaceScattering, lightingData.subsurfaceScattering && systemData.surfaceType != SurfaceType.Transparent); + context.AddField(HDFields.SubsurfaceScattering, stackLitData.subsurfaceScattering && systemData.surfaceType != SurfaceType.Transparent); context.AddField(HDFields.Transmission, stackLitData.transmission); context.AddField(HDFields.DualSpecularLobe, stackLitData.dualSpecularLobe); @@ -295,9 +297,9 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(BlockFields.SurfaceDescription.Smoothness); context.AddBlock(BlockFields.SurfaceDescription.Occlusion); context.AddBlock(HDBlockFields.SurfaceDescription.Anisotropy, stackLitData.anisotropy); - context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, lightingData.subsurfaceScattering); + context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, stackLitData.subsurfaceScattering); context.AddBlock(HDBlockFields.SurfaceDescription.Thickness, stackLitData.transmission); - context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, lightingData.subsurfaceScattering || stackLitData.transmission); + context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, stackLitData.subsurfaceScattering || stackLitData.transmission); // Base Metallic context.AddBlock(BlockFields.SurfaceDescription.Metallic, stackLitData.baseParametrization == StackLit.BaseParametrization.BaseMetallic); @@ -425,6 +427,9 @@ public static bool SpecularOcclusionConeFixupMethodModifiesRoughness(StackLitDat || soConeFixupMethod == StackLitData.SpecularOcclusionConeFixupMethod.BoostAndTilt); } + protected override int ComputeMaterialNeedsUpdateHash() + => base.ComputeMaterialNeedsUpdateHash() * 23 + stackLitData.subsurfaceScattering.GetHashCode(); + #region SubShaders static class SubShaders { 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 index 0fb625e6f81..62d171fcd2d 100644 --- 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 @@ -46,7 +46,7 @@ protected override void CreatePropertyGUI() 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("Subsurface Scattering", () => stackLitData.subsurfaceScattering, (newValue) => stackLitData.subsurfaceScattering = newValue, 1); AddProperty("Transmission", () => stackLitData.transmission, (newValue) => stackLitData.transmission = newValue, 1); // SpecularOcclusion from SSAO 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 9c07aa18291..faf9db61506 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 @@ -25,12 +25,12 @@ sealed partial class HDUnlitSubTarget : SurfaceSubTarget, IRequiresData HDRenderTypeTags.HDUnlitShader.ToString(); protected override string subTargetAssetGuid => "4516595d40fa52047a77940183dc8e74"; // HDUnlitSubTarget protected override string customInspector => "Rendering.HighDefinition.HDUnlitGUI"; + protected override FieldDescriptor subShaderField => HDFields.SubShader.Unlit; + protected override string subShaderInclude => CoreIncludes.kUnlit; protected override bool supportDistortion => true; protected override bool supportForward => true; - protected override FieldDescriptor subShaderField => HDFields.SubShader.Unlit; - - protected override string subShaderInclude => CoreIncludes.kUnlit; + protected override bool supportPathtracing => true; HDUnlitData m_UnlitData; @@ -125,43 +125,43 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera } // Stencil state for unlit: - HDSubShaderUtilities.AddStencilShaderProperties(collector, systemData, null); + HDSubShaderUtilities.AddStencilShaderProperties(collector, systemData, null, false); } -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Unlit = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { UnlitPasses.ShadowCaster }, - { UnlitPasses.META }, - { UnlitPasses.SceneSelection }, - { UnlitPasses.DepthForwardOnly }, - { UnlitPasses.MotionVectors }, - { UnlitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, - { UnlitPasses.ForwardOnly }, - }, - }; - - public static SubShaderDescriptor UnlitRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { UnlitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { UnlitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Unlit = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { UnlitPasses.ShadowCaster }, +// { UnlitPasses.META }, +// { UnlitPasses.SceneSelection }, +// { UnlitPasses.DepthForwardOnly }, +// { UnlitPasses.MotionVectors }, +// { UnlitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, +// { UnlitPasses.ForwardOnly }, +// }, +// }; + +// public static SubShaderDescriptor UnlitRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { UnlitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { UnlitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion // #region Passes // static class UnlitPasses diff --git a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs index 69535dce689..1d5761e6f2f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDSubShaderUtilities.cs @@ -67,17 +67,15 @@ static void AddToggleProperty(this PropertyCollector collector, string reference }); } - public static void AddStencilShaderProperties(PropertyCollector collector, SystemData systemData, LightingData lightingData) + public static void AddStencilShaderProperties(PropertyCollector collector, SystemData systemData, LightingData lightingData, bool splitLighting) { bool ssrStencil = false; - bool splitLighting = false; bool receiveSSROpaque = false; bool receiveSSRTransparent = false; if (lightingData != null) { ssrStencil = systemData.surfaceType == SurfaceType.Opaque ? lightingData.receiveSSR : lightingData.receiveSSRTransparent; - splitLighting = lightingData.subsurfaceScattering; receiveSSROpaque = lightingData.receiveSSR; receiveSSRTransparent = lightingData.receiveSSRTransparent; } 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 9cb666960cf..5d1ab80db6a 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_SubsurfaceScattering = false; - public bool subsurfaceScattering - { - get => m_SubsurfaceScattering; - set => m_SubsurfaceScattering = value; - } - [SerializeField] bool m_SpecularAA; public bool specularAA From 6d394ecc87cce8d57b3d07cc51f74a294e108ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Wed, 3 Jun 2020 19:16:03 +0200 Subject: [PATCH 18/30] Fix missing normal space --- .../Editor/Material/ShaderGraph/HDShaderPasses.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index 737a1217d57..c3321277ffa 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -360,6 +360,8 @@ IncludeCollection GenerateIncludes() public static BlockFieldDescriptor[] FragmentDepthOnlyVectors = new BlockFieldDescriptor[] { BlockFields.SurfaceDescription.NormalTS, + BlockFields.SurfaceDescription.NormalWS, + BlockFields.SurfaceDescription.NormalOS, BlockFields.SurfaceDescription.Smoothness, BlockFields.SurfaceDescription.Alpha, BlockFields.SurfaceDescription.AlphaClipThreshold, From ef2c086cd89530b85ab9ffa4aa251a709af30ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Thu, 4 Jun 2020 16:45:45 +0200 Subject: [PATCH 19/30] Shared more code between passes --- .../Decal/ShaderGraph/DecalSubTarget.cs | 3 +- .../Material/Eye/ShaderGraph/EyeSubTarget.cs | 2 - .../Fabric/ShaderGraph/FabricSubTarget.cs | 1124 ++++++------ .../Hair/ShaderGraph/HairSubTarget.cs | 1291 +++++++------ .../Lit/ShaderGraph/HDLitSubTarget.cs | 1626 ++++++++--------- .../Material/ShaderGraph/HDShaderPasses.cs | 331 +++- .../Material/ShaderGraph/SurfaceSubTarget.cs | 34 +- .../StackLit/ShaderGraph/StackLitSubTarget.cs | 1490 +++++++-------- .../Editor/ShaderGraph/HDTarget.cs | 2 + 9 files changed, 3099 insertions(+), 2804 deletions(-) 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 0c6a11084d5..12d26abf02f 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 @@ -25,6 +25,7 @@ sealed partial class DecalSubTarget : HDSubTarget, ILegacyTarget, IRequiresData< protected override string customInspector => "Rendering.HighDefinition.DecalGUI"; protected override string renderType => HDRenderTypeTags.Opaque.ToString(); protected override string renderQueue => HDRenderQueue.GetShaderTagValue(HDRenderQueue.ChangeType(HDRenderQueue.RenderQueueType.Opaque, decalData.drawOrder, false)); + protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; // Material Data DecalData m_DecalData; @@ -86,8 +87,6 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL blockList.AddPropertyBlock(new DecalPropertyBlock(decalData)); } - protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; - public override void CollectShaderProperties(PropertyCollector collector, GenerationMode generationMode) { Vector1ShaderProperty drawOrder = new Vector1ShaderProperty(); 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 8d028de4e50..7f41f571944 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 @@ -60,9 +60,7 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) base.GetActiveBlocks(ref context); // Eye specific blocks - context.AddBlock(BlockFields.SurfaceDescription.NormalTS); context.AddBlock(HDBlockFields.SurfaceDescription.IrisNormal); - context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); context.AddBlock(HDBlockFields.SurfaceDescription.IOR); context.AddBlock(HDBlockFields.SurfaceDescription.Mask); context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, eyeData.subsurfaceScattering); 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 069e14d224f..c9761f5ff39 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 @@ -47,8 +47,8 @@ protected override SubShaderDescriptor GetRaytracingSubShaderDescriptor() var descriptor = base.GetRaytracingSubShaderDescriptor(); if (fabricData.subsurfaceScattering) - descriptor.passes.Add(FabricPasses.RaytracingSubSurface); - + descriptor.passes.Add(HDShaderPasses.GenerateRaytracingSubsurface()); + return descriptor; } @@ -70,7 +70,6 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) base.GetActiveBlocks(ref context); // Fabric specific blocks - context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); context.AddBlock(BlockFields.SurfaceDescription.Specular); context.AddBlock(HDBlockFields.SurfaceDescription.DiffusionProfileHash, fabricData.subsurfaceScattering || fabricData.transmission); context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, fabricData.subsurfaceScattering); @@ -93,565 +92,564 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL protected override int ComputeMaterialNeedsUpdateHash() => base.ComputeMaterialNeedsUpdateHash() * 23 + fabricData.subsurfaceScattering.GetHashCode(); - -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Fabric = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { FabricPasses.ShadowCaster }, - { FabricPasses.META }, - { FabricPasses.SceneSelection }, - { FabricPasses.DepthForwardOnly }, - { FabricPasses.MotionVectors }, - { FabricPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, true), - new FieldCondition(HDFields.DisableSSRTransparent, true) }}, - { FabricPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, true), - new FieldCondition(HDFields.DisableSSRTransparent, false) }}, - { FabricPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, false), - new FieldCondition(HDFields.DisableSSRTransparent, false) }}, - { FabricPasses.ForwardOnly }, - { FabricPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, - }, - }; - - public static SubShaderDescriptor FabricRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { FabricPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { FabricPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion - -#region Passes - public static class FabricPasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validPixelBlocks = FabricBlockMasks.FragmentMETA, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = FabricIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.BlendShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = FabricIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.ShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = FabricIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = FabricIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = FabricIncludes.MotionVectors, - }; - - public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPrepass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPrepass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentTransparentDepthPrepass, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPrePass, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.TransparentDepthPrepass, - keywords = CoreKeywords.HDBase, - includes = FabricIncludes.DepthOnly, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Forward, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = FabricIncludes.ForwardOnly, - }; - - public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPostpass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPostpass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentTransparentDepthPostpass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPostPass, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = FabricIncludes.DepthOnly, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingIndirect, - keywords = CoreKeywords.RaytracingIndirect, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingVisibility, - keywords = CoreKeywords.RaytracingVisiblity, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingForward, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingSubSurface = new PassDescriptor() - { - //Definition - displayName = "SubSurfaceDXR", - referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", - lightMode = "SubSurfaceDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - //Port mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FabricBlockMasks.FragmentForward, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = FabricDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingSubSurface }, - }; - } -#endregion - -#region BlockMasks - static class FabricBlockMasks - { - public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.Anisotropy, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - }; - - public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, - HDBlockFields.SurfaceDescription.DepthOffset, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.Smoothness, - }; - - public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.Anisotropy, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - } -#endregion - -#region Defines - static class FabricDefines - { - public static DefineCollection RaytracingForward = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingIndirect = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingVisibility = new DefineCollection - { - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - public static DefineCollection RaytracingGBuffer = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - public static DefineCollection RaytracingPathTracing = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - } -#endregion - -#region Includes - static class FabricIncludes - { - const string kFabric = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; - - public static IncludeCollection Common = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { kFabric, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { kFabric, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - } -#endregion +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Fabric = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { FabricPasses.ShadowCaster }, +// { FabricPasses.META }, +// { FabricPasses.SceneSelection }, +// { FabricPasses.DepthForwardOnly }, +// { FabricPasses.MotionVectors }, +// { FabricPasses.TransparentDepthPrepass, new FieldCondition[]{ +// new FieldCondition(HDFields.TransparentDepthPrePass, true), +// new FieldCondition(HDFields.DisableSSRTransparent, true) }}, +// { FabricPasses.TransparentDepthPrepass, new FieldCondition[]{ +// new FieldCondition(HDFields.TransparentDepthPrePass, true), +// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, +// { FabricPasses.TransparentDepthPrepass, new FieldCondition[]{ +// new FieldCondition(HDFields.TransparentDepthPrePass, false), +// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, +// { FabricPasses.ForwardOnly }, +// { FabricPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, +// }, +// }; + +// public static SubShaderDescriptor FabricRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { FabricPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { FabricPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion + +// #region Passes +// public static class FabricPasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validPixelBlocks = FabricBlockMasks.FragmentMETA, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = FabricIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.BlendShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = FabricIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.ShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = FabricIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = FabricIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = FabricIncludes.MotionVectors, +// }; + +// public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPrepass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPrepass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentTransparentDepthPrepass, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPrePass, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.TransparentDepthPrepass, +// keywords = CoreKeywords.HDBase, +// includes = FabricIncludes.DepthOnly, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Forward, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = FabricIncludes.ForwardOnly, +// }; + +// public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPostpass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPostpass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentTransparentDepthPostpass, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPostPass, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = FabricIncludes.DepthOnly, +// }; + +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingIndirect, +// keywords = CoreKeywords.RaytracingIndirect, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingIndirect }, +// }; + +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingVisibility, +// keywords = CoreKeywords.RaytracingVisiblity, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingVisibility }, +// }; + +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingForward, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingForward }, +// }; + +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RayTracingGBuffer }, +// }; + +// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() +// { +// //Definition +// displayName = "SubSurfaceDXR", +// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", +// lightMode = "SubSurfaceDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// //Port mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = FabricBlockMasks.FragmentForward, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = FabricDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingSubSurface }, +// }; +// } +// #endregion + +// #region BlockMasks +// static class FabricBlockMasks +// { +// public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Specular, +// HDBlockFields.SurfaceDescription.DiffusionProfileHash, +// HDBlockFields.SurfaceDescription.SubsurfaceMask, +// HDBlockFields.SurfaceDescription.Thickness, +// HDBlockFields.SurfaceDescription.Tangent, +// HDBlockFields.SurfaceDescription.Anisotropy, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// }; + +// public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, +// HDBlockFields.SurfaceDescription.DepthOffset, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// BlockFields.SurfaceDescription.Smoothness, +// }; + +// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// HDBlockFields.SurfaceDescription.BentNormal, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Specular, +// HDBlockFields.SurfaceDescription.DiffusionProfileHash, +// HDBlockFields.SurfaceDescription.SubsurfaceMask, +// HDBlockFields.SurfaceDescription.Thickness, +// HDBlockFields.SurfaceDescription.Tangent, +// HDBlockFields.SurfaceDescription.Anisotropy, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.BakedGI, +// HDBlockFields.SurfaceDescription.BakedBackGI, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; +// } +// #endregion + +// #region Defines +// static class FabricDefines +// { +// public static DefineCollection RaytracingForward = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingIndirect = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingVisibility = new DefineCollection +// { +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingGBuffer = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingPathTracing = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; +// } +// #endregion + +// #region Includes + // static class FabricIncludes + // { + // const string kFabric = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; + + // public static IncludeCollection Common = new IncludeCollection + // { + // { CoreIncludes.CorePregraph }, + // { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, + // { kFabric, IncludeLocation.Pregraph }, + // { CoreIncludes.CoreUtility }, + // { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, + // { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, + // }; + + // public static IncludeCollection Meta = new IncludeCollection + // { + // { Common }, + // { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, + // }; + + // public static IncludeCollection DepthOnly = new IncludeCollection + // { + // { Common }, + // { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, + // }; + + // public static IncludeCollection MotionVectors = new IncludeCollection + // { + // { Common }, + // { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, + // }; + + // public static IncludeCollection ForwardOnly = new IncludeCollection + // { + // { CoreIncludes.CorePregraph }, + // { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, + // { CoreIncludes.kLighting, IncludeLocation.Pregraph }, + // { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, + // { kFabric, IncludeLocation.Pregraph }, + // { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, + // { CoreIncludes.CoreUtility }, + // { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, + // { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, + // { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, + // }; + // } +// #endregion } } 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 be96222727f..842ca7c616d 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 @@ -70,7 +70,6 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) base.GetActiveBlocks(ref context); // Hair specific blocks - context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); context.AddBlock(HDBlockFields.SurfaceDescription.Transmittance); context.AddBlock(HDBlockFields.SurfaceDescription.RimTransmissionIntensity); context.AddBlock(HDBlockFields.SurfaceDescription.HairStrandDirection); @@ -87,650 +86,650 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL blockList.AddPropertyBlock(new HairAdvancedOptionsPropertyBlock(hairData)); } -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor Hair = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { HairPasses.ShadowCaster }, - { HairPasses.META }, - { HairPasses.SceneSelection }, - { HairPasses.DepthForwardOnly }, - { HairPasses.MotionVectors }, - { HairPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, - { HairPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, true), - new FieldCondition(HDFields.DisableSSRTransparent, true) }}, - { HairPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, true), - new FieldCondition(HDFields.DisableSSRTransparent, false) }}, - { HairPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, false), - new FieldCondition(HDFields.DisableSSRTransparent, false) }}, - { HairPasses.ForwardOnly }, - { HairPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, - }, - }; - - public static SubShaderDescriptor HairRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { HairPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { HairPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion - -#region Passes - public static class HairPasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validPixelBlocks = HairBlockMasks.FragmentMETA, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentShadowCaster, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.BlendShadowCaster, - pragmas = CorePragmas.DotsInstancedInV2Only, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.SceneSelection, - pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = HairRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = HairIncludes.MotionVectors, - }; - - public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPrepass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPrepass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentTransparentDepthPrepass, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPrePass, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.TransparentDepthPrepass, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor TransparentBackface = new PassDescriptor() - { - // Definition - displayName = "TransparentBackface", - referenceName = "SHADERPASS_FORWARD", - lightMode = "TransparentBackface", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentTransparentBackface, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentBackface, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = HairIncludes.ForwardOnly, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.ForwardColorMask, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = HairIncludes.ForwardOnly, - }; - - public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPostpass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPostpass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentTransparentDepthPostpass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPostPass, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = HairIncludes.DepthOnly, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingIndirect, - keywords = CoreKeywords.RaytracingIndirect, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - keywords = CoreKeywords.RaytracingVisiblity, - defines = HairDefines.RaytracingVisibility, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingForward, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingSubSurface = new PassDescriptor() - { - //Definition - displayName = "SubSurfaceDXR", - referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", - lightMode = "SubSurfaceDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = HairBlockMasks.FragmentForward, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = HairDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingSubSurface }, - }; - } -#endregion - -#region BlockMasks - static class HairBlockMasks - { - public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - }; - - public static BlockFieldDescriptor[] FragmentShadowCaster = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, - HDBlockFields.SurfaceDescription.DepthOffset, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.Smoothness, - }; - - public static BlockFieldDescriptor[] FragmentTransparentBackface = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - } -#endregion - -#region RenderStates - static class HairRenderStates - { - public static RenderStateCollection MotionVectors = new RenderStateCollection - { - { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, - Ref = CoreRenderStates.Uniforms.stencilRefMV, - Comp = "Always", - Pass = "Replace", - }) }, - }; - } -#endregion - -#region Defines - static class HairDefines - { - public static DefineCollection RaytracingForward = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingIndirect = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingVisibility = new DefineCollection - { - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - public static DefineCollection RaytracingGBuffer = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - public static DefineCollection RaytracingPathTracing = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - } -#endregion - -#region Includes - static class HairIncludes - { - public static IncludeCollection Common = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kHair, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { CoreIncludes.kHair, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - } -#endregion +// #region SubShaders +// static class SubShaders +// { +// public static SubShaderDescriptor Hair = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = true, +// passes = new PassCollection +// { +// { HairPasses.ShadowCaster }, +// { HairPasses.META }, +// { HairPasses.SceneSelection }, +// { HairPasses.DepthForwardOnly }, +// { HairPasses.MotionVectors }, +// { HairPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, +// { HairPasses.TransparentDepthPrepass, new FieldCondition[]{ +// new FieldCondition(HDFields.TransparentDepthPrePass, true), +// new FieldCondition(HDFields.DisableSSRTransparent, true) }}, +// { HairPasses.TransparentDepthPrepass, new FieldCondition[]{ +// new FieldCondition(HDFields.TransparentDepthPrePass, true), +// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, +// { HairPasses.TransparentDepthPrepass, new FieldCondition[]{ +// new FieldCondition(HDFields.TransparentDepthPrePass, false), +// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, +// { HairPasses.ForwardOnly }, +// { HairPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, +// }, +// }; + +// public static SubShaderDescriptor HairRaytracing = new SubShaderDescriptor() +// { +// pipelineTag = HDRenderPipeline.k_ShaderTagName, +// generatesPreview = false, +// passes = new PassCollection +// { +// { HairPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// { HairPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, +// }, +// }; +// } +// #endregion + +// #region Passes +// public static class HairPasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validPixelBlocks = HairBlockMasks.FragmentMETA, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentShadowCaster, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.BlendShadowCaster, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.SceneSelection, +// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = HairRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = HairIncludes.MotionVectors, +// }; + +// public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPrepass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPrepass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentTransparentDepthPrepass, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPrePass, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.TransparentDepthPrepass, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor TransparentBackface = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentBackface", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "TransparentBackface", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentTransparentBackface, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitMinimal, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentBackface, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = HairIncludes.ForwardOnly, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.ForwardColorMask, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = HairIncludes.ForwardOnly, +// }; + +// public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPostpass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPostpass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentTransparentDepthPostpass, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPostPass, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = HairIncludes.DepthOnly, +// }; + +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingIndirect, +// keywords = CoreKeywords.RaytracingIndirect, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingIndirect }, +// }; + +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// keywords = CoreKeywords.RaytracingVisiblity, +// defines = HairDefines.RaytracingVisibility, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingVisibility }, +// }; + +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingForward, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingForward }, +// }; + +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RayTracingGBuffer }, +// }; + +// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() +// { +// //Definition +// displayName = "SubSurfaceDXR", +// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", +// lightMode = "SubSurfaceDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = HairBlockMasks.FragmentForward, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = HairDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingSubSurface }, +// }; +// } +// #endregion + +// #region BlockMasks +// static class HairBlockMasks +// { +// public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// HDBlockFields.SurfaceDescription.BentNormal, +// HDBlockFields.SurfaceDescription.HairStrandDirection, +// HDBlockFields.SurfaceDescription.Transmittance, +// HDBlockFields.SurfaceDescription.RimTransmissionIntensity, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// HDBlockFields.SurfaceDescription.SpecularTint, +// HDBlockFields.SurfaceDescription.SpecularShift, +// HDBlockFields.SurfaceDescription.SecondarySpecularTint, +// HDBlockFields.SurfaceDescription.SecondarySmoothness, +// HDBlockFields.SurfaceDescription.SecondarySpecularShift, +// }; + +// public static BlockFieldDescriptor[] FragmentShadowCaster = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, +// HDBlockFields.SurfaceDescription.DepthOffset, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// BlockFields.SurfaceDescription.Smoothness, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentBackface = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// HDBlockFields.SurfaceDescription.BentNormal, +// HDBlockFields.SurfaceDescription.HairStrandDirection, +// HDBlockFields.SurfaceDescription.Transmittance, +// HDBlockFields.SurfaceDescription.RimTransmissionIntensity, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// HDBlockFields.SurfaceDescription.SpecularTint, +// HDBlockFields.SurfaceDescription.SpecularShift, +// HDBlockFields.SurfaceDescription.SecondarySpecularTint, +// HDBlockFields.SurfaceDescription.SecondarySmoothness, +// HDBlockFields.SurfaceDescription.SecondarySpecularShift, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// HDBlockFields.SurfaceDescription.BentNormal, +// HDBlockFields.SurfaceDescription.HairStrandDirection, +// HDBlockFields.SurfaceDescription.Transmittance, +// HDBlockFields.SurfaceDescription.RimTransmissionIntensity, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// HDBlockFields.SurfaceDescription.SpecularTint, +// HDBlockFields.SurfaceDescription.SpecularShift, +// HDBlockFields.SurfaceDescription.SecondarySpecularTint, +// HDBlockFields.SurfaceDescription.SecondarySmoothness, +// HDBlockFields.SurfaceDescription.SecondarySpecularShift, +// HDBlockFields.SurfaceDescription.BakedGI, +// HDBlockFields.SurfaceDescription.BakedBackGI, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; +// } +// #endregion + +// #region RenderStates +// static class HairRenderStates +// { +// public static RenderStateCollection MotionVectors = new RenderStateCollection +// { +// { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, +// Ref = CoreRenderStates.Uniforms.stencilRefMV, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; +// } +// #endregion + +// #region Defines +// static class HairDefines +// { +// public static DefineCollection RaytracingForward = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingIndirect = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingVisibility = new DefineCollection +// { +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingGBuffer = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingPathTracing = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; +// } +// #endregion + +// #region Includes +// static class HairIncludes +// { +// public static IncludeCollection Common = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kHair, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; + +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { CoreIncludes.kHair, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; +// } +// #endregion } } 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 4b9f33c0cd8..1428a697835 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 @@ -40,6 +40,7 @@ public HDLitData litData protected override string postDecalsInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; protected override FieldDescriptor subShaderField => HDFields.SubShader.Lit; + protected override string subShaderInclude => CoreIncludes.kLit; // SubShader features protected override bool supportDistortion => true; @@ -51,11 +52,10 @@ protected override SubShaderDescriptor GetSubShaderDescriptor() { var descriptor = base.GetSubShaderDescriptor(); - // TODO: move these passes in HDShaderPasses - descriptor.passes.Add(LitPasses.DepthOnly); - descriptor.passes.Add(LitPasses.GBuffer); - descriptor.passes.Add(LitPasses.Forward); - descriptor.passes.Add(LitPasses.RayTracingPrepass); + descriptor.passes.Add(HDShaderPasses.GenerateLitDepthOnly()); + descriptor.passes.Add(HDShaderPasses.GenerateGBuffer()); + descriptor.passes.Add(HDShaderPasses.GenerateLitForward()); + descriptor.passes.Add(HDShaderPasses.GenerateLitRaytracingPrepass()); return descriptor; } @@ -65,7 +65,7 @@ protected override SubShaderDescriptor GetRaytracingSubShaderDescriptor() var descriptor = base.GetRaytracingSubShaderDescriptor(); if (litData.materialType == HDLitData.MaterialType.SubsurfaceScattering) - descriptor.passes.Add(LitPasses.RaytracingSubSurface); + descriptor.passes.Add(HDShaderPasses.GenerateRaytracingSubsurface()); return descriptor; } @@ -218,834 +218,832 @@ protected override int ComputeMaterialNeedsUpdateHash() // } // #endregion -#region Passes - public static class LitPasses - { - public static PassDescriptor GBuffer = new PassDescriptor() - { - // Definition - displayName = "GBuffer", - referenceName = "SHADERPASS_GBUFFER", - lightMode = "GBuffer", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = LitRenderStates.GBuffer, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = LitKeywords.GBuffer, - includes = LitIncludes.GBuffer, - - virtualTextureFeedback = true, - }; - - // public static PassDescriptor META = new PassDescriptor() - // { - // // Definition - // displayName = "META", - // referenceName = "SHADERPASS_LIGHT_TRANSPORT", - // lightMode = "META", - // useInPreview = false, - - // // Template - // passTemplatePath = passTemplatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Port Mask - // validPixelBlocks = LitBlockMasks.FragmentMeta, - - // // Collections - // structs = CoreStructCollections.Default, - // requiredFields = CoreRequiredFields.Meta, - // fieldDependencies = CoreFieldDependencies.Default, - // renderStates = CoreRenderStates.Meta, - // pragmas = CorePragmas.DotsInstancedInV1AndV2, - // defines = CoreDefines.ShaderGraphRaytracingHigh, - // keywords = CoreKeywords.HDBase, - // includes = LitIncludes.Meta, - // }; - - // public static PassDescriptor ShadowCaster = new PassDescriptor() - // { - // // Definition - // displayName = "ShadowCaster", - // referenceName = "SHADERPASS_SHADOWS", - // lightMode = "ShadowCaster", - // useInPreview = false, - - // // Template - // passTemplatePath = passTemplatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = LitBlockMasks.FragmentShadowCaster, - - // // Collections - // structs = CoreStructCollections.Default, - // fieldDependencies = CoreFieldDependencies.Default, - // renderStates = CoreRenderStates.BlendShadowCaster, - // pragmas = CorePragmas.DotsInstancedInV1AndV2, - // defines = CoreDefines.ShaderGraphRaytracingHigh, - // keywords = CoreKeywords.HDBase, - // includes = LitIncludes.DepthOnly, - // }; - - // public static PassDescriptor SceneSelection = new PassDescriptor() - // { - // // Definition - // displayName = "SceneSelectionPass", - // referenceName = "SHADERPASS_DEPTH_ONLY", - // lightMode = "SceneSelectionPass", - // useInPreview = false, - - // // Template - // passTemplatePath = passTemplatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = LitBlockMasks.FragmentSceneSelection, - - // // Collections - // structs = CoreStructCollections.Default, - // fieldDependencies = CoreFieldDependencies.Default, - // renderStates = CoreRenderStates.SceneSelection, - // pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, - // defines = CoreDefines.SceneSelection, - // keywords = CoreKeywords.HDBase, - // includes = LitIncludes.DepthOnly, - // }; - - public static PassDescriptor DepthOnly = new PassDescriptor() - { - // Definition - displayName = "DepthOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = LitKeywords.DepthMotionVectors, - includes = LitIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.MotionVectors, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = LitKeywords.DepthMotionVectors, - includes = LitIncludes.MotionVectors, - }; - - public static PassDescriptor DistortionVectors = new PassDescriptor() - { - // Definition - displayName = "DistortionVectors", - referenceName = "SHADERPASS_DISTORTION", - lightMode = "DistortionVectors", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDistortion, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = LitRenderStates.Distortion, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.Distortion, - }; - - public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPrepass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPrepass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentTransparentDepthPrepass, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPrePass, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.TransparentDepthPrepass, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.DepthOnly, - }; - - public static PassDescriptor TransparentBackface = new PassDescriptor() - { - // Definition - displayName = "TransparentBackface", - referenceName = "SHADERPASS_FORWARD", - lightMode = "TransparentBackface", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentTransparentBackface, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentBackface, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = LitIncludes.Forward, - }; - - public static PassDescriptor Forward = new PassDescriptor() - { - // Definition - displayName = "Forward", - referenceName = "SHADERPASS_FORWARD", - lightMode = "Forward", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.ForwardColorMask, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = LitIncludes.Forward, - - virtualTextureFeedback = true, - }; - - public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPostpass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPostpass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentTransparentDepthPostpass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPostPass, - pragmas = CorePragmas.DotsInstancedInV1AndV2, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.DepthOnly, - }; - - public static PassDescriptor RayTracingPrepass = new PassDescriptor() - { - // Definition - displayName = "RayTracingPrepass", - referenceName = "SHADERPASS_CONSTANT", - lightMode = "RayTracingPrepass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentRayTracingPrepass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = LitRenderStates.RayTracingPrepass, - pragmas = LitPragmas.RaytracingBasic, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = LitIncludes.RayTracingPrepass, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingIndirect, - keywords = CoreKeywords.RaytracingIndirect, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingVisibility, - includes = CoreIncludes.Raytracing, - keywords = CoreKeywords.RaytracingVisiblity, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingForward, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDefault, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingPathTracing = new PassDescriptor() - { - //Definition - displayName = "PathTracingDXR", - referenceName = "SHADERPASS_PATH_TRACING", - lightMode = "PathTracingDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - //Port mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDefault, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingPathTracing, - keywords = CoreKeywords.HDBaseNoCrossFade, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingPathTracing }, - }; - - public static PassDescriptor RaytracingSubSurface = new PassDescriptor() - { - //Definition - displayName = "SubSurfaceDXR", - referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", - lightMode = "SubSurfaceDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - //Port mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = LitBlockMasks.FragmentDefault, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = LitDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingSubSurface }, - }; - } -#endregion +// #region Passes +// public static class LitPasses +// { +// public static PassDescriptor GBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBuffer", +// referenceName = "SHADERPASS_GBUFFER", +// lightMode = "GBuffer", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitMinimal, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = LitRenderStates.GBuffer, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = LitKeywords.GBuffer, +// includes = LitIncludes.GBuffer, + +// virtualTextureFeedback = true, +// }; -#region BlockMasks - static class LitBlockMasks - { - public static BlockFieldDescriptor[] FragmentDefault = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.CoatMask, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.RefractionIndex, - HDBlockFields.SurfaceDescription.RefractionColor, - HDBlockFields.SurfaceDescription.RefractionDistance, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentMeta = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.CoatMask, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.RefractionIndex, - HDBlockFields.SurfaceDescription.RefractionColor, - HDBlockFields.SurfaceDescription.RefractionDistance, - }; - - public static BlockFieldDescriptor[] FragmentShadowCaster = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, - HDBlockFields.SurfaceDescription.DepthOffset, - }; +// // public static PassDescriptor META = new PassDescriptor() +// // { +// // // Definition +// // displayName = "META", +// // referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// // lightMode = "META", +// // useInPreview = false, + +// // // Template +// // passTemplatePath = passTemplatePath, +// // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // // Port Mask +// // validPixelBlocks = LitBlockMasks.FragmentMeta, + +// // // Collections +// // structs = CoreStructCollections.Default, +// // requiredFields = CoreRequiredFields.Meta, +// // fieldDependencies = CoreFieldDependencies.Default, +// // renderStates = CoreRenderStates.Meta, +// // pragmas = CorePragmas.DotsInstancedInV1AndV2, +// // defines = CoreDefines.ShaderGraphRaytracingHigh, +// // keywords = CoreKeywords.HDBase, +// // includes = LitIncludes.Meta, +// // }; + +// // public static PassDescriptor ShadowCaster = new PassDescriptor() +// // { +// // // Definition +// // displayName = "ShadowCaster", +// // referenceName = "SHADERPASS_SHADOWS", +// // lightMode = "ShadowCaster", +// // useInPreview = false, + +// // // Template +// // passTemplatePath = passTemplatePath, +// // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // // Port Mask +// // validVertexBlocks = CoreBlockMasks.Vertex, +// // validPixelBlocks = LitBlockMasks.FragmentShadowCaster, + +// // // Collections +// // structs = CoreStructCollections.Default, +// // fieldDependencies = CoreFieldDependencies.Default, +// // renderStates = CoreRenderStates.BlendShadowCaster, +// // pragmas = CorePragmas.DotsInstancedInV1AndV2, +// // defines = CoreDefines.ShaderGraphRaytracingHigh, +// // keywords = CoreKeywords.HDBase, +// // includes = LitIncludes.DepthOnly, +// // }; + +// // public static PassDescriptor SceneSelection = new PassDescriptor() +// // { +// // // Definition +// // displayName = "SceneSelectionPass", +// // referenceName = "SHADERPASS_DEPTH_ONLY", +// // lightMode = "SceneSelectionPass", +// // useInPreview = false, + +// // // Template +// // passTemplatePath = passTemplatePath, +// // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // // Port Mask +// // validVertexBlocks = CoreBlockMasks.Vertex, +// // validPixelBlocks = LitBlockMasks.FragmentSceneSelection, + +// // // Collections +// // structs = CoreStructCollections.Default, +// // fieldDependencies = CoreFieldDependencies.Default, +// // renderStates = CoreRenderStates.SceneSelection, +// // pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, +// // defines = CoreDefines.SceneSelection, +// // keywords = CoreKeywords.HDBase, +// // includes = LitIncludes.DepthOnly, +// // }; + +// public static PassDescriptor DepthOnly = new PassDescriptor() +// { +// // Definition +// displayName = "DepthOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = LitKeywords.DepthMotionVectors, +// includes = LitIncludes.DepthOnly, +// }; - public static BlockFieldDescriptor[] FragmentSceneSelection = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.MotionVectors, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = LitKeywords.DepthMotionVectors, +// includes = LitIncludes.MotionVectors, +// }; - public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Distortion, - HDBlockFields.SurfaceDescription.DistortionBlur, - }; +// public static PassDescriptor DistortionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "DistortionVectors", +// referenceName = "SHADERPASS_DISTORTION", +// lightMode = "DistortionVectors", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentDistortion, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = LitRenderStates.Distortion, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = LitIncludes.Distortion, +// }; - public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, - HDBlockFields.SurfaceDescription.DepthOffset, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.Smoothness, - }; - - public static BlockFieldDescriptor[] FragmentTransparentBackface = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.CoatMask, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.RefractionIndex, - HDBlockFields.SurfaceDescription.RefractionColor, - HDBlockFields.SurfaceDescription.RefractionDistance, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, - HDBlockFields.SurfaceDescription.DepthOffset, - }; +// public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPrepass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPrepass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentTransparentDepthPrepass, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPrePass, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.TransparentDepthPrepass, +// keywords = CoreKeywords.HDBase, +// includes = LitIncludes.DepthOnly, +// }; - public static BlockFieldDescriptor[] FragmentRayTracingPrepass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - } -#endregion +// public static PassDescriptor TransparentBackface = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentBackface", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "TransparentBackface", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentTransparentBackface, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentBackface, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = LitIncludes.Forward, +// }; -#region RenderStates - static class LitRenderStates - { - public static RenderStateCollection GBuffer = new RenderStateCollection - { - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZTest(CoreRenderStates.Uniforms.zTestGBuffer) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskGBuffer, - Ref = CoreRenderStates.Uniforms.stencilRefGBuffer, - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection Distortion = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, - { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, - { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, - { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, - { RenderState.ZWrite(ZWrite.Off) }, - { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, - { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, - Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, - Comp = "Always", - Pass = "Replace", - }) }, - }; - - public static RenderStateCollection RayTracingPrepass = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.Zero) }, - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.On) }, - // Note: we use default ZTest LEqual so if the object have already been render in depth prepass, it will re-render to tag stencil - }; - } -#endregion +// public static PassDescriptor Forward = new PassDescriptor() +// { +// // Definition +// displayName = "Forward", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "Forward", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitMinimal, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.ForwardColorMask, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = LitIncludes.Forward, + +// virtualTextureFeedback = true, +// }; -#region Pragmas - static class LitPragmas - { - public static PragmaCollection RaytracingBasic = new PragmaCollection - { - { Pragma.Target(ShaderModel.Target45) }, - { Pragma.Vertex("Vert") }, - { Pragma.Fragment("Frag") }, - { Pragma.OnlyRenderers(new Platform[] {Platform.D3D11}) }, - }; - } -#endregion +// public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPostpass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPostpass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentTransparentDepthPostpass, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPostPass, +// pragmas = CorePragmas.DotsInstancedInV1AndV2, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = LitIncludes.DepthOnly, +// }; -#region Defines - static class LitDefines - { - public static DefineCollection RaytracingForward = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; +// public static PassDescriptor RayTracingPrepass = new PassDescriptor() +// { +// // Definition +// displayName = "RayTracingPrepass", +// referenceName = "SHADERPASS_CONSTANT", +// lightMode = "RayTracingPrepass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentRayTracingPrepass, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = LitRenderStates.RayTracingPrepass, +// pragmas = LitPragmas.RaytracingBasic, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = LitIncludes.RayTracingPrepass, +// }; - public static DefineCollection RaytracingIndirect = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingIndirect, +// keywords = CoreKeywords.RaytracingIndirect, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingIndirect }, +// }; - public static DefineCollection RaytracingGBuffer = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingVisibility, +// includes = CoreIncludes.Raytracing, +// keywords = CoreKeywords.RaytracingVisiblity, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingVisibility }, +// }; - public static DefineCollection RaytracingVisibility = new DefineCollection - { - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingForward, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingForward }, +// }; - public static DefineCollection RaytracingPathTracing = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - } -#endregion +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentDefault, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RayTracingGBuffer }, +// }; -#region Keywords - static class LitKeywords - { - public static KeywordCollection GBuffer = new KeywordCollection - { - { CoreKeywords.HDBase }, - { CoreKeywordDescriptors.DebugDisplay }, - { CoreKeywords.Lightmaps }, - { CoreKeywordDescriptors.ShadowsShadowmask }, - { CoreKeywordDescriptors.LightLayers }, - { CoreKeywordDescriptors.Decals }, - }; - - public static KeywordCollection DepthMotionVectors = new KeywordCollection - { - { CoreKeywords.HDBase }, - { CoreKeywordDescriptors.WriteMsaaDepth }, - { CoreKeywordDescriptors.WriteNormalBuffer }, - { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, - }; - } -#endregion +// public static PassDescriptor RaytracingPathTracing = new PassDescriptor() +// { +// //Definition +// displayName = "PathTracingDXR", +// referenceName = "SHADERPASS_PATH_TRACING", +// lightMode = "PathTracingDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// //Port mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentDefault, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingPathTracing, +// keywords = CoreKeywords.HDBaseNoCrossFade, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingPathTracing }, +// }; - protected override string subShaderInclude => CoreIncludes.kLit; +// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() +// { +// //Definition +// displayName = "SubSurfaceDXR", +// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", +// lightMode = "SubSurfaceDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// //Port mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = LitBlockMasks.FragmentDefault, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = LitDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingSubSurface }, +// }; +// } +// #endregion -#region Includes - static class LitIncludes - { - const string kLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; - const string kPassGBuffer = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"; - const string kPassConstant = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassConstant.hlsl"; +// #region BlockMasks +// static class LitBlockMasks +// { +// public static BlockFieldDescriptor[] FragmentDefault = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// HDBlockFields.SurfaceDescription.BentNormal, +// HDBlockFields.SurfaceDescription.Tangent, +// HDBlockFields.SurfaceDescription.SubsurfaceMask, +// HDBlockFields.SurfaceDescription.Thickness, +// HDBlockFields.SurfaceDescription.DiffusionProfileHash, +// HDBlockFields.SurfaceDescription.IridescenceMask, +// HDBlockFields.SurfaceDescription.IridescenceThickness, +// BlockFields.SurfaceDescription.Specular, +// HDBlockFields.SurfaceDescription.CoatMask, +// BlockFields.SurfaceDescription.Metallic, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.Anisotropy, +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// HDBlockFields.SurfaceDescription.RefractionIndex, +// HDBlockFields.SurfaceDescription.RefractionColor, +// HDBlockFields.SurfaceDescription.RefractionDistance, +// HDBlockFields.SurfaceDescription.BakedGI, +// HDBlockFields.SurfaceDescription.BakedBackGI, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentMeta = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// HDBlockFields.SurfaceDescription.BentNormal, +// HDBlockFields.SurfaceDescription.Tangent, +// HDBlockFields.SurfaceDescription.SubsurfaceMask, +// HDBlockFields.SurfaceDescription.Thickness, +// HDBlockFields.SurfaceDescription.DiffusionProfileHash, +// HDBlockFields.SurfaceDescription.IridescenceMask, +// HDBlockFields.SurfaceDescription.IridescenceThickness, +// BlockFields.SurfaceDescription.Specular, +// HDBlockFields.SurfaceDescription.CoatMask, +// BlockFields.SurfaceDescription.Metallic, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.Anisotropy, +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// HDBlockFields.SurfaceDescription.RefractionIndex, +// HDBlockFields.SurfaceDescription.RefractionColor, +// HDBlockFields.SurfaceDescription.RefractionDistance, +// }; + +// public static BlockFieldDescriptor[] FragmentShadowCaster = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentSceneSelection = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.Distortion, +// HDBlockFields.SurfaceDescription.DistortionBlur, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, +// HDBlockFields.SurfaceDescription.DepthOffset, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// BlockFields.SurfaceDescription.Smoothness, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentBackface = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// HDBlockFields.SurfaceDescription.BentNormal, +// HDBlockFields.SurfaceDescription.Tangent, +// HDBlockFields.SurfaceDescription.SubsurfaceMask, +// HDBlockFields.SurfaceDescription.Thickness, +// HDBlockFields.SurfaceDescription.DiffusionProfileHash, +// HDBlockFields.SurfaceDescription.IridescenceMask, +// HDBlockFields.SurfaceDescription.IridescenceThickness, +// BlockFields.SurfaceDescription.Specular, +// HDBlockFields.SurfaceDescription.CoatMask, +// BlockFields.SurfaceDescription.Metallic, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Smoothness, +// BlockFields.SurfaceDescription.Occlusion, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.Anisotropy, +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// HDBlockFields.SurfaceDescription.RefractionIndex, +// HDBlockFields.SurfaceDescription.RefractionColor, +// HDBlockFields.SurfaceDescription.RefractionDistance, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentRayTracingPrepass = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; +// } +// #endregion + +// #region RenderStates +// static class LitRenderStates +// { +// public static RenderStateCollection GBuffer = new RenderStateCollection +// { +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZTest(CoreRenderStates.Uniforms.zTestGBuffer) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskGBuffer, +// Ref = CoreRenderStates.Uniforms.stencilRefGBuffer, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection Distortion = new RenderStateCollection +// { +// { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, +// { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, +// { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, +// { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, +// { RenderState.ZWrite(ZWrite.Off) }, +// { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, +// { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, +// Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; + +// public static RenderStateCollection RayTracingPrepass = new RenderStateCollection +// { +// { RenderState.Blend(Blend.One, Blend.Zero) }, +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.On) }, +// // Note: we use default ZTest LEqual so if the object have already been render in depth prepass, it will re-render to tag stencil +// }; +// } +// #endregion + +// #region Pragmas +// static class LitPragmas +// { +// public static PragmaCollection RaytracingBasic = new PragmaCollection +// { +// { Pragma.Target(ShaderModel.Target45) }, +// { Pragma.Vertex("Vert") }, +// { Pragma.Fragment("Frag") }, +// { Pragma.OnlyRenderers(new Platform[] {Platform.D3D11}) }, +// }; +// } +// #endregion + +// #region Defines +// static class LitDefines +// { +// public static DefineCollection RaytracingForward = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingIndirect = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingGBuffer = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingVisibility = new DefineCollection +// { +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingPathTracing = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; +// } +// #endregion + +// #region Keywords +// static class LitKeywords +// { +// public static KeywordCollection GBuffer = new KeywordCollection +// { +// { CoreKeywords.HDBase }, +// { CoreKeywordDescriptors.DebugDisplay }, +// { CoreKeywords.Lightmaps }, +// { CoreKeywordDescriptors.ShadowsShadowmask }, +// { CoreKeywordDescriptors.LightLayers }, +// { CoreKeywordDescriptors.Decals }, +// }; + +// public static KeywordCollection DepthMotionVectors = new KeywordCollection +// { +// { CoreKeywords.HDBase }, +// { CoreKeywordDescriptors.WriteMsaaDepth }, +// { CoreKeywordDescriptors.WriteNormalBuffer }, +// { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, +// }; +// } +// #endregion + +// #region Includes +// static class LitIncludes +// { +// const string kLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; +// const string kPassGBuffer = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"; +// const string kPassConstant = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassConstant.hlsl"; - public static IncludeCollection Common = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { kLitDecalData, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection GBuffer = new IncludeCollection - { - { Common }, - { kPassGBuffer, IncludeLocation.Postgraph }, - }; +// public static IncludeCollection Common = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { kLitDecalData, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; +// public static IncludeCollection GBuffer = new IncludeCollection +// { +// { Common }, +// { kPassGBuffer, IncludeLocation.Postgraph }, +// }; - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; - public static IncludeCollection RayTracingPrepass = new IncludeCollection - { - { Common }, - { kPassConstant, IncludeLocation.Postgraph }, - }; +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; +// public static IncludeCollection RayTracingPrepass = new IncludeCollection +// { +// { Common }, +// { kPassConstant, IncludeLocation.Postgraph }, +// }; - public static IncludeCollection Forward = new IncludeCollection - { - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { CoreIncludes.kLit, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { kLitDecalData, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection Distortion = new IncludeCollection - { - { Common }, - { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, - }; - } -#endregion +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection Forward = new IncludeCollection +// { +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { CoreIncludes.kLit, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { kLitDecalData, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection Distortion = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, +// }; +// } +// #endregion } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index c3321277ffa..5d3496c9c83 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -27,8 +27,8 @@ public static PassDescriptor GenerateDistortionPass(bool supportLighting) sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, // Port mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FragmentDistortion, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = FragmentDistortion, // Collections structs = CoreStructCollections.Default, @@ -105,8 +105,8 @@ public static PassDescriptor GenerateSceneSelection(bool supportLighting) useInPreview = false, // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FragmentSceneSelection, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = FragmentSceneSelection, // Collections structs = CoreStructCollections.Default, @@ -161,8 +161,8 @@ static public PassDescriptor GenerateShadowCaster(bool supportLighting) useInPreview = false, // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FragmentShadowCaster, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = FragmentShadowCaster, // Collections structs = CoreStructCollections.Default, @@ -305,8 +305,8 @@ public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting) useInPreview = true, // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FragmentDepthOnlyVectors, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = FragmentDepthOnlyVectors, // Collections structs = CoreStructCollections.Default, @@ -383,8 +383,8 @@ public static PassDescriptor GenerateMotionVectors(bool supportLighting) useInPreview = false, // Block Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FragmentMotionVectors, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = FragmentMotionVectors, // Collections structs = CoreStructCollections.Default, @@ -472,8 +472,8 @@ public static PassDescriptor GenereateForwardOnlyPass(bool supportLighting) useInPreview = true, // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FragmentForwardOnly, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = FragmentForwardOnly, // Collections structs = CoreStructCollections.Default, @@ -569,8 +569,8 @@ public static PassDescriptor GenerateBackThenFront(bool supportLighting) useInPreview = true, // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FragmentBackThenFront, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = FragmentBackThenFront, // Collections structs = CoreStructCollections.Default, @@ -672,8 +672,8 @@ public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLightin useInPreview = true, // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FragmentTransparentDepthPrepass, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = FragmentTransparentDepthPrepass, // Collections structs = CoreStructCollections.Default, @@ -785,8 +785,8 @@ public static PassDescriptor GenerateTransparentDepthPostpass(bool supportLighti useInPreview = true, // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = FragmentTransparentDepthPostpass, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = FragmentTransparentDepthPostpass, // Collections structs = CoreStructCollections.Default, @@ -841,6 +841,242 @@ RenderStateCollection GenerateRenderState() #endregion +#region Lit DepthOnly + + public static PassDescriptor GenerateLitDepthOnly() + { + return new PassDescriptor + { + displayName = "DepthOnly", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "DepthOnly", + useInPreview = true, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentDepthMotionVectors, + + // Collections + structs = CoreStructCollections.Default, + requiredFields = CoreRequiredFields.LitFull, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = CoreRenderStates.DepthOnly, + pragmas = CorePragmas.DotsInstancedInV1AndV2, + defines = CoreDefines.ShaderGraphRaytracingHigh, + keywords = LitDepthOnlyKeywords, + includes = DepthOnlyIncludes, + }; + } + + public static IncludeCollection DepthOnlyIncludes = new IncludeCollection + { + { CoreIncludes.CorePregraph }, + { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, + { CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph }, + { CoreIncludes.CoreUtility }, + { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, + { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, + { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, + { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, + }; + + public static KeywordCollection LitDepthOnlyKeywords = new KeywordCollection + { + { CoreKeywords.HDBase }, + { CoreKeywordDescriptors.WriteMsaaDepth }, + { CoreKeywordDescriptors.WriteNormalBuffer }, + { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, + }; + +#endregion + +#region GBuffer + + public static PassDescriptor GenerateGBuffer() + { + return new PassDescriptor + { + // Definition + displayName = "GBuffer", + referenceName = "SHADERPASS_GBUFFER", + lightMode = "GBuffer", + useInPreview = true, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentDefault, + + // Collections + structs = CoreStructCollections.Default, + requiredFields = CoreRequiredFields.LitMinimal, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = GBufferRenderState, + pragmas = CorePragmas.DotsInstancedInV1AndV2, + defines = CoreDefines.ShaderGraphRaytracingHigh, + keywords = GBufferKeywords, + includes = GBufferIncludes, + + virtualTextureFeedback = true, + }; + } + + public static KeywordCollection GBufferKeywords = new KeywordCollection + { + { CoreKeywords.HDBase }, + { CoreKeywordDescriptors.DebugDisplay }, + { CoreKeywords.Lightmaps }, + { CoreKeywordDescriptors.ShadowsShadowmask }, + { CoreKeywordDescriptors.LightLayers }, + { CoreKeywordDescriptors.Decals }, + }; + + public static IncludeCollection GBufferIncludes = new IncludeCollection + { + { CoreIncludes.CorePregraph }, + { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, + { CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph }, + { CoreIncludes.CoreUtility }, + { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, + { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, + { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, + { CoreIncludes.kPassGBuffer, IncludeLocation.Postgraph }, + }; + + public static RenderStateCollection GBufferRenderState = new RenderStateCollection + { + { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, + { RenderState.ZTest(CoreRenderStates.Uniforms.zTestGBuffer) }, + { RenderState.Stencil(new StencilDescriptor() + { + WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskGBuffer, + Ref = CoreRenderStates.Uniforms.stencilRefGBuffer, + Comp = "Always", + Pass = "Replace", + }) }, + }; + +#endregion + +#region Lit Forward + + public static PassDescriptor GenerateLitForward() + { + return new PassDescriptor + { + // Definition + displayName = "Forward", + referenceName = "SHADERPASS_FORWARD", + lightMode = "Forward", + useInPreview = true, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentDefault, + + // Collections + structs = CoreStructCollections.Default, + requiredFields = CoreRequiredFields.LitMinimal, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = CoreRenderStates.ForwardColorMask, + pragmas = CorePragmas.DotsInstancedInV1AndV2, + defines = CoreDefines.Forward, + keywords = CoreKeywords.Forward, + includes = ForwardIncludes, + + virtualTextureFeedback = true, + }; + } + + public static IncludeCollection ForwardIncludes = new IncludeCollection + { + { CoreIncludes.CorePregraph }, + { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, + { CoreIncludes.kLighting, IncludeLocation.Pregraph }, + { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, + { CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph }, + { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, + { CoreIncludes.CoreUtility }, + { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, + { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, + { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, + { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, + }; + +#endregion + +#region Lit Raytracing Prepass + + public static PassDescriptor GenerateLitRaytracingPrepass() + { + return new PassDescriptor + { + // Definition + displayName = "RayTracingPrepass", + referenceName = "SHADERPASS_CONSTANT", + lightMode = "RayTracingPrepass", + useInPreview = false, + + // // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // // Port Mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentRayTracingPrepass, + + // Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + renderStates = RayTracingPrepassRenderState, + pragmas = LitRaytracingPrepassPragmas, + defines = CoreDefines.ShaderGraphRaytracingHigh, + keywords = CoreKeywords.HDBase, + includes = RayTracingPrepassIncludes, + }; + } + + public static PragmaCollection LitRaytracingPrepassPragmas = new PragmaCollection + { + { Pragma.Target(ShaderModel.Target45) }, + { Pragma.Vertex("Vert") }, + { Pragma.Fragment("Frag") }, + { Pragma.OnlyRenderers(new Platform[] {Platform.D3D11}) }, + }; + + public static IncludeCollection RayTracingPrepassIncludes = new IncludeCollection + { + { CoreIncludes.CorePregraph }, + { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, + { CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph }, + { CoreIncludes.CoreUtility }, + { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, + { CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph }, + { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, + { CoreIncludes.kPassConstant, IncludeLocation.Postgraph }, + }; + + public static RenderStateCollection RayTracingPrepassRenderState = new RenderStateCollection + { + { RenderState.Blend(Blend.One, Blend.Zero) }, + { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, + { RenderState.ZWrite(ZWrite.On) }, + // Note: we use default ZTest LEqual so if the object have already been render in depth prepass, it will re-render to tag stencil + }; + +#endregion + #region Raytracing Indirect public static PassDescriptor GenerateRaytracingIndirect(bool supportLighting) @@ -854,8 +1090,8 @@ public static PassDescriptor GenerateRaytracingIndirect(bool supportLighting) useInPreview = false, // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = RaytracingIndirectFragment, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = RaytracingIndirectFragment, // Collections structs = CoreStructCollections.Default, @@ -935,8 +1171,8 @@ public static PassDescriptor GenerateRaytracingVisibility(bool supportLighting) useInPreview = false, // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = RaytracingVisibilityFragment, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = RaytracingVisibilityFragment, // Collections structs = CoreStructCollections.Default, @@ -1012,8 +1248,8 @@ public static PassDescriptor GenerateRaytracingForward(bool supportLighting) useInPreview = false, // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = RaytracingForwardFragment, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = RaytracingForwardFragment, // Collections structs = CoreStructCollections.Default, @@ -1090,8 +1326,8 @@ public static PassDescriptor GenerateRaytracingGBuffer(bool supportLighting) useInPreview = false, // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = RaytracingGBufferFragment, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = RaytracingGBufferFragment, // Collections structs = CoreStructCollections.Default, @@ -1167,8 +1403,8 @@ public static PassDescriptor GeneratePathTracing(bool supportLighting) useInPreview = false, //Port mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = PathTracingFragment, + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = PathTracingFragment, //Collections structs = CoreStructCollections.Default, @@ -1221,6 +1457,45 @@ public static PassDescriptor GeneratePathTracing(bool supportLighting) HDBlockFields.SurfaceDescription.DepthOffset, }; +#endregion + +#region Raytracing Subsurface + + public static PassDescriptor GenerateRaytracingSubsurface() + { + return new PassDescriptor + { + //Definition + displayName = "SubSurfaceDXR", + referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", + lightMode = "SubSurfaceDXR", + useInPreview = false, + + // Template + // passTemplatePath = passTemplatePath, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + + // //Port mask + // validVertexBlocks = CoreBlockMasks.Vertex, + // validPixelBlocks = LitBlockMasks.FragmentDefault, + + //Collections + structs = CoreStructCollections.Default, + fieldDependencies = CoreFieldDependencies.Default, + pragmas = CorePragmas.RaytracingBasic, + defines = RaytracingSubsurfaceDefines, + keywords = CoreKeywords.RaytracingGBufferForward, + includes = CoreIncludes.Raytracing, + requiredFields = new FieldCollection(){ HDFields.ShaderPass.RaytracingSubSurface }, + }; + } + + public static DefineCollection RaytracingSubsurfaceDefines = new DefineCollection + { + { CoreKeywordDescriptors.Shadow, 0 }, + { RayTracingNode.GetRayTracingKeyword(), 1 }, + }; + #endregion } 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 3eac5b7bcd9..1dce71f01f5 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 @@ -124,7 +124,6 @@ PassCollection GetPasses() passes.Add(HDShaderPasses.GenerateRaytracingVisibility(supportLighting)); passes.Add(HDShaderPasses.GenerateRaytracingForward(supportLighting)); passes.Add(HDShaderPasses.GenerateRaytracingGBuffer(supportLighting)); - passes.Add(HDShaderPasses.GenerateRaytracingGBuffer(supportLighting)); }; if (supportPathtracing) @@ -150,7 +149,6 @@ SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor IncludeCollection finalIncludes = new IncludeCollection(); var includeList = passDescriptor.includes.Select(i => i.descriptor).ToList(); - // Replace include placeholders if necessary: foreach (var include in passDescriptor.includes) { @@ -162,14 +160,28 @@ SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor if (!String.IsNullOrEmpty(include.descriptor.value)) finalIncludes.Add(include.descriptor.value, include.descriptor.location, include.fieldConditions); } + passDescriptor.includes = finalIncludes; + + // Replace valid pixel blocks by automatic thing so we don't have to write them + // if (passDescriptor.displayName != "ForwardOnly") + { + var tmpCtx = new TargetActiveBlockContext(new List(), passDescriptor); + GetActiveBlocks(ref tmpCtx); + passDescriptor.validPixelBlocks = tmpCtx.activeBlocks.Where(b => b.shaderStage == ShaderStage.Fragment).ToArray(); + passDescriptor.validVertexBlocks = tmpCtx.activeBlocks.Where(b => b.shaderStage == ShaderStage.Vertex).ToArray(); + } + + // Set default values for HDRP "surface" passes: + if (passDescriptor.structs == null) + passDescriptor.structs = CoreStructCollections.Default; + if (passDescriptor.fieldDependencies == null) + passDescriptor.fieldDependencies = CoreFieldDependencies.Default; + // Add the subShader to enable fields that depends on it if (passDescriptor.requiredFields == null) passDescriptor.requiredFields = new FieldCollection(); - passDescriptor.requiredFields.Add(subShaderField); - passDescriptor.includes = finalIncludes; - finalPasses.Add(passDescriptor, passes[i].fieldConditions); } @@ -248,9 +260,15 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) 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); + context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, + systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPrepass + && (context.pass != null && context.pass.Value.lightMode == "TransparentDepthPrepass")); + context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, + systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.alphaTestDepthPostpass + && (context.pass != null && context.pass.Value.lightMode == "TransparentDepthPostpass")); + context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, + systemData.alphaTest && builtinData.alphaTestShadow + && (context.pass != null && context.pass.Value.lightMode == "ShadowCaster")); // Misc context.AddBlock(HDBlockFields.SurfaceDescription.DepthOffset, builtinData.depthOffset); 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 69285d35309..bfffb8d141e 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 @@ -28,6 +28,8 @@ sealed partial class StackLitSubTarget : LightingSubTarget, ILegacyTarget, IRequ protected override string subTargetAssetGuid => "5f7ba34a143e67647b202a662748dae3"; // StackLitSubTarget.cs protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_StackLit; protected override FieldDescriptor subShaderField => HDFields.SubShader.StackLit; + protected override string postDecalsInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLitDecalData.hlsl"; + protected override string subShaderInclude => CoreIncludes.kStackLit; protected override bool supportDistortion => true; protected override bool requireSplitLighting => stackLitData.subsurfaceScattering; @@ -46,13 +48,23 @@ public StackLitData stackLitData set => m_StackLitData = value; } - // TODO stacklit share pass - protected override IEnumerable EnumerateSubShaders() + protected override SubShaderDescriptor GetRaytracingSubShaderDescriptor() { - yield return SubShaders.StackLit; - yield return SubShaders.StackLitRaytracing; + var descriptor = base.GetRaytracingSubShaderDescriptor(); + + if (stackLitData.subsurfaceScattering) + descriptor.passes.Add(HDShaderPasses.GenerateRaytracingSubsurface()); + + return descriptor; } + // TODO stacklit share pass + // protected override IEnumerable EnumerateSubShaders() + // { + // yield return SubShaders.StackLit; + // yield return SubShaders.StackLitRaytracing; + // } + // Reference for GetFields // ------------------------------------------- // @@ -292,10 +304,7 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) base.GetActiveBlocks(ref context); // Common - context.AddBlock(HDBlockFields.SurfaceDescription.BentNormal); context.AddBlock(HDBlockFields.SurfaceDescription.Tangent); - context.AddBlock(BlockFields.SurfaceDescription.Smoothness); - context.AddBlock(BlockFields.SurfaceDescription.Occlusion); context.AddBlock(HDBlockFields.SurfaceDescription.Anisotropy, stackLitData.anisotropy); context.AddBlock(HDBlockFields.SurfaceDescription.SubsurfaceMask, stackLitData.subsurfaceScattering); context.AddBlock(HDBlockFields.SurfaceDescription.Thickness, stackLitData.transmission); @@ -430,739 +439,738 @@ public static bool SpecularOcclusionConeFixupMethodModifiesRoughness(StackLitDat protected override int ComputeMaterialNeedsUpdateHash() => base.ComputeMaterialNeedsUpdateHash() * 23 + stackLitData.subsurfaceScattering.GetHashCode(); -#region SubShaders - static class SubShaders - { - public static SubShaderDescriptor StackLit = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = true, - passes = new PassCollection - { - { StackLitPasses.ShadowCaster }, - { StackLitPasses.META }, - { StackLitPasses.SceneSelection }, - { StackLitPasses.DepthForwardOnly }, - { StackLitPasses.MotionVectors }, - { StackLitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, - { StackLitPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, true), - new FieldCondition(HDFields.DisableSSRTransparent, true) }}, - { StackLitPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, true), - new FieldCondition(HDFields.DisableSSRTransparent, false) }}, - { StackLitPasses.TransparentDepthPrepass, new FieldCondition[]{ - new FieldCondition(HDFields.TransparentDepthPrePass, false), - new FieldCondition(HDFields.DisableSSRTransparent, false) }}, - { StackLitPasses.ForwardOnly }, - { StackLitPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, - }, - }; - - public static SubShaderDescriptor StackLitRaytracing = new SubShaderDescriptor() - { - pipelineTag = HDRenderPipeline.k_ShaderTagName, - generatesPreview = false, - passes = new PassCollection - { - { StackLitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, - { StackLitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, - { StackLitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, - { StackLitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, - { StackLitPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, - }, - }; - } -#endregion - -#region Passes - public static class StackLitPasses - { - public static PassDescriptor META = new PassDescriptor() - { - // Definition - displayName = "META", - referenceName = "SHADERPASS_LIGHT_TRANSPORT", - lightMode = "META", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validPixelBlocks = StackLitBlockMasks.FragmentMETA, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Meta, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - keywords = CoreKeywords.HDBase, - includes = StackLitIncludes.Meta, - }; - - public static PassDescriptor ShadowCaster = new PassDescriptor() - { - // Definition - displayName = "ShadowCaster", - referenceName = "SHADERPASS_SHADOWS", - lightMode = "ShadowCaster", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = StackLitBlockMasks.VertexPosition, - validPixelBlocks = StackLitBlockMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = StackLitRenderStates.ShadowCaster, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - keywords = CoreKeywords.HDBase, - includes = StackLitIncludes.DepthOnly, - }; - - public static PassDescriptor SceneSelection = new PassDescriptor() - { - // Definition - displayName = "SceneSelectionPass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "SceneSelectionPass", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentAlphaDepth, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.SceneSelection, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayerEditorSync, - defines = CoreDefines.SceneSelection, - keywords = CoreKeywords.HDBase, - includes = StackLitIncludes.DepthOnly, - }; - - public static PassDescriptor DepthForwardOnly = new PassDescriptor() - { - // // Code path for WRITE_NORMAL_BUFFER - // See StackLit.hlsl:ConvertSurfaceDataToNormalData() - // which ShaderPassDepthOnly uses: we need to add proper interpolators dependencies depending on WRITE_NORMAL_BUFFER. - // In our case WRITE_NORMAL_BUFFER is always enabled here. - // Also, we need to add PixelShaderSlots dependencies for everything potentially used there. - // See AddPixelShaderSlotsForWriteNormalBufferPasses() - - // Definition - displayName = "DepthForwardOnly", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "DepthForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.DepthOnly, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = StackLitIncludes.DepthOnly, - }; - - public static PassDescriptor MotionVectors = new PassDescriptor() - { - // Definition - displayName = "MotionVectors", - referenceName = "SHADERPASS_MOTION_VECTORS", - lightMode = "MotionVectors", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentDepthMotionVectors, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.MotionVectors, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - defines = CoreDefines.DepthMotionVectors, - keywords = CoreKeywords.DepthMotionVectorsNoNormal, - includes = StackLitIncludes.MotionVectors, - }; - - public static PassDescriptor Distortion = new PassDescriptor() - { - // Definition - displayName = "DistortionVectors", - referenceName = "SHADERPASS_DISTORTION", - lightMode = "DistortionVectors", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentDistortion, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = StackLitRenderStates.Distortion, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - keywords = CoreKeywords.HDBase, - includes = StackLitIncludes.Distortion, - }; - - public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPrepass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPrepass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentTransparentDepthPrepass, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPrePass, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.TransparentDepthPrepass, - keywords = CoreKeywords.HDBase, - includes = StackLitIncludes.DepthOnly, - }; - - public static PassDescriptor ForwardOnly = new PassDescriptor() - { - // Definition - displayName = "ForwardOnly", - referenceName = "SHADERPASS_FORWARD", - lightMode = "ForwardOnly", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.Forward, - pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, - defines = CoreDefines.Forward, - keywords = CoreKeywords.Forward, - includes = StackLitIncludes.ForwardOnly, - }; - - public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() - { - // Definition - displayName = "TransparentDepthPostpass", - referenceName = "SHADERPASS_DEPTH_ONLY", - lightMode = "TransparentDepthPostpass", - useInPreview = true, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentTransparentDepthPostpass, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - renderStates = CoreRenderStates.TransparentDepthPostPass, - pragmas = CorePragmas.DotsInstancedInV2Only, - defines = CoreDefines.ShaderGraphRaytracingHigh, - keywords = CoreKeywords.HDBase, - includes = StackLitIncludes.DepthOnly, - }; - - public static PassDescriptor RaytracingIndirect = new PassDescriptor() - { - // Definition - displayName = "IndirectDXR", - referenceName = "SHADERPASS_RAYTRACING_INDIRECT", - lightMode = "IndirectDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = StackLitDefines.RaytracingIndirect, - keywords = CoreKeywords.RaytracingIndirect, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingIndirect }, - }; - - public static PassDescriptor RaytracingVisibility = new PassDescriptor() - { - // Definition - displayName = "VisibilityDXR", - referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", - lightMode = "VisibilityDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = StackLitDefines.RaytracingVisibility, - keywords = CoreKeywords.RaytracingVisiblity, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingVisibility }, - }; - - public static PassDescriptor RaytracingForward = new PassDescriptor() - { - // Definition - displayName = "ForwardDXR", - referenceName = "SHADERPASS_RAYTRACING_FORWARD", - lightMode = "ForwardDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = StackLitDefines.RaytracingForward, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingForward }, - }; - - public static PassDescriptor RaytracingGBuffer = new PassDescriptor() - { - // Definition - displayName = "GBufferDXR", - referenceName = "SHADERPASS_RAYTRACING_GBUFFER", - lightMode = "GBufferDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port Mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentForward, - - // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = StackLitDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RayTracingGBuffer }, - }; - - public static PassDescriptor RaytracingSubSurface = new PassDescriptor() - { - //Definition - displayName = "SubSurfaceDXR", - referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", - lightMode = "SubSurfaceDXR", - useInPreview = false, - - // Template - passTemplatePath = passTemplatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - //Port mask - validVertexBlocks = CoreBlockMasks.Vertex, - validPixelBlocks = StackLitBlockMasks.FragmentForward, - - //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, - pragmas = CorePragmas.RaytracingBasic, - defines = StackLitDefines.RaytracingGBuffer, - keywords = CoreKeywords.RaytracingGBufferForward, - includes = CoreIncludes.Raytracing, - requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingSubSurface }, - }; - } -#endregion - -#region PortMasks - static class StackLitBlockMasks - { - public static BlockFieldDescriptor[] VertexPosition = new BlockFieldDescriptor[] - { - BlockFields.VertexDescription.Position, - }; - - public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIR, - HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIRClamp, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.DielectricIor, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - HDBlockFields.SurfaceDescription.SmoothnessB, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.AnisotropyB, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.CoatSmoothness, - HDBlockFields.SurfaceDescription.CoatIor, - HDBlockFields.SurfaceDescription.CoatThickness, - HDBlockFields.SurfaceDescription.CoatExtinction, - HDBlockFields.SurfaceDescription.CoatNormal, - HDBlockFields.SurfaceDescription.CoatMask, - HDBlockFields.SurfaceDescription.LobeMix, - HDBlockFields.SurfaceDescription.Haziness, - HDBlockFields.SurfaceDescription.HazeExtent, - HDBlockFields.SurfaceDescription.HazyGlossMaxDielectricF0, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - HDBlockFields.SurfaceDescription.SOFixupVisibilityRatioThreshold, - HDBlockFields.SurfaceDescription.SOFixupStrengthFactor, - HDBlockFields.SurfaceDescription.SOFixupMaxAddedRoughness, - }; - - public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - // StackLitMasterNode.coat - HDBlockFields.SurfaceDescription.CoatSmoothness, - HDBlockFields.SurfaceDescription.CoatNormal, - // !StackLitMasterNode.coat - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.LobeMix, - BlockFields.SurfaceDescription.Smoothness, - HDBlockFields.SurfaceDescription.SmoothnessB, - // StackLitMasterNode.geometricSpecularAA - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - }; - - public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Distortion, - HDBlockFields.SurfaceDescription.DistortionBlur, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, - HDBlockFields.SurfaceDescription.DepthOffset, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.Smoothness, - }; - - public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIR, - HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIRClamp, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.DielectricIor, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - HDBlockFields.SurfaceDescription.SmoothnessB, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.AnisotropyB, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.CoatSmoothness, - HDBlockFields.SurfaceDescription.CoatIor, - HDBlockFields.SurfaceDescription.CoatThickness, - HDBlockFields.SurfaceDescription.CoatExtinction, - HDBlockFields.SurfaceDescription.CoatNormal, - HDBlockFields.SurfaceDescription.CoatMask, - HDBlockFields.SurfaceDescription.LobeMix, - HDBlockFields.SurfaceDescription.Haziness, - HDBlockFields.SurfaceDescription.HazeExtent, - HDBlockFields.SurfaceDescription.HazyGlossMaxDielectricF0, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - HDBlockFields.SurfaceDescription.SOFixupVisibilityRatioThreshold, - HDBlockFields.SurfaceDescription.SOFixupStrengthFactor, - HDBlockFields.SurfaceDescription.SOFixupMaxAddedRoughness, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - - public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - } -#endregion - -#region RenderStates - static class StackLitRenderStates - { - public static RenderStateCollection ShadowCaster = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.Zero) }, - { RenderState.ZWrite(ZWrite.On) }, - { RenderState.ZClip(CoreRenderStates.Uniforms.zClip) }, - { RenderState.ColorMask("ColorMask 0") }, - }; - - public static RenderStateCollection Distortion = new RenderStateCollection - { - { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, - { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, - { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, - { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, - { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, - { RenderState.ZWrite(ZWrite.Off) }, - { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, - { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, - { RenderState.Stencil(new StencilDescriptor() - { - WriteMask = $"{(int)StencilUsage.DistortionVectors}", - Ref = $"{(int)StencilUsage.DistortionVectors}", - Comp = "Always", - Pass = "Replace", - }) }, - }; - } -#endregion - -#region Defines - static class StackLitDefines - { - public static DefineCollection RaytracingForward = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingIndirect = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - - public static DefineCollection RaytracingGBuffer = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - public static DefineCollection RaytracingVisibility = new DefineCollection - { - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - public static DefineCollection RaytracingPathTracing = new DefineCollection - { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 0 }, - { CoreKeywordDescriptors.HasLightloop, 1 }, - }; - } -#endregion - -#region Pragmas - static class StackLitPragmas - { - public static PragmaCollection DotsInstancedInV2OnlyRenderingLayer = new PragmaCollection - { - { CorePragmas.Basic }, - { Pragma.MultiCompileInstancing }, - { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) }, - #if ENABLE_HYBRID_RENDERER_V2 - { Pragma.DOTSInstancing }, - { Pragma.InstancingOptions(InstancingOptions.NoLodFade) }, - #endif - }; - - public static PragmaCollection DotsInstancedInV2OnlyRenderingLayerEditorSync = new PragmaCollection - { - { CorePragmas.Basic }, - { Pragma.MultiCompileInstancing }, - { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) }, - { Pragma.EditorSyncCompilation }, - #if ENABLE_HYBRID_RENDERER_V2 - { Pragma.DOTSInstancing }, - { Pragma.InstancingOptions(InstancingOptions.NoLodFade) }, - #endif - }; - } -#endregion - protected override string subShaderInclude => CoreIncludes.kStackLit; - -#region Includes - static class StackLitIncludes - { - const string kSpecularOcclusionDef = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/SphericalCapPivot/SpecularOcclusionDef.hlsl"; - const string kStackLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLitDecalData.hlsl"; - - public static IncludeCollection Common = new IncludeCollection - { - { kSpecularOcclusionDef, IncludeLocation.Pregraph }, - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kStackLit, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { kStackLitDecalData, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - }; - - public static IncludeCollection Meta = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection DepthOnly = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection MotionVectors = new IncludeCollection - { - { Common }, - { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection Distortion = new IncludeCollection - { - { Common }, - { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, - }; - - public static IncludeCollection ForwardOnly = new IncludeCollection - { - { kSpecularOcclusionDef, IncludeLocation.Pregraph }, - { CoreIncludes.CorePregraph }, - { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - { CoreIncludes.kStackLit, IncludeLocation.Pregraph }, - { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - { CoreIncludes.CoreUtility }, - { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { kStackLitDecalData, IncludeLocation.Pregraph }, - { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - }; - } -#endregion +// #region SubShaders +// // static class SubShaders +// // { +// // public static SubShaderDescriptor StackLit = new SubShaderDescriptor() +// // { +// // pipelineTag = HDRenderPipeline.k_ShaderTagName, +// // generatesPreview = true, +// // passes = new PassCollection +// // { +// // { StackLitPasses.ShadowCaster }, +// // { StackLitPasses.META }, +// // { StackLitPasses.SceneSelection }, +// // { StackLitPasses.DepthForwardOnly }, +// // { StackLitPasses.MotionVectors }, +// // { StackLitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, +// // { StackLitPasses.TransparentDepthPrepass, new FieldCondition[]{ +// // new FieldCondition(HDFields.TransparentDepthPrePass, true), +// // new FieldCondition(HDFields.DisableSSRTransparent, true) }}, +// // { StackLitPasses.TransparentDepthPrepass, new FieldCondition[]{ +// // new FieldCondition(HDFields.TransparentDepthPrePass, true), +// // new FieldCondition(HDFields.DisableSSRTransparent, false) }}, +// // { StackLitPasses.TransparentDepthPrepass, new FieldCondition[]{ +// // new FieldCondition(HDFields.TransparentDepthPrePass, false), +// // new FieldCondition(HDFields.DisableSSRTransparent, false) }}, +// // { StackLitPasses.ForwardOnly }, +// // { StackLitPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, +// // }, +// // }; + +// // public static SubShaderDescriptor StackLitRaytracing = new SubShaderDescriptor() +// // { +// // pipelineTag = HDRenderPipeline.k_ShaderTagName, +// // generatesPreview = false, +// // passes = new PassCollection +// // { +// // { StackLitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, +// // { StackLitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, +// // { StackLitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, +// // { StackLitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, +// // { StackLitPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, +// // }, +// // }; +// // } +// #endregion + +// #region Passes +// public static class StackLitPasses +// { +// public static PassDescriptor META = new PassDescriptor() +// { +// // Definition +// displayName = "META", +// referenceName = "SHADERPASS_LIGHT_TRANSPORT", +// lightMode = "META", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validPixelBlocks = StackLitBlockMasks.FragmentMETA, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.Meta, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Meta, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// keywords = CoreKeywords.HDBase, +// includes = StackLitIncludes.Meta, +// }; + +// public static PassDescriptor ShadowCaster = new PassDescriptor() +// { +// // Definition +// displayName = "ShadowCaster", +// referenceName = "SHADERPASS_SHADOWS", +// lightMode = "ShadowCaster", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = StackLitBlockMasks.VertexPosition, +// validPixelBlocks = StackLitBlockMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = StackLitRenderStates.ShadowCaster, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// keywords = CoreKeywords.HDBase, +// includes = StackLitIncludes.DepthOnly, +// }; + +// public static PassDescriptor SceneSelection = new PassDescriptor() +// { +// // Definition +// displayName = "SceneSelectionPass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "SceneSelectionPass", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentAlphaDepth, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.SceneSelection, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayerEditorSync, +// defines = CoreDefines.SceneSelection, +// keywords = CoreKeywords.HDBase, +// includes = StackLitIncludes.DepthOnly, +// }; + +// public static PassDescriptor DepthForwardOnly = new PassDescriptor() +// { +// // // Code path for WRITE_NORMAL_BUFFER +// // See StackLit.hlsl:ConvertSurfaceDataToNormalData() +// // which ShaderPassDepthOnly uses: we need to add proper interpolators dependencies depending on WRITE_NORMAL_BUFFER. +// // In our case WRITE_NORMAL_BUFFER is always enabled here. +// // Also, we need to add PixelShaderSlots dependencies for everything potentially used there. +// // See AddPixelShaderSlotsForWriteNormalBufferPasses() + +// // Definition +// displayName = "DepthForwardOnly", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "DepthForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.DepthOnly, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = StackLitIncludes.DepthOnly, +// }; + +// public static PassDescriptor MotionVectors = new PassDescriptor() +// { +// // Definition +// displayName = "MotionVectors", +// referenceName = "SHADERPASS_MOTION_VECTORS", +// lightMode = "MotionVectors", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentDepthMotionVectors, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.MotionVectors, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// defines = CoreDefines.DepthMotionVectors, +// keywords = CoreKeywords.DepthMotionVectorsNoNormal, +// includes = StackLitIncludes.MotionVectors, +// }; + +// public static PassDescriptor Distortion = new PassDescriptor() +// { +// // Definition +// displayName = "DistortionVectors", +// referenceName = "SHADERPASS_DISTORTION", +// lightMode = "DistortionVectors", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentDistortion, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = StackLitRenderStates.Distortion, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// keywords = CoreKeywords.HDBase, +// includes = StackLitIncludes.Distortion, +// }; + +// public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPrepass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPrepass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentTransparentDepthPrepass, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPrePass, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.TransparentDepthPrepass, +// keywords = CoreKeywords.HDBase, +// includes = StackLitIncludes.DepthOnly, +// }; + +// public static PassDescriptor ForwardOnly = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardOnly", +// referenceName = "SHADERPASS_FORWARD", +// lightMode = "ForwardOnly", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// requiredFields = CoreRequiredFields.LitFull, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.Forward, +// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, +// defines = CoreDefines.Forward, +// keywords = CoreKeywords.Forward, +// includes = StackLitIncludes.ForwardOnly, +// }; + +// public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() +// { +// // Definition +// displayName = "TransparentDepthPostpass", +// referenceName = "SHADERPASS_DEPTH_ONLY", +// lightMode = "TransparentDepthPostpass", +// useInPreview = true, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentTransparentDepthPostpass, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// renderStates = CoreRenderStates.TransparentDepthPostPass, +// pragmas = CorePragmas.DotsInstancedInV2Only, +// defines = CoreDefines.ShaderGraphRaytracingHigh, +// keywords = CoreKeywords.HDBase, +// includes = StackLitIncludes.DepthOnly, +// }; + +// public static PassDescriptor RaytracingIndirect = new PassDescriptor() +// { +// // Definition +// displayName = "IndirectDXR", +// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", +// lightMode = "IndirectDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = StackLitDefines.RaytracingIndirect, +// keywords = CoreKeywords.RaytracingIndirect, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingIndirect }, +// }; + +// public static PassDescriptor RaytracingVisibility = new PassDescriptor() +// { +// // Definition +// displayName = "VisibilityDXR", +// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", +// lightMode = "VisibilityDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = StackLitDefines.RaytracingVisibility, +// keywords = CoreKeywords.RaytracingVisiblity, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingVisibility }, +// }; + +// public static PassDescriptor RaytracingForward = new PassDescriptor() +// { +// // Definition +// displayName = "ForwardDXR", +// referenceName = "SHADERPASS_RAYTRACING_FORWARD", +// lightMode = "ForwardDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = StackLitDefines.RaytracingForward, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingForward }, +// }; + +// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() +// { +// // Definition +// displayName = "GBufferDXR", +// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", +// lightMode = "GBufferDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// // Port Mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentForward, + +// // Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = StackLitDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RayTracingGBuffer }, +// }; + +// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() +// { +// //Definition +// displayName = "SubSurfaceDXR", +// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", +// lightMode = "SubSurfaceDXR", +// useInPreview = false, + +// // Template +// passTemplatePath = passTemplatePath, +// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + +// //Port mask +// validVertexBlocks = CoreBlockMasks.Vertex, +// validPixelBlocks = StackLitBlockMasks.FragmentForward, + +// //Collections +// structs = CoreStructCollections.Default, +// fieldDependencies = CoreFieldDependencies.Default, +// pragmas = CorePragmas.RaytracingBasic, +// defines = StackLitDefines.RaytracingGBuffer, +// keywords = CoreKeywords.RaytracingGBufferForward, +// includes = CoreIncludes.Raytracing, +// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingSubSurface }, +// }; +// } +// #endregion + +// #region PortMasks +// static class StackLitBlockMasks +// { +// public static BlockFieldDescriptor[] VertexPosition = new BlockFieldDescriptor[] +// { +// BlockFields.VertexDescription.Position, +// }; + +// public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// HDBlockFields.SurfaceDescription.BentNormal, +// HDBlockFields.SurfaceDescription.Tangent, +// HDBlockFields.SurfaceDescription.SubsurfaceMask, +// HDBlockFields.SurfaceDescription.Thickness, +// HDBlockFields.SurfaceDescription.DiffusionProfileHash, +// HDBlockFields.SurfaceDescription.IridescenceMask, +// HDBlockFields.SurfaceDescription.IridescenceThickness, +// HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIR, +// HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIRClamp, +// BlockFields.SurfaceDescription.Specular, +// HDBlockFields.SurfaceDescription.DielectricIor, +// BlockFields.SurfaceDescription.Metallic, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Smoothness, +// HDBlockFields.SurfaceDescription.SmoothnessB, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.Anisotropy, +// HDBlockFields.SurfaceDescription.AnisotropyB, +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// HDBlockFields.SurfaceDescription.CoatSmoothness, +// HDBlockFields.SurfaceDescription.CoatIor, +// HDBlockFields.SurfaceDescription.CoatThickness, +// HDBlockFields.SurfaceDescription.CoatExtinction, +// HDBlockFields.SurfaceDescription.CoatNormal, +// HDBlockFields.SurfaceDescription.CoatMask, +// HDBlockFields.SurfaceDescription.LobeMix, +// HDBlockFields.SurfaceDescription.Haziness, +// HDBlockFields.SurfaceDescription.HazeExtent, +// HDBlockFields.SurfaceDescription.HazyGlossMaxDielectricF0, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// HDBlockFields.SurfaceDescription.SOFixupVisibilityRatioThreshold, +// HDBlockFields.SurfaceDescription.SOFixupStrengthFactor, +// HDBlockFields.SurfaceDescription.SOFixupMaxAddedRoughness, +// }; + +// public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.DepthOffset, +// // StackLitMasterNode.coat +// HDBlockFields.SurfaceDescription.CoatSmoothness, +// HDBlockFields.SurfaceDescription.CoatNormal, +// // !StackLitMasterNode.coat +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// HDBlockFields.SurfaceDescription.LobeMix, +// BlockFields.SurfaceDescription.Smoothness, +// HDBlockFields.SurfaceDescription.SmoothnessB, +// // StackLitMasterNode.geometricSpecularAA +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// }; + +// public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.Distortion, +// HDBlockFields.SurfaceDescription.DistortionBlur, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, +// HDBlockFields.SurfaceDescription.DepthOffset, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// BlockFields.SurfaceDescription.Smoothness, +// }; + +// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.BaseColor, +// BlockFields.SurfaceDescription.NormalTS, +// BlockFields.SurfaceDescription.NormalWS, +// BlockFields.SurfaceDescription.NormalOS, +// HDBlockFields.SurfaceDescription.BentNormal, +// HDBlockFields.SurfaceDescription.Tangent, +// HDBlockFields.SurfaceDescription.SubsurfaceMask, +// HDBlockFields.SurfaceDescription.Thickness, +// HDBlockFields.SurfaceDescription.DiffusionProfileHash, +// HDBlockFields.SurfaceDescription.IridescenceMask, +// HDBlockFields.SurfaceDescription.IridescenceThickness, +// HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIR, +// HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIRClamp, +// BlockFields.SurfaceDescription.Specular, +// HDBlockFields.SurfaceDescription.DielectricIor, +// BlockFields.SurfaceDescription.Metallic, +// BlockFields.SurfaceDescription.Emission, +// BlockFields.SurfaceDescription.Smoothness, +// HDBlockFields.SurfaceDescription.SmoothnessB, +// BlockFields.SurfaceDescription.Occlusion, +// BlockFields.SurfaceDescription.Alpha, +// BlockFields.SurfaceDescription.AlphaClipThreshold, +// HDBlockFields.SurfaceDescription.Anisotropy, +// HDBlockFields.SurfaceDescription.AnisotropyB, +// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, +// HDBlockFields.SurfaceDescription.SpecularAAThreshold, +// HDBlockFields.SurfaceDescription.CoatSmoothness, +// HDBlockFields.SurfaceDescription.CoatIor, +// HDBlockFields.SurfaceDescription.CoatThickness, +// HDBlockFields.SurfaceDescription.CoatExtinction, +// HDBlockFields.SurfaceDescription.CoatNormal, +// HDBlockFields.SurfaceDescription.CoatMask, +// HDBlockFields.SurfaceDescription.LobeMix, +// HDBlockFields.SurfaceDescription.Haziness, +// HDBlockFields.SurfaceDescription.HazeExtent, +// HDBlockFields.SurfaceDescription.HazyGlossMaxDielectricF0, +// HDBlockFields.SurfaceDescription.SpecularOcclusion, +// HDBlockFields.SurfaceDescription.SOFixupVisibilityRatioThreshold, +// HDBlockFields.SurfaceDescription.SOFixupStrengthFactor, +// HDBlockFields.SurfaceDescription.SOFixupMaxAddedRoughness, +// HDBlockFields.SurfaceDescription.BakedGI, +// HDBlockFields.SurfaceDescription.BakedBackGI, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; + +// public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] +// { +// BlockFields.SurfaceDescription.Alpha, +// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, +// HDBlockFields.SurfaceDescription.DepthOffset, +// }; +// } +// #endregion + +// #region RenderStates +// static class StackLitRenderStates +// { +// public static RenderStateCollection ShadowCaster = new RenderStateCollection +// { +// { RenderState.Blend(Blend.One, Blend.Zero) }, +// { RenderState.ZWrite(ZWrite.On) }, +// { RenderState.ZClip(CoreRenderStates.Uniforms.zClip) }, +// { RenderState.ColorMask("ColorMask 0") }, +// }; + +// public static RenderStateCollection Distortion = new RenderStateCollection +// { +// { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, +// { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, +// { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, +// { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, +// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, +// { RenderState.ZWrite(ZWrite.Off) }, +// { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, +// { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, +// { RenderState.Stencil(new StencilDescriptor() +// { +// WriteMask = $"{(int)StencilUsage.DistortionVectors}", +// Ref = $"{(int)StencilUsage.DistortionVectors}", +// Comp = "Always", +// Pass = "Replace", +// }) }, +// }; +// } +// #endregion + +// #region Defines +// static class StackLitDefines +// { +// public static DefineCollection RaytracingForward = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingIndirect = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; + +// public static DefineCollection RaytracingGBuffer = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingVisibility = new DefineCollection +// { +// { RayTracingNode.GetRayTracingKeyword(), 1 }, +// }; + +// public static DefineCollection RaytracingPathTracing = new DefineCollection +// { +// { CoreKeywordDescriptors.Shadow, 0 }, +// { RayTracingNode.GetRayTracingKeyword(), 0 }, +// { CoreKeywordDescriptors.HasLightloop, 1 }, +// }; +// } +// #endregion + +// #region Pragmas +// static class StackLitPragmas +// { +// public static PragmaCollection DotsInstancedInV2OnlyRenderingLayer = new PragmaCollection +// { +// { CorePragmas.Basic }, +// { Pragma.MultiCompileInstancing }, +// { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) }, +// #if ENABLE_HYBRID_RENDERER_V2 +// { Pragma.DOTSInstancing }, +// { Pragma.InstancingOptions(InstancingOptions.NoLodFade) }, +// #endif +// }; + +// public static PragmaCollection DotsInstancedInV2OnlyRenderingLayerEditorSync = new PragmaCollection +// { +// { CorePragmas.Basic }, +// { Pragma.MultiCompileInstancing }, +// { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) }, +// { Pragma.EditorSyncCompilation }, +// #if ENABLE_HYBRID_RENDERER_V2 +// { Pragma.DOTSInstancing }, +// { Pragma.InstancingOptions(InstancingOptions.NoLodFade) }, +// #endif +// }; +// } +// #endregion + +// #region Includes +// static class StackLitIncludes +// { +// const string kSpecularOcclusionDef = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/SphericalCapPivot/SpecularOcclusionDef.hlsl"; +// const string kStackLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLitDecalData.hlsl"; + +// public static IncludeCollection Common = new IncludeCollection +// { +// { kSpecularOcclusionDef, IncludeLocation.Pregraph }, +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kStackLit, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { kStackLitDecalData, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// }; + +// public static IncludeCollection Meta = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection DepthOnly = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection MotionVectors = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection Distortion = new IncludeCollection +// { +// { Common }, +// { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, +// }; + +// public static IncludeCollection ForwardOnly = new IncludeCollection +// { +// { kSpecularOcclusionDef, IncludeLocation.Pregraph }, +// { CoreIncludes.CorePregraph }, +// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, +// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, +// { CoreIncludes.kStackLit, IncludeLocation.Pregraph }, +// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, +// { CoreIncludes.CoreUtility }, +// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, +// { kStackLitDecalData, IncludeLocation.Pregraph }, +// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, +// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, +// }; +// } +// #endregion } } 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 90d9b80506d..f2029065546 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs @@ -992,11 +992,13 @@ static class CoreIncludes // Public Postgraph Pass public const string kPassLightTransport = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl"; public const string kPassDepthOnly = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDepthOnly.hlsl"; + public const string kPassGBuffer = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"; public const string kPassMotionVectors = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassMotionVectors.hlsl"; public const string kDisortionVectors = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassDistortion.hlsl"; public const string kPassForward = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForward.hlsl"; public const string kStandardLit = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StandardLit/StandardLit.hlsl"; public const string kPassForwardUnlit = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"; + public const string kPassConstant = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassConstant.hlsl"; public static IncludeCollection CorePregraph = new IncludeCollection { From defe67d17b7848d569161a9475f3a98e5468dba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Thu, 4 Jun 2020 19:02:50 +0200 Subject: [PATCH 20/30] Added file dependency and remove unused template path --- .../Decal/ShaderGraph/DecalSubTarget.cs | 3 +- .../Material/Eye/ShaderGraph/EyeSubTarget.cs | 3 - .../Fabric/ShaderGraph/FabricSubTarget.cs | 3 - .../Hair/ShaderGraph/HairSubTarget.cs | 3 - .../Lit/ShaderGraph/HDLitSubTarget.cs | 3 - .../Material/ShaderGraph/HDShaderPasses.cs | 68 ++-------- .../Material/ShaderGraph/HDSubTarget.cs | 2 +- .../Material/ShaderGraph/LightingSubTarget.cs | 6 + .../Material/ShaderGraph/SurfaceSubTarget.cs | 18 +-- .../StackLit/ShaderGraph/StackLitSubTarget.cs | 120 ------------------ 10 files changed, 32 insertions(+), 197 deletions(-) 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 12d26abf02f..5e8421691a4 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 @@ -17,10 +17,9 @@ sealed partial class DecalSubTarget : HDSubTarget, ILegacyTarget, IRequiresData< { public DecalSubTarget() => displayName = "Decal"; - // TODO: remove this line public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Decal/ShaderGraph/DecalPass.template"; - protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Decal/ShaderGraph/DecalPass.template"; + protected override string templatePath => passTemplatePath; protected override string subTargetAssetGuid => "3ec927dfcb5d60e4883b2c224857b6c2"; protected override string customInspector => "Rendering.HighDefinition.DecalGUI"; protected override string renderType => HDRenderTypeTags.Opaque.ToString(); 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 7f41f571944..6bbcf5c1cdc 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 @@ -17,9 +17,6 @@ sealed partial class EyeSubTarget : LightingSubTarget, ILegacyTarget, IRequiresD { public EyeSubTarget() => displayName = "Eye"; - // TODO: remove this line - public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Eye/ShaderGraph/EyePass.template"; - protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Eye/ShaderGraph/EyePass.template"; protected override string customInspector => "Rendering.HighDefinition.EyeGUI"; protected override string subTargetAssetGuid => "864e4e09d6293cf4d98457f740bb3301"; 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 c9761f5ff39..d8147983e52 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 @@ -17,9 +17,6 @@ sealed partial class FabricSubTarget : LightingSubTarget, ILegacyTarget, IRequir { public FabricSubTarget() => displayName = "Fabric"; - // TODO: remove this line - public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Fabric/ShaderGraph/FabricPass.template"; - protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Fabric/ShaderGraph/FabricPass.template"; protected override string subTargetAssetGuid => "74f1a4749bab90d429ac01d094be0aeb"; // FabricSubTarget.cs protected override string customInspector => "Rendering.HighDefinition.FabricGUI"; 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 0d9485187b6..ae6f463826d 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 @@ -17,9 +17,6 @@ sealed partial class HairSubTarget : LightingSubTarget, ILegacyTarget, IRequires { public HairSubTarget() => displayName = "Hair"; - // TODO: remove this line - public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Hair/ShaderGraph/HairPass.template"; - protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Hair/ShaderGraph/HairPass.template"; protected override string customInspector => "Rendering.HighDefinition.HairGUI"; protected override string subTargetAssetGuid => "7e681cc79dd8e6c46ba1e8412d519e26"; // HairSubTarget.cs 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 f56391eea4a..7269d7a5660 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 @@ -31,9 +31,6 @@ public HDLitData litData public HDLitSubTarget() => displayName = "Lit"; - // TODO: remove this line when all the passes are moved to HDPasses - public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; - protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; protected override string customInspector => "Rendering.HighDefinition.HDLitGUI"; protected override string subTargetAssetGuid => "caab952c840878340810cca27417971c"; // HDLitSubTarget.cs diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index 5d3496c9c83..50aed180b33 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -24,15 +24,13 @@ public static PassDescriptor GenerateDistortionPass(bool supportLighting) // Template // passTemplatePath = templatePath, - sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, + // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, // Port mask // validVertexBlocks = CoreBlockMasks.Vertex, // validPixelBlocks = FragmentDistortion, // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, renderStates = GenerateRenderState(), pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = CoreDefines.ShaderGraphRaytracingHigh, @@ -82,13 +80,13 @@ IncludeCollection GenerateIncludes() } } - public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Distortion, - HDBlockFields.SurfaceDescription.DistortionBlur, - }; + // public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] + // { + // BlockFields.SurfaceDescription.Alpha, + // BlockFields.SurfaceDescription.AlphaClipThreshold, + // HDBlockFields.SurfaceDescription.Distortion, + // HDBlockFields.SurfaceDescription.DistortionBlur, + // }; #endregion @@ -109,8 +107,6 @@ public static PassDescriptor GenerateSceneSelection(bool supportLighting) // validPixelBlocks = FragmentSceneSelection, // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, renderStates = CoreRenderStates.SceneSelection, pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, defines = CoreDefines.SceneSelection, @@ -139,12 +135,12 @@ IncludeCollection GenerateIncludes() } } - public static BlockFieldDescriptor[] FragmentSceneSelection = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; + // public static BlockFieldDescriptor[] FragmentSceneSelection = new BlockFieldDescriptor[] + // { + // BlockFields.SurfaceDescription.Alpha, + // BlockFields.SurfaceDescription.AlphaClipThreshold, + // HDBlockFields.SurfaceDescription.DepthOffset, + // }; #endregion @@ -165,8 +161,6 @@ static public PassDescriptor GenerateShadowCaster(bool supportLighting) // validPixelBlocks = FragmentShadowCaster, // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, renderStates = CoreRenderStates.ShadowCaster, pragmas = CorePragmas.DotsInstancedInV2Only, keywords = CoreKeywords.HDBase, @@ -226,9 +220,7 @@ public static PassDescriptor GenerateMETA(bool supportLighting) validPixelBlocks = FragmentMeta, // Collections - structs = CoreStructCollections.Default, requiredFields = CoreRequiredFields.Meta, - fieldDependencies = CoreFieldDependencies.Default, renderStates = CoreRenderStates.Meta, pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = CoreDefines.ShaderGraphRaytracingHigh, @@ -309,9 +301,7 @@ public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting) // validPixelBlocks = FragmentDepthOnlyVectors, // Collections - structs = CoreStructCollections.Default, requiredFields = GenerateRequiredFields(), - fieldDependencies = CoreFieldDependencies.Default, renderStates = CoreRenderStates.DepthOnly, pragmas = CorePragmas.DotsInstancedInV2Only, defines = supportLighting ? CoreDefines.DepthMotionVectors : null, @@ -387,10 +377,8 @@ public static PassDescriptor GenerateMotionVectors(bool supportLighting) // validPixelBlocks = FragmentMotionVectors, // Collections - structs = CoreStructCollections.Default, requiredFields = CoreRequiredFields.LitFull, renderStates = GenerateRenderState(), - fieldDependencies = CoreFieldDependencies.Default, defines = supportLighting ? CoreDefines.DepthMotionVectors : null, pragmas = CorePragmas.DotsInstancedInV2Only, keywords = GenerateKeywords(), @@ -476,9 +464,7 @@ public static PassDescriptor GenereateForwardOnlyPass(bool supportLighting) // validPixelBlocks = FragmentForwardOnly, // Collections - structs = CoreStructCollections.Default, requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, renderStates = CoreRenderStates.Forward, pragmas = CorePragmas.DotsInstancedInV2Only, defines = supportLighting ? CoreDefines.Forward : null, @@ -573,9 +559,7 @@ public static PassDescriptor GenerateBackThenFront(bool supportLighting) // validPixelBlocks = FragmentBackThenFront, // Collections - structs = CoreStructCollections.Default, requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, renderStates = CoreRenderStates.TransparentBackface, pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = CoreDefines.Forward, @@ -676,9 +660,7 @@ public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLightin // validPixelBlocks = FragmentTransparentDepthPrepass, // Collections - structs = CoreStructCollections.Default, requiredFields = TransparentDepthPrepassFields, - fieldDependencies = CoreFieldDependencies.Default, renderStates = GenerateRenderState(), pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = GenerateDefines(), @@ -789,8 +771,6 @@ public static PassDescriptor GenerateTransparentDepthPostpass(bool supportLighti // validPixelBlocks = FragmentTransparentDepthPostpass, // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, renderStates = GenerateRenderState(), pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = CoreDefines.ShaderGraphRaytracingHigh, @@ -861,9 +841,7 @@ public static PassDescriptor GenerateLitDepthOnly() // validPixelBlocks = LitBlockMasks.FragmentDepthMotionVectors, // Collections - structs = CoreStructCollections.Default, requiredFields = CoreRequiredFields.LitFull, - fieldDependencies = CoreFieldDependencies.Default, renderStates = CoreRenderStates.DepthOnly, pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = CoreDefines.ShaderGraphRaytracingHigh, @@ -915,9 +893,7 @@ public static PassDescriptor GenerateGBuffer() // validPixelBlocks = LitBlockMasks.FragmentDefault, // Collections - structs = CoreStructCollections.Default, requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, renderStates = GBufferRenderState, pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = CoreDefines.ShaderGraphRaytracingHigh, @@ -986,9 +962,7 @@ public static PassDescriptor GenerateLitForward() // validPixelBlocks = LitBlockMasks.FragmentDefault, // Collections - structs = CoreStructCollections.Default, requiredFields = CoreRequiredFields.LitMinimal, - fieldDependencies = CoreFieldDependencies.Default, renderStates = CoreRenderStates.ForwardColorMask, pragmas = CorePragmas.DotsInstancedInV1AndV2, defines = CoreDefines.Forward, @@ -1037,8 +1011,6 @@ public static PassDescriptor GenerateLitRaytracingPrepass() // validPixelBlocks = LitBlockMasks.FragmentRayTracingPrepass, // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, renderStates = RayTracingPrepassRenderState, pragmas = LitRaytracingPrepassPragmas, defines = CoreDefines.ShaderGraphRaytracingHigh, @@ -1094,8 +1066,6 @@ public static PassDescriptor GenerateRaytracingIndirect(bool supportLighting) // validPixelBlocks = RaytracingIndirectFragment, // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, pragmas = CorePragmas.RaytracingBasic, defines = supportLighting ? GenerateDefines() : null, keywords = CoreKeywords.RaytracingIndirect, @@ -1175,8 +1145,6 @@ public static PassDescriptor GenerateRaytracingVisibility(bool supportLighting) // validPixelBlocks = RaytracingVisibilityFragment, // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, pragmas = CorePragmas.RaytracingBasic, defines = supportLighting ? RaytracingVisibilityDefines : null, keywords = CoreKeywords.RaytracingVisiblity, @@ -1252,8 +1220,6 @@ public static PassDescriptor GenerateRaytracingForward(bool supportLighting) // validPixelBlocks = RaytracingForwardFragment, // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, pragmas = CorePragmas.RaytracingBasic, defines = supportLighting ? RaytracingForwardDefines : null, keywords = CoreKeywords.RaytracingGBufferForward, @@ -1330,8 +1296,6 @@ public static PassDescriptor GenerateRaytracingGBuffer(bool supportLighting) // validPixelBlocks = RaytracingGBufferFragment, // Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, pragmas = CorePragmas.RaytracingBasic, defines = supportLighting ? RaytracingGBufferDefines : null, keywords = CoreKeywords.RaytracingGBufferForward, @@ -1407,8 +1371,6 @@ public static PassDescriptor GeneratePathTracing(bool supportLighting) // validPixelBlocks = PathTracingFragment, //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, pragmas = CorePragmas.RaytracingBasic, defines = supportLighting ? RaytracingPathTracingDefines : null, keywords = CoreKeywords.HDBaseNoCrossFade, @@ -1480,8 +1442,6 @@ public static PassDescriptor GenerateRaytracingSubsurface() // validPixelBlocks = LitBlockMasks.FragmentDefault, //Collections - structs = CoreStructCollections.Default, - fieldDependencies = CoreFieldDependencies.Default, pragmas = CorePragmas.RaytracingBasic, defines = RaytracingSubsurfaceDefines, keywords = CoreKeywords.RaytracingGBufferForward, 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 2120c582a58..e38cb729c03 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 @@ -59,7 +59,7 @@ public virtual ScriptableObject GetMetadataObject() return hdMetadata; } - public sealed override void Setup(ref TargetSetupContext context) + public override void Setup(ref TargetSetupContext context) { context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath("c09e6e9062cbd5a48900c48a0c2ed1c2")); // HDSubTarget.cs context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath(subTargetAssetGuid)); 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 f6ff3102677..dd2f1689081 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 @@ -31,6 +31,12 @@ public LightingData lightingData protected override string renderType => HDRenderTypeTags.HDLitShader.ToString(); + public override void Setup(ref TargetSetupContext context) + { + context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath("aea3df556ea7e9b44855d1fff79fed53")); // LightingSubTarget.cs + base.Setup(ref context); + } + public override void GetPropertiesGUI(ref TargetPropertyGUIContext context, Action onChange, Action registerUndo) { var gui = new SubTargetPropertiesGUI(context, onChange, registerUndo, systemData, builtinData, lightingData); 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 1dce71f01f5..a9f3d626e8a 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 @@ -47,7 +47,12 @@ protected override string renderQueue // Maybe we should rename it custom forward pass include ? // protected virtual string postGraphInclude => null; - // TODO: put this method as sealed when the new pass system is done + public override void Setup(ref TargetSetupContext context) + { + context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath("f4df7e8f9b8c23648ae50cbca0221e47")); // SurfaceSubTarget.cs + base.Setup(ref context); + } + protected override IEnumerable EnumerateSubShaders() { yield return PostProcessSubShader(GetSubShaderDescriptor()); @@ -163,13 +168,10 @@ SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor passDescriptor.includes = finalIncludes; // Replace valid pixel blocks by automatic thing so we don't have to write them - // if (passDescriptor.displayName != "ForwardOnly") - { - var tmpCtx = new TargetActiveBlockContext(new List(), passDescriptor); - GetActiveBlocks(ref tmpCtx); - passDescriptor.validPixelBlocks = tmpCtx.activeBlocks.Where(b => b.shaderStage == ShaderStage.Fragment).ToArray(); - passDescriptor.validVertexBlocks = tmpCtx.activeBlocks.Where(b => b.shaderStage == ShaderStage.Vertex).ToArray(); - } + var tmpCtx = new TargetActiveBlockContext(new List(), passDescriptor); + GetActiveBlocks(ref tmpCtx); + passDescriptor.validPixelBlocks = tmpCtx.activeBlocks.Where(b => b.shaderStage == ShaderStage.Fragment).ToArray(); + passDescriptor.validVertexBlocks = tmpCtx.activeBlocks.Where(b => b.shaderStage == ShaderStage.Vertex).ToArray(); // Set default values for HDRP "surface" passes: if (passDescriptor.structs == null) 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 4bc0d2b0f64..b4e5e1ae81a 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 @@ -20,9 +20,6 @@ sealed partial class StackLitSubTarget : LightingSubTarget, ILegacyTarget, IRequ { public StackLitSubTarget() => displayName = "StackLit"; - // TODO: remove this line - public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/StackLit/ShaderGraph/StackLitPass.template"; - protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/StackLit/ShaderGraph/StackLitPass.template"; protected override string customInspector => "Rendering.HighDefinition.StackLitGUI"; protected override string subTargetAssetGuid => "5f7ba34a143e67647b202a662748dae3"; // StackLitSubTarget.cs @@ -58,123 +55,6 @@ protected override SubShaderDescriptor GetRaytracingSubShaderDescriptor() return descriptor; } - // TODO stacklit share pass - // protected override IEnumerable EnumerateSubShaders() - // { - // yield return SubShaders.StackLit; - // yield return SubShaders.StackLitRaytracing; - // } - - // Reference for GetFields - // ------------------------------------------- - // - // Properties (enables etc): - // - // ok+MFD -> material feature define: means we need a predicate, because we will transform it into a #define that match the material feature, shader_feature-defined, that the rest of the shader code uses. - // - // ok+MFD masterNode.baseParametrization --> even though we can just always transfer present fields (check with $SurfaceDescription.*) like specularcolor and metallic, - // we need to translate this into the _MATERIAL_FEATURE_SPECULAR_COLOR define. - // - // ok masterNode.energyConservingSpecular - // - // ~~~~ ok+MFD: these are almost all material features: - // masterNode.anisotropy - // masterNode.coat - // masterNode.coatNormal - // masterNode.dualSpecularLobe - // masterNode.dualSpecularLobeParametrization - // masterNode.capHazinessWrtMetallic -> not a material feature define, as such, we will create a combined predicate for the HazyGlossMaxDielectricF0 slot dependency - // instead of adding a #define in the template... - // masterNode.iridescence - // masterNode.subsurfaceScattering - // masterNode.transmission - // - // ~~~~ ...ok+MFD: these are all material features - // - // ok masterNode.receiveDecals - // ok masterNode.receiveSSR - // ok masterNode.geometricSpecularAA --> check, a way to combine predicates and/or exclude passes: TODOTODO What about WRITE_NORMAL_BUFFER passes ? (ie smoothness) - // ok masterNode.specularOcclusion --> no use for it though! see comments. - // - // ~~~~ ok+D: these require translation to defines also... - // - // masterNode.anisotropyForAreaLights - // masterNode.recomputeStackPerLight - // masterNode.shadeBaseUsingRefractedAngles - // masterNode.debug - - // Inputs: Most inputs don't need a specific predicate in addition to the "present field predicate", ie the $SurfaceDescription.*, - // but in some special cases we check connectivity to avoid processing the default value for nothing... - // (see specular occlusion with _MASKMAP and _BENTNORMALMAP in LitData, or _TANGENTMAP, _BENTNORMALMAP, etc. which act a bit like that - // although they also avoid sampling in that case, but default tiny texture map sampling isn't a big hit since they are all cached once - // a default "unityTexWhite" is sampled, it is cached for everyone defaulting to white...) - // - // ok+ means there's a specific additional predicate - // - // ok masterNode.BaseColorSlotId - // ok masterNode.NormalSlotId - // - // ok+ masterNode.BentNormalSlotId --> Dependency of the predicate on IsSlotConnected avoids processing even if the slots - // ok+ masterNode.TangentSlotId are always there so any pass that declares its use in PixelShaderSlots will have the field in SurfaceDescription, - // but it's not necessarily useful (if slot isnt connected, waste processing on potentially static expressions if - // shader compiler cant optimize...and even then, useless to have static override value for those.) - // - // TODOTODO: Note you could have the same argument for NormalSlot (which we dont exclude with a predicate). - // Also and anyways, the compiler is smart enough not to do the TS to WS matrix multiply on a (0,0,1) vector. - // - // ok+ masterNode.CoatNormalSlotId -> we already have a "material feature" coat normal map so can use that instead, although using that former, we assume the coat normal slot - // will be there, but it's ok, we can #ifdef the code on the material feature define, and use the $SurfaceDescription.CoatNormal predicate - // for the actual assignment, - // although for that one we could again - // use the "connected" condition like for tangent and bentnormal - // - // The following are all ok, no need beyond present field predicate, ie $SurfaceDescription.*, - // except special cases where noted - // - // ok masterNode.SubsurfaceMaskSlotId - // ok masterNode.ThicknessSlotId - // ok masterNode.DiffusionProfileHashSlotId - // ok masterNode.IridescenceMaskSlotId - // ok masterNode.IridescenceThicknessSlotId - // ok masterNode.SpecularColorSlotId - // ok masterNode.DielectricIorSlotId - // ok masterNode.MetallicSlotId - // ok masterNode.EmissionSlotId - // ok masterNode.SmoothnessASlotId - // ok masterNode.SmoothnessBSlotId - // ok+ masterNode.AmbientOcclusionSlotId -> defined a specific predicate, but not used, see StackLitData. - // ok masterNode.AlphaSlotId - // ok masterNode.AlphaClipThresholdSlotId - // ok masterNode.AnisotropyASlotId - // ok masterNode.AnisotropyBSlotId - // ok masterNode.SpecularAAScreenSpaceVarianceSlotId - // ok masterNode.SpecularAAThresholdSlotId - // ok masterNode.CoatSmoothnessSlotId - // ok masterNode.CoatIorSlotId - // ok masterNode.CoatThicknessSlotId - // ok masterNode.CoatExtinctionSlotId - // ok masterNode.LobeMixSlotId - // ok masterNode.HazinessSlotId - // ok masterNode.HazeExtentSlotId - // ok masterNode.HazyGlossMaxDielectricF0SlotId -> No need for a predicate, the needed predicate is the combined (capHazinessWrtMetallic + HazyGlossMaxDielectricF0) - // "leaking case": if the 2 are true, but we're not in metallic mode, the capHazinessWrtMetallic property is wrong, - // that means the master node is really misconfigured, spew an error, should never happen... - // If it happens, it's because we forgot UpdateNodeAfterDeserialization() call when modifying the capHazinessWrtMetallic or baseParametrization - // properties, maybe through debug etc. - // - // ok masterNode.DistortionSlotId -> Warning: peculiarly, instead of using $SurfaceDescription.Distortion and DistortionBlur, - // ok masterNode.DistortionBlurSlotId we do an #if (SHADERPASS == SHADERPASS_DISTORTION) in the template, instead of - // relying on other passed NOT to include the DistortionSlotId in their PixelShaderSlots!! - - // Other to deal with, and - // Common between Lit and StackLit: - // - // doubleSidedMode, alphaTest, receiveDecals, - // surfaceType, alphaMode, blendPreserveSpecular, transparencyFog, - // distortion, distortionMode, distortionDepthTest, - // sortPriority (int) - // geometricSpecularAA, energyConservingSpecular, specularOcclusion - public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); From 5075eaaa1bf31662ac2b405f3ba7aac047e7346a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Thu, 4 Jun 2020 19:03:29 +0200 Subject: [PATCH 21/30] Added target block context changes --- com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs | 2 +- .../Editor/Generation/Contexts/TargetActiveBlockContext.cs | 4 +++- .../Editor/Generation/Processors/Generator.cs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs b/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs index 9b508d1e496..70633485d30 100644 --- a/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs +++ b/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs @@ -634,7 +634,7 @@ public List GetActiveBlocksForAllActiveTargets() { // Get list of active Block types var currentBlocks = GetNodes(); - var context = new TargetActiveBlockContext(currentBlocks.Select(x => x.descriptor).ToList()); + var context = new TargetActiveBlockContext(currentBlocks.Select(x => x.descriptor).ToList(), null); foreach(var target in activeTargets) { target.GetActiveBlocks(ref context); diff --git a/com.unity.shadergraph/Editor/Generation/Contexts/TargetActiveBlockContext.cs b/com.unity.shadergraph/Editor/Generation/Contexts/TargetActiveBlockContext.cs index 355f4c54b6e..36fe7a7ca0e 100644 --- a/com.unity.shadergraph/Editor/Generation/Contexts/TargetActiveBlockContext.cs +++ b/com.unity.shadergraph/Editor/Generation/Contexts/TargetActiveBlockContext.cs @@ -7,11 +7,13 @@ internal class TargetActiveBlockContext { public List activeBlocks { get; private set; } public List currentBlocks { get; private set; } + public PassDescriptor? pass { get; private set; } - public TargetActiveBlockContext(List currentBlocks) + public TargetActiveBlockContext(List currentBlocks, PassDescriptor? pass) { activeBlocks = new List(); this.currentBlocks = currentBlocks; + this.pass = pass; } public void AddBlock(BlockFieldDescriptor block, bool conditional = true) diff --git a/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs b/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs index 68fd33a7be5..3c68a6421b8 100644 --- a/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs +++ b/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs @@ -240,7 +240,7 @@ void GenerateShaderPass(int targetIndex, PassDescriptor pass, ActiveFields activ if(m_OutputNode == null) { // Update supported block list for current target implementation - var activeBlockContext = new TargetActiveBlockContext(currentBlockDescriptors); + var activeBlockContext = new TargetActiveBlockContext(currentBlockDescriptors, pass); m_Targets[targetIndex].GetActiveBlocks(ref activeBlockContext); void ProcessStackForPass(ContextData contextData, BlockFieldDescriptor[] passBlockMask, From 89cd155278a1417a08c3ea5331e4dcbe3b31d988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Thu, 4 Jun 2020 19:27:05 +0200 Subject: [PATCH 22/30] Removed all the commented code --- .../Material/Eye/ShaderGraph/EyeSubTarget.cs | 289 ------ .../Fabric/ShaderGraph/FabricSubTarget.cs | 560 ----------- .../Hair/ShaderGraph/HairSubTarget.cs | 646 ------------- .../Lit/ShaderGraph/HDLitSubTarget.cs | 877 ------------------ .../Material/ShaderGraph/HDShaderPasses.cs | 491 +--------- .../StackLit/ShaderGraph/StackLitSubTarget.cs | 734 --------------- .../Unlit/ShaderGraph/HDUnlitSubTarget.cs | 569 ------------ 7 files changed, 25 insertions(+), 4141 deletions(-) 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 6bbcf5c1cdc..c7e67cc6d4e 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 @@ -72,294 +72,5 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL protected override int ComputeMaterialNeedsUpdateHash() => base.ComputeMaterialNeedsUpdateHash() * 23 + eyeData.subsurfaceScattering.GetHashCode(); - -// #region SubShaders -// static class SubShaders -// { -// public static SubShaderDescriptor Eye = new SubShaderDescriptor() -// { -// pipelineTag = HDRenderPipeline.k_ShaderTagName, -// generatesPreview = true, -// passes = new PassCollection -// { -// { EyePasses.ShadowCaster }, -// { EyePasses.META }, -// { EyePasses.SceneSelection }, -// { EyePasses.DepthForwardOnly }, -// { EyePasses.MotionVectors }, -// { EyePasses.ForwardOnly }, -// }, -// }; -// } -// #endregion - -// #region Passes -// public static class EyePasses -// { -// public static PassDescriptor META = new PassDescriptor() -// { -// // Definition -// displayName = "META", -// referenceName = "SHADERPASS_LIGHT_TRANSPORT", -// lightMode = "META", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validPixelBlocks = EyeBlockMasks.FragmentMETA, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.Meta, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.Meta, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = CoreKeywords.HDBase, -// includes = EyeIncludes.Meta, -// }; - -// public static PassDescriptor ShadowCaster = new PassDescriptor() -// { -// // Definition -// displayName = "ShadowCaster", -// referenceName = "SHADERPASS_SHADOWS", -// lightMode = "ShadowCaster", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = EyeBlockMasks.FragmentAlphaDepth, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.BlendShadowCaster, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = CoreKeywords.HDBase, -// includes = EyeIncludes.DepthOnly, -// }; - -// public static PassDescriptor SceneSelection = new PassDescriptor() -// { -// // Definition -// displayName = "SceneSelectionPass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "SceneSelectionPass", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = EyeBlockMasks.FragmentAlphaDepth, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.SceneSelection, -// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, -// defines = CoreDefines.SceneSelection, -// keywords = CoreKeywords.HDBase, -// includes = EyeIncludes.DepthOnly, -// }; - -// public static PassDescriptor DepthForwardOnly = new PassDescriptor() -// { -// // Definition -// displayName = "DepthForwardOnly", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "DepthForwardOnly", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = EyeBlockMasks.FragmentDepthMotionVectors, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.DepthOnly, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.DepthMotionVectors, -// keywords = CoreKeywords.DepthMotionVectorsNoNormal, -// includes = EyeIncludes.DepthOnly, -// }; - -// public static PassDescriptor MotionVectors = new PassDescriptor() -// { -// // Definition -// displayName = "MotionVectors", -// referenceName = "SHADERPASS_MOTION_VECTORS", -// lightMode = "MotionVectors", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = EyeBlockMasks.FragmentDepthMotionVectors, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.MotionVectors, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.DepthMotionVectors, -// keywords = CoreKeywords.DepthMotionVectorsNoNormal, -// includes = EyeIncludes.MotionVectors, -// }; - -// public static PassDescriptor ForwardOnly = new PassDescriptor() -// { -// // Definition -// displayName = "ForwardOnly", -// referenceName = "SHADERPASS_FORWARD", -// lightMode = "ForwardOnly", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = EyeBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.Forward, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.Forward, -// keywords = CoreKeywords.Forward, -// includes = EyeIncludes.ForwardOnly, -// }; -// } -// #endregion - -// #region BlockMasks -// static class EyeBlockMasks -// { -// public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// BlockFields.SurfaceDescription.NormalTS, -// HDBlockFields.SurfaceDescription.IrisNormal, -// BlockFields.SurfaceDescription.Smoothness, -// HDBlockFields.SurfaceDescription.IOR, -// BlockFields.SurfaceDescription.Occlusion, -// HDBlockFields.SurfaceDescription.Mask, -// HDBlockFields.SurfaceDescription.DiffusionProfileHash, -// HDBlockFields.SurfaceDescription.SubsurfaceMask, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// }; - -// public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// BlockFields.SurfaceDescription.NormalTS, -// HDBlockFields.SurfaceDescription.IrisNormal, -// BlockFields.SurfaceDescription.Smoothness, -// HDBlockFields.SurfaceDescription.IOR, -// BlockFields.SurfaceDescription.Occlusion, -// HDBlockFields.SurfaceDescription.Mask, -// HDBlockFields.SurfaceDescription.DiffusionProfileHash, -// HDBlockFields.SurfaceDescription.SubsurfaceMask, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.BakedGI, -// HDBlockFields.SurfaceDescription.BakedBackGI, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; -// } -// #endregion - -// #region Includes -// static class EyeIncludes -// { -// const string kEye = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl"; - -// public static IncludeCollection Common = new IncludeCollection -// { -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, -// { kEye, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// }; - -// public static IncludeCollection Meta = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection DepthOnly = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection MotionVectors = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection ForwardOnly = new IncludeCollection -// { -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, -// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, -// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, -// { kEye, IncludeLocation.Pregraph }, -// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, -// }; -// } -// #endregion } } 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 d8147983e52..ea99a65fa80 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 @@ -88,565 +88,5 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL protected override int ComputeMaterialNeedsUpdateHash() => base.ComputeMaterialNeedsUpdateHash() * 23 + fabricData.subsurfaceScattering.GetHashCode(); - -// #region SubShaders -// static class SubShaders -// { -// public static SubShaderDescriptor Fabric = new SubShaderDescriptor() -// { -// pipelineTag = HDRenderPipeline.k_ShaderTagName, -// generatesPreview = true, -// passes = new PassCollection -// { -// { FabricPasses.ShadowCaster }, -// { FabricPasses.META }, -// { FabricPasses.SceneSelection }, -// { FabricPasses.DepthForwardOnly }, -// { FabricPasses.MotionVectors }, -// { FabricPasses.TransparentDepthPrepass, new FieldCondition[]{ -// new FieldCondition(HDFields.TransparentDepthPrePass, true), -// new FieldCondition(HDFields.DisableSSRTransparent, true) }}, -// { FabricPasses.TransparentDepthPrepass, new FieldCondition[]{ -// new FieldCondition(HDFields.TransparentDepthPrePass, true), -// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, -// { FabricPasses.TransparentDepthPrepass, new FieldCondition[]{ -// new FieldCondition(HDFields.TransparentDepthPrePass, false), -// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, -// { FabricPasses.ForwardOnly }, -// { FabricPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, -// }, -// }; - -// public static SubShaderDescriptor FabricRaytracing = new SubShaderDescriptor() -// { -// pipelineTag = HDRenderPipeline.k_ShaderTagName, -// generatesPreview = false, -// passes = new PassCollection -// { -// { FabricPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, -// { FabricPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, -// { FabricPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, -// { FabricPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, -// { FabricPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, -// }, -// }; -// } -// #endregion - -// #region Passes -// public static class FabricPasses -// { -// public static PassDescriptor META = new PassDescriptor() -// { -// // Definition -// displayName = "META", -// referenceName = "SHADERPASS_LIGHT_TRANSPORT", -// lightMode = "META", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validPixelBlocks = FabricBlockMasks.FragmentMETA, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.Meta, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.Meta, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = CoreKeywords.HDBase, -// includes = FabricIncludes.Meta, -// }; - -// public static PassDescriptor ShadowCaster = new PassDescriptor() -// { -// // Definition -// displayName = "ShadowCaster", -// referenceName = "SHADERPASS_SHADOWS", -// lightMode = "ShadowCaster", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentAlphaDepth, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.BlendShadowCaster, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = CoreKeywords.HDBase, -// includes = FabricIncludes.DepthOnly, -// }; - -// public static PassDescriptor SceneSelection = new PassDescriptor() -// { -// // Definition -// displayName = "SceneSelectionPass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "SceneSelectionPass", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentAlphaDepth, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.ShadowCaster, -// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, -// defines = CoreDefines.SceneSelection, -// keywords = CoreKeywords.HDBase, -// includes = FabricIncludes.DepthOnly, -// }; - -// public static PassDescriptor DepthForwardOnly = new PassDescriptor() -// { -// // Definition -// displayName = "DepthForwardOnly", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "DepthForwardOnly", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentDepthMotionVectors, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.DepthOnly, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.DepthMotionVectors, -// keywords = CoreKeywords.DepthMotionVectorsNoNormal, -// includes = FabricIncludes.DepthOnly, -// }; - -// public static PassDescriptor MotionVectors = new PassDescriptor() -// { -// // Definition -// displayName = "MotionVectors", -// referenceName = "SHADERPASS_MOTION_VECTORS", -// lightMode = "MotionVectors", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentDepthMotionVectors, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.MotionVectors, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.DepthMotionVectors, -// keywords = CoreKeywords.DepthMotionVectorsNoNormal, -// includes = FabricIncludes.MotionVectors, -// }; - -// public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() -// { -// // Definition -// displayName = "TransparentDepthPrepass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "TransparentDepthPrepass", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentTransparentDepthPrepass, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.TransparentDepthPrePass, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.TransparentDepthPrepass, -// keywords = CoreKeywords.HDBase, -// includes = FabricIncludes.DepthOnly, -// }; - -// public static PassDescriptor ForwardOnly = new PassDescriptor() -// { -// // Definition -// displayName = "ForwardOnly", -// referenceName = "SHADERPASS_FORWARD", -// lightMode = "ForwardOnly", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.Forward, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.Forward, -// keywords = CoreKeywords.Forward, -// includes = FabricIncludes.ForwardOnly, -// }; - -// public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() -// { -// // Definition -// displayName = "TransparentDepthPostpass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "TransparentDepthPostpass", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentTransparentDepthPostpass, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.TransparentDepthPostPass, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.ShaderGraphRaytracingHigh, -// keywords = CoreKeywords.HDBase, -// includes = FabricIncludes.DepthOnly, -// }; - -// public static PassDescriptor RaytracingIndirect = new PassDescriptor() -// { -// // Definition -// displayName = "IndirectDXR", -// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", -// lightMode = "IndirectDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = FabricDefines.RaytracingIndirect, -// keywords = CoreKeywords.RaytracingIndirect, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingIndirect }, -// }; - -// public static PassDescriptor RaytracingVisibility = new PassDescriptor() -// { -// // Definition -// displayName = "VisibilityDXR", -// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", -// lightMode = "VisibilityDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = FabricDefines.RaytracingVisibility, -// keywords = CoreKeywords.RaytracingVisiblity, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingVisibility }, -// }; - -// public static PassDescriptor RaytracingForward = new PassDescriptor() -// { -// // Definition -// displayName = "ForwardDXR", -// referenceName = "SHADERPASS_RAYTRACING_FORWARD", -// lightMode = "ForwardDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = FabricDefines.RaytracingForward, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingForward }, -// }; - -// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() -// { -// // Definition -// displayName = "GBufferDXR", -// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", -// lightMode = "GBufferDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = FabricDefines.RaytracingGBuffer, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RayTracingGBuffer }, -// }; - -// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() -// { -// //Definition -// displayName = "SubSurfaceDXR", -// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", -// lightMode = "SubSurfaceDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// //Port mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = FabricBlockMasks.FragmentForward, - -// //Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = FabricDefines.RaytracingGBuffer, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Fabric, HDFields.ShaderPass.RaytracingSubSurface }, -// }; -// } -// #endregion - -// #region BlockMasks -// static class FabricBlockMasks -// { -// public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Occlusion, -// BlockFields.SurfaceDescription.Specular, -// HDBlockFields.SurfaceDescription.DiffusionProfileHash, -// HDBlockFields.SurfaceDescription.SubsurfaceMask, -// HDBlockFields.SurfaceDescription.Thickness, -// HDBlockFields.SurfaceDescription.Tangent, -// HDBlockFields.SurfaceDescription.Anisotropy, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// }; - -// public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, -// HDBlockFields.SurfaceDescription.DepthOffset, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// BlockFields.SurfaceDescription.Smoothness, -// }; - -// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// HDBlockFields.SurfaceDescription.BentNormal, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Occlusion, -// BlockFields.SurfaceDescription.Specular, -// HDBlockFields.SurfaceDescription.DiffusionProfileHash, -// HDBlockFields.SurfaceDescription.SubsurfaceMask, -// HDBlockFields.SurfaceDescription.Thickness, -// HDBlockFields.SurfaceDescription.Tangent, -// HDBlockFields.SurfaceDescription.Anisotropy, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.BakedGI, -// HDBlockFields.SurfaceDescription.BakedBackGI, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; -// } -// #endregion - -// #region Defines -// static class FabricDefines -// { -// public static DefineCollection RaytracingForward = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 0 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; - -// public static DefineCollection RaytracingIndirect = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; - -// public static DefineCollection RaytracingVisibility = new DefineCollection -// { -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// }; - -// public static DefineCollection RaytracingGBuffer = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// }; - -// public static DefineCollection RaytracingPathTracing = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 0 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; -// } -// #endregion - -// #region Includes - // static class FabricIncludes - // { - // const string kFabric = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/Fabric.hlsl"; - - // public static IncludeCollection Common = new IncludeCollection - // { - // { CoreIncludes.CorePregraph }, - // { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - // { kFabric, IncludeLocation.Pregraph }, - // { CoreIncludes.CoreUtility }, - // { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - // { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - // }; - - // public static IncludeCollection Meta = new IncludeCollection - // { - // { Common }, - // { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, - // }; - - // public static IncludeCollection DepthOnly = new IncludeCollection - // { - // { Common }, - // { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, - // }; - - // public static IncludeCollection MotionVectors = new IncludeCollection - // { - // { Common }, - // { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, - // }; - - // public static IncludeCollection ForwardOnly = new IncludeCollection - // { - // { CoreIncludes.CorePregraph }, - // { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, - // { CoreIncludes.kLighting, IncludeLocation.Pregraph }, - // { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, - // { kFabric, IncludeLocation.Pregraph }, - // { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, - // { CoreIncludes.CoreUtility }, - // { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - // { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, - // { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, - // }; - // } -// #endregion } } 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 ae6f463826d..61b8cede707 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 @@ -83,651 +83,5 @@ protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockL blockList.AddPropertyBlock(new SurfaceOptionPropertyBlock(SurfaceOptionPropertyBlock.Features.Lit)); blockList.AddPropertyBlock(new HairAdvancedOptionsPropertyBlock(hairData)); } - -// #region SubShaders -// static class SubShaders -// { -// public static SubShaderDescriptor Hair = new SubShaderDescriptor() -// { -// pipelineTag = HDRenderPipeline.k_ShaderTagName, -// generatesPreview = true, -// passes = new PassCollection -// { -// { HairPasses.ShadowCaster }, -// { HairPasses.META }, -// { HairPasses.SceneSelection }, -// { HairPasses.DepthForwardOnly }, -// { HairPasses.MotionVectors }, -// { HairPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, -// { HairPasses.TransparentDepthPrepass, new FieldCondition[]{ -// new FieldCondition(HDFields.TransparentDepthPrePass, true), -// new FieldCondition(HDFields.DisableSSRTransparent, true) }}, -// { HairPasses.TransparentDepthPrepass, new FieldCondition[]{ -// new FieldCondition(HDFields.TransparentDepthPrePass, true), -// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, -// { HairPasses.TransparentDepthPrepass, new FieldCondition[]{ -// new FieldCondition(HDFields.TransparentDepthPrePass, false), -// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, -// { HairPasses.ForwardOnly }, -// { HairPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, -// }, -// }; - -// public static SubShaderDescriptor HairRaytracing = new SubShaderDescriptor() -// { -// pipelineTag = HDRenderPipeline.k_ShaderTagName, -// generatesPreview = false, -// passes = new PassCollection -// { -// { HairPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, -// { HairPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, -// { HairPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, -// { HairPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, -// { HairPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, -// }, -// }; -// } -// #endregion - -// #region Passes -// public static class HairPasses -// { -// public static PassDescriptor META = new PassDescriptor() -// { -// // Definition -// displayName = "META", -// referenceName = "SHADERPASS_LIGHT_TRANSPORT", -// lightMode = "META", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validPixelBlocks = HairBlockMasks.FragmentMETA, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.Meta, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.Meta, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = CoreKeywords.HDBase, -// includes = HairIncludes.Meta, -// }; - -// public static PassDescriptor ShadowCaster = new PassDescriptor() -// { -// // Definition -// displayName = "ShadowCaster", -// referenceName = "SHADERPASS_SHADOWS", -// lightMode = "ShadowCaster", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentShadowCaster, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.BlendShadowCaster, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = CoreKeywords.HDBase, -// includes = HairIncludes.DepthOnly, -// }; - -// public static PassDescriptor SceneSelection = new PassDescriptor() -// { -// // Definition -// displayName = "SceneSelectionPass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "SceneSelectionPass", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentAlphaDepth, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.SceneSelection, -// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, -// defines = CoreDefines.SceneSelection, -// keywords = CoreKeywords.HDBase, -// includes = HairIncludes.DepthOnly, -// }; - -// public static PassDescriptor DepthForwardOnly = new PassDescriptor() -// { -// // Definition -// displayName = "DepthForwardOnly", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "DepthForwardOnly", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentDepthMotionVectors, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.DepthOnly, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.DepthMotionVectors, -// keywords = CoreKeywords.DepthMotionVectorsNoNormal, -// includes = HairIncludes.DepthOnly, -// }; - -// public static PassDescriptor MotionVectors = new PassDescriptor() -// { -// // Definition -// displayName = "MotionVectors", -// referenceName = "SHADERPASS_MOTION_VECTORS", -// lightMode = "MotionVectors", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentDepthMotionVectors, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = HairRenderStates.MotionVectors, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.DepthMotionVectors, -// keywords = CoreKeywords.DepthMotionVectorsNoNormal, -// includes = HairIncludes.MotionVectors, -// }; - -// public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() -// { -// // Definition -// displayName = "TransparentDepthPrepass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "TransparentDepthPrepass", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentTransparentDepthPrepass, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.TransparentDepthPrePass, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.TransparentDepthPrepass, -// keywords = CoreKeywords.HDBase, -// includes = HairIncludes.DepthOnly, -// }; - -// public static PassDescriptor TransparentBackface = new PassDescriptor() -// { -// // Definition -// displayName = "TransparentBackface", -// referenceName = "SHADERPASS_FORWARD", -// lightMode = "TransparentBackface", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentTransparentBackface, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitMinimal, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.TransparentBackface, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.Forward, -// keywords = CoreKeywords.Forward, -// includes = HairIncludes.ForwardOnly, -// }; - -// public static PassDescriptor ForwardOnly = new PassDescriptor() -// { -// // Definition -// displayName = "ForwardOnly", -// referenceName = "SHADERPASS_FORWARD", -// lightMode = "ForwardOnly", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.ForwardColorMask, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.Forward, -// keywords = CoreKeywords.Forward, -// includes = HairIncludes.ForwardOnly, -// }; - -// public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() -// { -// // Definition -// displayName = "TransparentDepthPostpass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "TransparentDepthPostpass", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentTransparentDepthPostpass, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.TransparentDepthPostPass, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.ShaderGraphRaytracingHigh, -// keywords = CoreKeywords.HDBase, -// includes = HairIncludes.DepthOnly, -// }; - -// public static PassDescriptor RaytracingIndirect = new PassDescriptor() -// { -// // Definition -// displayName = "IndirectDXR", -// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", -// lightMode = "IndirectDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = HairDefines.RaytracingIndirect, -// keywords = CoreKeywords.RaytracingIndirect, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingIndirect }, -// }; - -// public static PassDescriptor RaytracingVisibility = new PassDescriptor() -// { -// // Definition -// displayName = "VisibilityDXR", -// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", -// lightMode = "VisibilityDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// keywords = CoreKeywords.RaytracingVisiblity, -// defines = HairDefines.RaytracingVisibility, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingVisibility }, -// }; - -// public static PassDescriptor RaytracingForward = new PassDescriptor() -// { -// // Definition -// displayName = "ForwardDXR", -// referenceName = "SHADERPASS_RAYTRACING_FORWARD", -// lightMode = "ForwardDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = HairDefines.RaytracingForward, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingForward }, -// }; - -// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() -// { -// // Definition -// displayName = "GBufferDXR", -// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", -// lightMode = "GBufferDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = HairDefines.RaytracingGBuffer, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RayTracingGBuffer }, -// }; - -// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() -// { -// //Definition -// displayName = "SubSurfaceDXR", -// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", -// lightMode = "SubSurfaceDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = HairBlockMasks.FragmentForward, - -// //Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = HairDefines.RaytracingGBuffer, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Hair, HDFields.ShaderPass.RaytracingSubSurface }, -// }; -// } -// #endregion - -// #region BlockMasks -// static class HairBlockMasks -// { -// public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// HDBlockFields.SurfaceDescription.BentNormal, -// HDBlockFields.SurfaceDescription.HairStrandDirection, -// HDBlockFields.SurfaceDescription.Transmittance, -// HDBlockFields.SurfaceDescription.RimTransmissionIntensity, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Occlusion, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, -// HDBlockFields.SurfaceDescription.SpecularAAThreshold, -// HDBlockFields.SurfaceDescription.SpecularTint, -// HDBlockFields.SurfaceDescription.SpecularShift, -// HDBlockFields.SurfaceDescription.SecondarySpecularTint, -// HDBlockFields.SurfaceDescription.SecondarySmoothness, -// HDBlockFields.SurfaceDescription.SecondarySpecularShift, -// }; - -// public static BlockFieldDescriptor[] FragmentShadowCaster = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, -// HDBlockFields.SurfaceDescription.DepthOffset, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// BlockFields.SurfaceDescription.Smoothness, -// }; - -// public static BlockFieldDescriptor[] FragmentTransparentBackface = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// HDBlockFields.SurfaceDescription.BentNormal, -// HDBlockFields.SurfaceDescription.HairStrandDirection, -// HDBlockFields.SurfaceDescription.Transmittance, -// HDBlockFields.SurfaceDescription.RimTransmissionIntensity, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Occlusion, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, -// HDBlockFields.SurfaceDescription.SpecularAAThreshold, -// HDBlockFields.SurfaceDescription.SpecularTint, -// HDBlockFields.SurfaceDescription.SpecularShift, -// HDBlockFields.SurfaceDescription.SecondarySpecularTint, -// HDBlockFields.SurfaceDescription.SecondarySmoothness, -// HDBlockFields.SurfaceDescription.SecondarySpecularShift, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// HDBlockFields.SurfaceDescription.BentNormal, -// HDBlockFields.SurfaceDescription.HairStrandDirection, -// HDBlockFields.SurfaceDescription.Transmittance, -// HDBlockFields.SurfaceDescription.RimTransmissionIntensity, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Occlusion, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, -// HDBlockFields.SurfaceDescription.SpecularAAThreshold, -// HDBlockFields.SurfaceDescription.SpecularTint, -// HDBlockFields.SurfaceDescription.SpecularShift, -// HDBlockFields.SurfaceDescription.SecondarySpecularTint, -// HDBlockFields.SurfaceDescription.SecondarySmoothness, -// HDBlockFields.SurfaceDescription.SecondarySpecularShift, -// HDBlockFields.SurfaceDescription.BakedGI, -// HDBlockFields.SurfaceDescription.BakedBackGI, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; -// } -// #endregion - -// #region RenderStates -// static class HairRenderStates -// { -// public static RenderStateCollection MotionVectors = new RenderStateCollection -// { -// { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, -// { RenderState.Stencil(new StencilDescriptor() -// { -// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, -// Ref = CoreRenderStates.Uniforms.stencilRefMV, -// Comp = "Always", -// Pass = "Replace", -// }) }, -// }; -// } -// #endregion - -// #region Defines -// static class HairDefines -// { -// public static DefineCollection RaytracingForward = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 0 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; - -// public static DefineCollection RaytracingIndirect = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; - -// public static DefineCollection RaytracingVisibility = new DefineCollection -// { -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// }; - -// public static DefineCollection RaytracingGBuffer = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// }; - -// public static DefineCollection RaytracingPathTracing = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 0 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; -// } -// #endregion - -// #region Includes -// static class HairIncludes -// { -// public static IncludeCollection Common = new IncludeCollection -// { -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, -// { CoreIncludes.kHair, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// }; - -// public static IncludeCollection Meta = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection DepthOnly = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection MotionVectors = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection ForwardOnly = new IncludeCollection -// { -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, -// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, -// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, -// { CoreIncludes.kHair, IncludeLocation.Pregraph }, -// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, -// }; -// } -// #endregion } } 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 7269d7a5660..74b7fe3ccd2 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 @@ -167,882 +167,5 @@ protected override int ComputeMaterialNeedsUpdateHash() return hash; } - -// #region SubShaders -// static class SubShaders -// { -// public static SubShaderDescriptor Lit = new SubShaderDescriptor() -// { -// pipelineTag = HDRenderPipeline.k_ShaderTagName, -// generatesPreview = true, -// passes = new PassCollection -// { -// { LitPasses.ShadowCaster }, -// { LitPasses.META }, -// { LitPasses.SceneSelection }, -// { LitPasses.DepthOnly }, -// { LitPasses.GBuffer }, -// { LitPasses.MotionVectors }, -// { LitPasses.DistortionVectors, new FieldCondition(HDFields.TransparentDistortion, true) }, -// { LitPasses.TransparentBackface, new FieldCondition(HDFields.TransparentBackFace, true) }, -// { LitPasses.TransparentDepthPrepass, new FieldCondition[]{ -// new FieldCondition(HDFields.TransparentDepthPrePass, true), -// new FieldCondition(HDFields.DisableSSRTransparent, true) }}, -// { LitPasses.TransparentDepthPrepass, new FieldCondition[]{ -// new FieldCondition(HDFields.TransparentDepthPrePass, true), -// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, -// { LitPasses.TransparentDepthPrepass, new FieldCondition[]{ -// new FieldCondition(HDFields.TransparentDepthPrePass, false), -// new FieldCondition(HDFields.DisableSSRTransparent, false) }}, -// { LitPasses.Forward }, -// { LitPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, -// { LitPasses.RayTracingPrepass, new FieldCondition(HDFields.RayTracing, true) }, -// }, -// }; - -// public static SubShaderDescriptor LitRaytracing = new SubShaderDescriptor() -// { -// pipelineTag = HDRenderPipeline.k_ShaderTagName, -// generatesPreview = false, -// passes = new PassCollection -// { -// { LitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, -// { LitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, -// { LitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, -// { LitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, -// { LitPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, -// { LitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, -// }, -// }; -// } -// #endregion - -// #region Passes -// public static class LitPasses -// { -// public static PassDescriptor GBuffer = new PassDescriptor() -// { -// // Definition -// displayName = "GBuffer", -// referenceName = "SHADERPASS_GBUFFER", -// lightMode = "GBuffer", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitMinimal, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = LitRenderStates.GBuffer, -// pragmas = CorePragmas.DotsInstancedInV1AndV2, -// defines = CoreDefines.ShaderGraphRaytracingHigh, -// keywords = LitKeywords.GBuffer, -// includes = LitIncludes.GBuffer, - -// virtualTextureFeedback = true, -// }; - -// // public static PassDescriptor META = new PassDescriptor() -// // { -// // // Definition -// // displayName = "META", -// // referenceName = "SHADERPASS_LIGHT_TRANSPORT", -// // lightMode = "META", -// // useInPreview = false, - -// // // Template -// // passTemplatePath = passTemplatePath, -// // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // // Port Mask -// // validPixelBlocks = LitBlockMasks.FragmentMeta, - -// // // Collections -// // structs = CoreStructCollections.Default, -// // requiredFields = CoreRequiredFields.Meta, -// // fieldDependencies = CoreFieldDependencies.Default, -// // renderStates = CoreRenderStates.Meta, -// // pragmas = CorePragmas.DotsInstancedInV1AndV2, -// // defines = CoreDefines.ShaderGraphRaytracingHigh, -// // keywords = CoreKeywords.HDBase, -// // includes = LitIncludes.Meta, -// // }; - -// // public static PassDescriptor ShadowCaster = new PassDescriptor() -// // { -// // // Definition -// // displayName = "ShadowCaster", -// // referenceName = "SHADERPASS_SHADOWS", -// // lightMode = "ShadowCaster", -// // useInPreview = false, - -// // // Template -// // passTemplatePath = passTemplatePath, -// // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // // Port Mask -// // validVertexBlocks = CoreBlockMasks.Vertex, -// // validPixelBlocks = LitBlockMasks.FragmentShadowCaster, - -// // // Collections -// // structs = CoreStructCollections.Default, -// // fieldDependencies = CoreFieldDependencies.Default, -// // renderStates = CoreRenderStates.BlendShadowCaster, -// // pragmas = CorePragmas.DotsInstancedInV1AndV2, -// // defines = CoreDefines.ShaderGraphRaytracingHigh, -// // keywords = CoreKeywords.HDBase, -// // includes = LitIncludes.DepthOnly, -// // }; - -// // public static PassDescriptor SceneSelection = new PassDescriptor() -// // { -// // // Definition -// // displayName = "SceneSelectionPass", -// // referenceName = "SHADERPASS_DEPTH_ONLY", -// // lightMode = "SceneSelectionPass", -// // useInPreview = false, - -// // // Template -// // passTemplatePath = passTemplatePath, -// // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // // Port Mask -// // validVertexBlocks = CoreBlockMasks.Vertex, -// // validPixelBlocks = LitBlockMasks.FragmentSceneSelection, - -// // // Collections -// // structs = CoreStructCollections.Default, -// // fieldDependencies = CoreFieldDependencies.Default, -// // renderStates = CoreRenderStates.SceneSelection, -// // pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, -// // defines = CoreDefines.SceneSelection, -// // keywords = CoreKeywords.HDBase, -// // includes = LitIncludes.DepthOnly, -// // }; - -// public static PassDescriptor DepthOnly = new PassDescriptor() -// { -// // Definition -// displayName = "DepthOnly", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "DepthOnly", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentDepthMotionVectors, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.DepthOnly, -// pragmas = CorePragmas.DotsInstancedInV1AndV2, -// defines = CoreDefines.ShaderGraphRaytracingHigh, -// keywords = LitKeywords.DepthMotionVectors, -// includes = LitIncludes.DepthOnly, -// }; - -// public static PassDescriptor MotionVectors = new PassDescriptor() -// { -// // Definition -// displayName = "MotionVectors", -// referenceName = "SHADERPASS_MOTION_VECTORS", -// lightMode = "MotionVectors", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentDepthMotionVectors, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.MotionVectors, -// pragmas = CorePragmas.DotsInstancedInV1AndV2, -// defines = CoreDefines.ShaderGraphRaytracingHigh, -// keywords = LitKeywords.DepthMotionVectors, -// includes = LitIncludes.MotionVectors, -// }; - -// public static PassDescriptor DistortionVectors = new PassDescriptor() -// { -// // Definition -// displayName = "DistortionVectors", -// referenceName = "SHADERPASS_DISTORTION", -// lightMode = "DistortionVectors", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentDistortion, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = LitRenderStates.Distortion, -// pragmas = CorePragmas.DotsInstancedInV1AndV2, -// defines = CoreDefines.ShaderGraphRaytracingHigh, -// keywords = CoreKeywords.HDBase, -// includes = LitIncludes.Distortion, -// }; - -// public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() -// { -// // Definition -// displayName = "TransparentDepthPrepass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "TransparentDepthPrepass", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentTransparentDepthPrepass, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.TransparentDepthPrePass, -// pragmas = CorePragmas.DotsInstancedInV1AndV2, -// defines = CoreDefines.TransparentDepthPrepass, -// keywords = CoreKeywords.HDBase, -// includes = LitIncludes.DepthOnly, -// }; - -// public static PassDescriptor TransparentBackface = new PassDescriptor() -// { -// // Definition -// displayName = "TransparentBackface", -// referenceName = "SHADERPASS_FORWARD", -// lightMode = "TransparentBackface", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentTransparentBackface, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.TransparentBackface, -// pragmas = CorePragmas.DotsInstancedInV1AndV2, -// defines = CoreDefines.Forward, -// keywords = CoreKeywords.Forward, -// includes = LitIncludes.Forward, -// }; - -// public static PassDescriptor Forward = new PassDescriptor() -// { -// // Definition -// displayName = "Forward", -// referenceName = "SHADERPASS_FORWARD", -// lightMode = "Forward", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitMinimal, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.ForwardColorMask, -// pragmas = CorePragmas.DotsInstancedInV1AndV2, -// defines = CoreDefines.Forward, -// keywords = CoreKeywords.Forward, -// includes = LitIncludes.Forward, - -// virtualTextureFeedback = true, -// }; - -// public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() -// { -// // Definition -// displayName = "TransparentDepthPostpass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "TransparentDepthPostpass", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentTransparentDepthPostpass, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.TransparentDepthPostPass, -// pragmas = CorePragmas.DotsInstancedInV1AndV2, -// defines = CoreDefines.ShaderGraphRaytracingHigh, -// keywords = CoreKeywords.HDBase, -// includes = LitIncludes.DepthOnly, -// }; - -// public static PassDescriptor RayTracingPrepass = new PassDescriptor() -// { -// // Definition -// displayName = "RayTracingPrepass", -// referenceName = "SHADERPASS_CONSTANT", -// lightMode = "RayTracingPrepass", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentRayTracingPrepass, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = LitRenderStates.RayTracingPrepass, -// pragmas = LitPragmas.RaytracingBasic, -// defines = CoreDefines.ShaderGraphRaytracingHigh, -// keywords = CoreKeywords.HDBase, -// includes = LitIncludes.RayTracingPrepass, -// }; - -// public static PassDescriptor RaytracingIndirect = new PassDescriptor() -// { -// // Definition -// displayName = "IndirectDXR", -// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", -// lightMode = "IndirectDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = LitDefines.RaytracingIndirect, -// keywords = CoreKeywords.RaytracingIndirect, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingIndirect }, -// }; - -// public static PassDescriptor RaytracingVisibility = new PassDescriptor() -// { -// // Definition -// displayName = "VisibilityDXR", -// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", -// lightMode = "VisibilityDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = LitDefines.RaytracingVisibility, -// includes = CoreIncludes.Raytracing, -// keywords = CoreKeywords.RaytracingVisiblity, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingVisibility }, -// }; - -// public static PassDescriptor RaytracingForward = new PassDescriptor() -// { -// // Definition -// displayName = "ForwardDXR", -// referenceName = "SHADERPASS_RAYTRACING_FORWARD", -// lightMode = "ForwardDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = LitDefines.RaytracingForward, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingForward }, -// }; - -// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() -// { -// // Definition -// displayName = "GBufferDXR", -// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", -// lightMode = "GBufferDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = LitDefines.RaytracingGBuffer, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RayTracingGBuffer }, -// }; - -// public static PassDescriptor RaytracingPathTracing = new PassDescriptor() -// { -// //Definition -// displayName = "PathTracingDXR", -// referenceName = "SHADERPASS_PATH_TRACING", -// lightMode = "PathTracingDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// //Port mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentDefault, - -// //Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = LitDefines.RaytracingPathTracing, -// keywords = CoreKeywords.HDBaseNoCrossFade, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingPathTracing }, -// }; - -// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() -// { -// //Definition -// displayName = "SubSurfaceDXR", -// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", -// lightMode = "SubSurfaceDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// //Port mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = LitBlockMasks.FragmentDefault, - -// //Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = LitDefines.RaytracingGBuffer, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Lit, HDFields.ShaderPass.RaytracingSubSurface }, -// }; -// } -// #endregion - -// #region BlockMasks -// static class LitBlockMasks -// { -// public static BlockFieldDescriptor[] FragmentDefault = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// HDBlockFields.SurfaceDescription.BentNormal, -// HDBlockFields.SurfaceDescription.Tangent, -// HDBlockFields.SurfaceDescription.SubsurfaceMask, -// HDBlockFields.SurfaceDescription.Thickness, -// HDBlockFields.SurfaceDescription.DiffusionProfileHash, -// HDBlockFields.SurfaceDescription.IridescenceMask, -// HDBlockFields.SurfaceDescription.IridescenceThickness, -// BlockFields.SurfaceDescription.Specular, -// HDBlockFields.SurfaceDescription.CoatMask, -// BlockFields.SurfaceDescription.Metallic, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Occlusion, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.Anisotropy, -// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, -// HDBlockFields.SurfaceDescription.SpecularAAThreshold, -// HDBlockFields.SurfaceDescription.RefractionIndex, -// HDBlockFields.SurfaceDescription.RefractionColor, -// HDBlockFields.SurfaceDescription.RefractionDistance, -// HDBlockFields.SurfaceDescription.BakedGI, -// HDBlockFields.SurfaceDescription.BakedBackGI, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentMeta = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// HDBlockFields.SurfaceDescription.BentNormal, -// HDBlockFields.SurfaceDescription.Tangent, -// HDBlockFields.SurfaceDescription.SubsurfaceMask, -// HDBlockFields.SurfaceDescription.Thickness, -// HDBlockFields.SurfaceDescription.DiffusionProfileHash, -// HDBlockFields.SurfaceDescription.IridescenceMask, -// HDBlockFields.SurfaceDescription.IridescenceThickness, -// BlockFields.SurfaceDescription.Specular, -// HDBlockFields.SurfaceDescription.CoatMask, -// BlockFields.SurfaceDescription.Metallic, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Occlusion, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.Anisotropy, -// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, -// HDBlockFields.SurfaceDescription.SpecularAAThreshold, -// HDBlockFields.SurfaceDescription.RefractionIndex, -// HDBlockFields.SurfaceDescription.RefractionColor, -// HDBlockFields.SurfaceDescription.RefractionDistance, -// }; - -// public static BlockFieldDescriptor[] FragmentShadowCaster = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentSceneSelection = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.Distortion, -// HDBlockFields.SurfaceDescription.DistortionBlur, -// }; - -// public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, -// HDBlockFields.SurfaceDescription.DepthOffset, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// BlockFields.SurfaceDescription.Smoothness, -// }; - -// public static BlockFieldDescriptor[] FragmentTransparentBackface = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// HDBlockFields.SurfaceDescription.BentNormal, -// HDBlockFields.SurfaceDescription.Tangent, -// HDBlockFields.SurfaceDescription.SubsurfaceMask, -// HDBlockFields.SurfaceDescription.Thickness, -// HDBlockFields.SurfaceDescription.DiffusionProfileHash, -// HDBlockFields.SurfaceDescription.IridescenceMask, -// HDBlockFields.SurfaceDescription.IridescenceThickness, -// BlockFields.SurfaceDescription.Specular, -// HDBlockFields.SurfaceDescription.CoatMask, -// BlockFields.SurfaceDescription.Metallic, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Smoothness, -// BlockFields.SurfaceDescription.Occlusion, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.Anisotropy, -// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, -// HDBlockFields.SurfaceDescription.SpecularAAThreshold, -// HDBlockFields.SurfaceDescription.RefractionIndex, -// HDBlockFields.SurfaceDescription.RefractionColor, -// HDBlockFields.SurfaceDescription.RefractionDistance, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentRayTracingPrepass = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; -// } -// #endregion - -// #region RenderStates -// static class LitRenderStates -// { -// public static RenderStateCollection GBuffer = new RenderStateCollection -// { -// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, -// { RenderState.ZTest(CoreRenderStates.Uniforms.zTestGBuffer) }, -// { RenderState.Stencil(new StencilDescriptor() -// { -// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskGBuffer, -// Ref = CoreRenderStates.Uniforms.stencilRefGBuffer, -// Comp = "Always", -// Pass = "Replace", -// }) }, -// }; - -// public static RenderStateCollection Distortion = new RenderStateCollection -// { -// { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, -// { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, -// { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, -// { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, -// { RenderState.ZWrite(ZWrite.Off) }, -// { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, -// { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, -// { RenderState.Stencil(new StencilDescriptor() -// { -// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, -// Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, -// Comp = "Always", -// Pass = "Replace", -// }) }, -// }; - -// public static RenderStateCollection RayTracingPrepass = new RenderStateCollection -// { -// { RenderState.Blend(Blend.One, Blend.Zero) }, -// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, -// { RenderState.ZWrite(ZWrite.On) }, -// // Note: we use default ZTest LEqual so if the object have already been render in depth prepass, it will re-render to tag stencil -// }; -// } -// #endregion - -// #region Pragmas -// static class LitPragmas -// { -// public static PragmaCollection RaytracingBasic = new PragmaCollection -// { -// { Pragma.Target(ShaderModel.Target45) }, -// { Pragma.Vertex("Vert") }, -// { Pragma.Fragment("Frag") }, -// { Pragma.OnlyRenderers(new Platform[] {Platform.D3D11}) }, -// }; -// } -// #endregion - -// #region Defines -// static class LitDefines -// { -// public static DefineCollection RaytracingForward = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 0 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; - -// public static DefineCollection RaytracingIndirect = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; - -// public static DefineCollection RaytracingGBuffer = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// }; - -// public static DefineCollection RaytracingVisibility = new DefineCollection -// { -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// }; - -// public static DefineCollection RaytracingPathTracing = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 0 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; -// } -// #endregion - -// #region Keywords -// static class LitKeywords -// { -// public static KeywordCollection GBuffer = new KeywordCollection -// { -// { CoreKeywords.HDBase }, -// { CoreKeywordDescriptors.DebugDisplay }, -// { CoreKeywords.Lightmaps }, -// { CoreKeywordDescriptors.ShadowsShadowmask }, -// { CoreKeywordDescriptors.LightLayers }, -// { CoreKeywordDescriptors.Decals }, -// }; - -// public static KeywordCollection DepthMotionVectors = new KeywordCollection -// { -// { CoreKeywords.HDBase }, -// { CoreKeywordDescriptors.WriteMsaaDepth }, -// { CoreKeywordDescriptors.WriteNormalBuffer }, -// { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, -// }; -// } -// #endregion - -// #region Includes -// static class LitIncludes -// { -// const string kLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; -// const string kPassGBuffer = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassGBuffer.hlsl"; -// const string kPassConstant = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassConstant.hlsl"; - -// public static IncludeCollection Common = new IncludeCollection -// { -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, -// { CoreIncludes.kLit, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, -// { kLitDecalData, IncludeLocation.Pregraph }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// }; - -// public static IncludeCollection GBuffer = new IncludeCollection -// { -// { Common }, -// { kPassGBuffer, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection Meta = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection DepthOnly = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection RayTracingPrepass = new IncludeCollection -// { -// { Common }, -// { kPassConstant, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection MotionVectors = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection Forward = new IncludeCollection -// { -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, -// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, -// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, -// { CoreIncludes.kLit, IncludeLocation.Pregraph }, -// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, -// { kLitDecalData, IncludeLocation.Pregraph }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection Distortion = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, -// }; -// } -// #endregion } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index 50aed180b33..376ab98f650 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -22,14 +22,6 @@ public static PassDescriptor GenerateDistortionPass(bool supportLighting) lightMode = "DistortionVectors", useInPreview = true, - // Template - // passTemplatePath = templatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // Port mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = FragmentDistortion, - // Collections renderStates = GenerateRenderState(), pragmas = CorePragmas.DotsInstancedInV1AndV2, @@ -80,13 +72,6 @@ IncludeCollection GenerateIncludes() } } - // public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] - // { - // BlockFields.SurfaceDescription.Alpha, - // BlockFields.SurfaceDescription.AlphaClipThreshold, - // HDBlockFields.SurfaceDescription.Distortion, - // HDBlockFields.SurfaceDescription.DistortionBlur, - // }; #endregion @@ -102,10 +87,6 @@ public static PassDescriptor GenerateSceneSelection(bool supportLighting) lightMode = "SceneSelectionPass", useInPreview = false, - // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = FragmentSceneSelection, - // Collections renderStates = CoreRenderStates.SceneSelection, pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, @@ -135,13 +116,6 @@ IncludeCollection GenerateIncludes() } } - // public static BlockFieldDescriptor[] FragmentSceneSelection = new BlockFieldDescriptor[] - // { - // BlockFields.SurfaceDescription.Alpha, - // BlockFields.SurfaceDescription.AlphaClipThreshold, - // HDBlockFields.SurfaceDescription.DepthOffset, - // }; - #endregion #region Shadow Caster Pass @@ -156,10 +130,6 @@ static public PassDescriptor GenerateShadowCaster(bool supportLighting) lightMode = "ShadowCaster", useInPreview = false, - // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = FragmentShadowCaster, - // Collections renderStates = CoreRenderStates.ShadowCaster, pragmas = CorePragmas.DotsInstancedInV2Only, @@ -194,14 +164,6 @@ IncludeCollection GenerateIncludes() HDFields.SubShader.Unlit, }; - public static BlockFieldDescriptor[] FragmentShadowCaster = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - #endregion #region META pass @@ -216,9 +178,6 @@ public static PassDescriptor GenerateMETA(bool supportLighting) lightMode = "META", useInPreview = false, - // Port Mask - validPixelBlocks = FragmentMeta, - // Collections requiredFields = CoreRequiredFields.Meta, renderStates = CoreRenderStates.Meta, @@ -249,39 +208,6 @@ IncludeCollection GenerateIncludes() } } - public static BlockFieldDescriptor[] FragmentMeta = new BlockFieldDescriptor[] - { - // TODO: We want to only put common fields here, not target specific. - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.CoatMask, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.RefractionIndex, - HDBlockFields.SurfaceDescription.RefractionColor, - HDBlockFields.SurfaceDescription.RefractionDistance, - // Eye fields - HDBlockFields.SurfaceDescription.IrisNormal, - }; - #endregion #region Depth Forward Only @@ -296,10 +222,6 @@ public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting) lightMode = "DepthForwardOnly", useInPreview = true, - // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = FragmentDepthOnlyVectors, - // Collections requiredFields = GenerateRequiredFields(), renderStates = CoreRenderStates.DepthOnly, @@ -347,17 +269,6 @@ IncludeCollection GenerateIncludes() } } - public static BlockFieldDescriptor[] FragmentDepthOnlyVectors = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - #endregion #region Motion Vectors @@ -372,10 +283,6 @@ public static PassDescriptor GenerateMotionVectors(bool supportLighting) lightMode = "MotionVectors", useInPreview = false, - // Block Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = FragmentMotionVectors, - // Collections requiredFields = CoreRequiredFields.LitFull, renderStates = GenerateRenderState(), @@ -434,16 +341,6 @@ IncludeCollection GenerateIncludes() } } - public static BlockFieldDescriptor[] FragmentMotionVectors = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.DepthOffset, - }; #endregion @@ -459,10 +356,6 @@ public static PassDescriptor GenereateForwardOnlyPass(bool supportLighting) lightMode = "ForwardOnly", useInPreview = true, - // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = FragmentForwardOnly, - // Collections requiredFields = CoreRequiredFields.LitFull, renderStates = CoreRenderStates.Forward, @@ -502,44 +395,6 @@ IncludeCollection GenerateIncludes() } } - public static BlockFieldDescriptor[] FragmentForwardOnly = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.NormalWS, - HDBlockFields.SurfaceDescription.BentNormal, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.Anisotropy, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - HDBlockFields.SurfaceDescription.ShadowTint, // Unlit only field - // Eye fields - HDBlockFields.SurfaceDescription.IrisNormal, - HDBlockFields.SurfaceDescription.IOR, - HDBlockFields.SurfaceDescription.Mask, - // Hair only - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - }; - #endregion #region Back then front pass @@ -554,10 +409,6 @@ public static PassDescriptor GenerateBackThenFront(bool supportLighting) lightMode = "TransparentBackface", useInPreview = true, - // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = FragmentBackThenFront, - // Collections requiredFields = CoreRequiredFields.LitMinimal, renderStates = CoreRenderStates.TransparentBackface, @@ -597,50 +448,6 @@ IncludeCollection GenerateIncludes() } } - public static BlockFieldDescriptor[] FragmentBackThenFront = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.CoatMask, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.RefractionIndex, - HDBlockFields.SurfaceDescription.RefractionColor, - HDBlockFields.SurfaceDescription.RefractionDistance, - HDBlockFields.SurfaceDescription.DepthOffset, - // Eye fields - HDBlockFields.SurfaceDescription.IrisNormal, - HDBlockFields.SurfaceDescription.IOR, - HDBlockFields.SurfaceDescription.Mask, - // Hair only - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - }; - #endregion #region Transparent Depth Prepass @@ -655,10 +462,6 @@ public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLightin lightMode = "TransparentDepthPrepass", useInPreview = true, - // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = FragmentTransparentDepthPrepass, - // Collections requiredFields = TransparentDepthPrepassFields, renderStates = GenerateRenderState(), @@ -741,17 +544,6 @@ IncludeCollection GenerateIncludes() HDStructFields.FragInputs.color, }; - public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, - HDBlockFields.SurfaceDescription.DepthOffset, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - BlockFields.SurfaceDescription.Smoothness, - }; - #endregion #region Transparent Depth Postpass @@ -766,10 +558,6 @@ public static PassDescriptor GenerateTransparentDepthPostpass(bool supportLighti lightMode = "TransparentDepthPostpass", useInPreview = true, - // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = FragmentTransparentDepthPostpass, - // Collections renderStates = GenerateRenderState(), pragmas = CorePragmas.DotsInstancedInV1AndV2, @@ -812,13 +600,6 @@ RenderStateCollection GenerateRenderState() } } - public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.Alpha, - HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - #endregion #region Lit DepthOnly @@ -832,14 +613,6 @@ public static PassDescriptor GenerateLitDepthOnly() lightMode = "DepthOnly", useInPreview = true, - // // Template - // passTemplatePath = passTemplatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = LitBlockMasks.FragmentDepthMotionVectors, - // Collections requiredFields = CoreRequiredFields.LitFull, renderStates = CoreRenderStates.DepthOnly, @@ -884,14 +657,6 @@ public static PassDescriptor GenerateGBuffer() lightMode = "GBuffer", useInPreview = true, - // // Template - // passTemplatePath = passTemplatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = LitBlockMasks.FragmentDefault, - // Collections requiredFields = CoreRequiredFields.LitMinimal, renderStates = GBufferRenderState, @@ -953,14 +718,6 @@ public static PassDescriptor GenerateLitForward() lightMode = "Forward", useInPreview = true, - // // Template - // passTemplatePath = passTemplatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = LitBlockMasks.FragmentDefault, - // Collections requiredFields = CoreRequiredFields.LitMinimal, renderStates = CoreRenderStates.ForwardColorMask, @@ -1002,14 +759,6 @@ public static PassDescriptor GenerateLitRaytracingPrepass() lightMode = "RayTracingPrepass", useInPreview = false, - // // Template - // passTemplatePath = passTemplatePath, - // sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - - // // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = LitBlockMasks.FragmentRayTracingPrepass, - // Collections renderStates = RayTracingPrepassRenderState, pragmas = LitRaytracingPrepassPragmas, @@ -1061,10 +810,6 @@ public static PassDescriptor GenerateRaytracingIndirect(bool supportLighting) lightMode = "IndirectDXR", useInPreview = false, - // Port Mask - // validVertexBlocks = CoreBlockMasks.Vertex, - // validPixelBlocks = RaytracingIndirectFragment, - // Collections pragmas = CorePragmas.RaytracingBasic, defines = supportLighting ? GenerateDefines() : null, @@ -1077,55 +822,13 @@ DefineCollection GenerateDefines() { return new DefineCollection { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, + { Defines.shadowLow }, + { Defines.raytracingLow }, { CoreKeywordDescriptors.HasLightloop, 1 }, }; } } - public static BlockFieldDescriptor[] RaytracingIndirectFragment = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.CoatMask, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.RefractionIndex, - HDBlockFields.SurfaceDescription.RefractionColor, - HDBlockFields.SurfaceDescription.RefractionDistance, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - //Hair blocks: - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, - }; - #endregion #region Raytracing Visibility @@ -1155,50 +858,7 @@ public static PassDescriptor GenerateRaytracingVisibility(bool supportLighting) public static DefineCollection RaytracingVisibilityDefines = new DefineCollection { - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - // TODO: we might want to share this with all ray tracing passes - public static BlockFieldDescriptor[] RaytracingVisibilityFragment = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.CoatMask, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.RefractionIndex, - HDBlockFields.SurfaceDescription.RefractionColor, - HDBlockFields.SurfaceDescription.RefractionDistance, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - //Hair blocks: - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, + { Defines.raytracingLow }, }; #endregion @@ -1230,53 +890,11 @@ public static PassDescriptor GenerateRaytracingForward(bool supportLighting) public static DefineCollection RaytracingForwardDefines = new DefineCollection { - { CoreKeywordDescriptors.Shadow, 0 }, + { Defines.shadowLow }, { RayTracingNode.GetRayTracingKeyword(), 0 }, { CoreKeywordDescriptors.HasLightloop, 1 }, }; - public static BlockFieldDescriptor[] RaytracingForwardFragment = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.CoatMask, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.RefractionIndex, - HDBlockFields.SurfaceDescription.RefractionColor, - HDBlockFields.SurfaceDescription.RefractionDistance, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - //Hair blocks: - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, - }; - #endregion #region Raytracing GBuffer @@ -1306,50 +924,8 @@ public static PassDescriptor GenerateRaytracingGBuffer(bool supportLighting) public static DefineCollection RaytracingGBufferDefines = new DefineCollection { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, - }; - - public static BlockFieldDescriptor[] RaytracingGBufferFragment = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.CoatMask, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.RefractionIndex, - HDBlockFields.SurfaceDescription.RefractionColor, - HDBlockFields.SurfaceDescription.RefractionDistance, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - //Hair blocks: - HDBlockFields.SurfaceDescription.SpecularTint, - HDBlockFields.SurfaceDescription.SpecularShift, - HDBlockFields.SurfaceDescription.SecondarySpecularTint, - HDBlockFields.SurfaceDescription.SecondarySmoothness, - HDBlockFields.SurfaceDescription.SecondarySpecularShift, - HDBlockFields.SurfaceDescription.HairStrandDirection, - HDBlockFields.SurfaceDescription.Transmittance, - HDBlockFields.SurfaceDescription.RimTransmissionIntensity, + { Defines.shadowLow }, + { Defines.raytracingLow }, }; #endregion @@ -1381,44 +957,11 @@ public static PassDescriptor GeneratePathTracing(bool supportLighting) public static DefineCollection RaytracingPathTracingDefines = new DefineCollection { - { CoreKeywordDescriptors.Shadow, 0 }, + { Defines.shadowLow }, { RayTracingNode.GetRayTracingKeyword(), 0 }, { CoreKeywordDescriptors.HasLightloop, 1 }, }; - public static BlockFieldDescriptor[] PathTracingFragment = new BlockFieldDescriptor[] - { - BlockFields.SurfaceDescription.BaseColor, - BlockFields.SurfaceDescription.NormalTS, - BlockFields.SurfaceDescription.NormalWS, - BlockFields.SurfaceDescription.NormalOS, - HDBlockFields.SurfaceDescription.BentNormal, - HDBlockFields.SurfaceDescription.Tangent, - HDBlockFields.SurfaceDescription.SubsurfaceMask, - HDBlockFields.SurfaceDescription.Thickness, - HDBlockFields.SurfaceDescription.DiffusionProfileHash, - HDBlockFields.SurfaceDescription.IridescenceMask, - HDBlockFields.SurfaceDescription.IridescenceThickness, - BlockFields.SurfaceDescription.Specular, - HDBlockFields.SurfaceDescription.CoatMask, - BlockFields.SurfaceDescription.Metallic, - BlockFields.SurfaceDescription.Emission, - BlockFields.SurfaceDescription.Smoothness, - BlockFields.SurfaceDescription.Occlusion, - HDBlockFields.SurfaceDescription.SpecularOcclusion, - BlockFields.SurfaceDescription.Alpha, - BlockFields.SurfaceDescription.AlphaClipThreshold, - HDBlockFields.SurfaceDescription.Anisotropy, - HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, - HDBlockFields.SurfaceDescription.SpecularAAThreshold, - HDBlockFields.SurfaceDescription.RefractionIndex, - HDBlockFields.SurfaceDescription.RefractionColor, - HDBlockFields.SurfaceDescription.RefractionDistance, - HDBlockFields.SurfaceDescription.BakedGI, - HDBlockFields.SurfaceDescription.BakedBackGI, - HDBlockFields.SurfaceDescription.DepthOffset, - }; - #endregion #region Raytracing Subsurface @@ -1452,10 +995,26 @@ public static PassDescriptor GenerateRaytracingSubsurface() public static DefineCollection RaytracingSubsurfaceDefines = new DefineCollection { - { CoreKeywordDescriptors.Shadow, 0 }, - { RayTracingNode.GetRayTracingKeyword(), 1 }, + { Defines.shadowLow }, + { Defines.raytracingLow }, }; +#endregion + +#region Define Utility + + public static class Defines + { + // Shadows + public static DefineCollection shadowLow = new DefineCollection { {CoreKeywordDescriptors.Shadow, 0} }; + public static DefineCollection shadowMedium = new DefineCollection { {CoreKeywordDescriptors.Shadow, 1} }; + public static DefineCollection shadowHigh = new DefineCollection { {CoreKeywordDescriptors.Shadow, 2} }; + + // Raytracing Quality + public static DefineCollection raytracingLow = new DefineCollection { {RayTracingNode.GetRayTracingKeyword(), 0} }; + public static DefineCollection raytracingHigh = new DefineCollection { {RayTracingNode.GetRayTracingKeyword(), 1} }; + } + #endregion } 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 b4e5e1ae81a..c987df8759a 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 @@ -320,739 +320,5 @@ public static bool SpecularOcclusionConeFixupMethodModifiesRoughness(StackLitDat protected override int ComputeMaterialNeedsUpdateHash() => base.ComputeMaterialNeedsUpdateHash() * 23 + stackLitData.subsurfaceScattering.GetHashCode(); - -// #region SubShaders -// // static class SubShaders -// // { -// // public static SubShaderDescriptor StackLit = new SubShaderDescriptor() -// // { -// // pipelineTag = HDRenderPipeline.k_ShaderTagName, -// // generatesPreview = true, -// // passes = new PassCollection -// // { -// // { StackLitPasses.ShadowCaster }, -// // { StackLitPasses.META }, -// // { StackLitPasses.SceneSelection }, -// // { StackLitPasses.DepthForwardOnly }, -// // { StackLitPasses.MotionVectors }, -// // { StackLitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, -// // { StackLitPasses.TransparentDepthPrepass, new FieldCondition[]{ -// // new FieldCondition(HDFields.TransparentDepthPrePass, true), -// // new FieldCondition(HDFields.DisableSSRTransparent, true) }}, -// // { StackLitPasses.TransparentDepthPrepass, new FieldCondition[]{ -// // new FieldCondition(HDFields.TransparentDepthPrePass, true), -// // new FieldCondition(HDFields.DisableSSRTransparent, false) }}, -// // { StackLitPasses.TransparentDepthPrepass, new FieldCondition[]{ -// // new FieldCondition(HDFields.TransparentDepthPrePass, false), -// // new FieldCondition(HDFields.DisableSSRTransparent, false) }}, -// // { StackLitPasses.ForwardOnly }, -// // { StackLitPasses.TransparentDepthPostpass, new FieldCondition(HDFields.TransparentDepthPostPass, true) }, -// // }, -// // }; - -// // public static SubShaderDescriptor StackLitRaytracing = new SubShaderDescriptor() -// // { -// // pipelineTag = HDRenderPipeline.k_ShaderTagName, -// // generatesPreview = false, -// // passes = new PassCollection -// // { -// // { StackLitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, -// // { StackLitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, -// // { StackLitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, -// // { StackLitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, -// // { StackLitPasses.RaytracingSubSurface, new FieldCondition(Fields.IsPreview, false) }, -// // }, -// // }; -// // } -// #endregion - -// #region Passes -// public static class StackLitPasses -// { -// public static PassDescriptor META = new PassDescriptor() -// { -// // Definition -// displayName = "META", -// referenceName = "SHADERPASS_LIGHT_TRANSPORT", -// lightMode = "META", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validPixelBlocks = StackLitBlockMasks.FragmentMETA, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.Meta, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.Meta, -// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, -// keywords = CoreKeywords.HDBase, -// includes = StackLitIncludes.Meta, -// }; - -// public static PassDescriptor ShadowCaster = new PassDescriptor() -// { -// // Definition -// displayName = "ShadowCaster", -// referenceName = "SHADERPASS_SHADOWS", -// lightMode = "ShadowCaster", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = StackLitBlockMasks.VertexPosition, -// validPixelBlocks = StackLitBlockMasks.FragmentAlphaDepth, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = StackLitRenderStates.ShadowCaster, -// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, -// keywords = CoreKeywords.HDBase, -// includes = StackLitIncludes.DepthOnly, -// }; - -// public static PassDescriptor SceneSelection = new PassDescriptor() -// { -// // Definition -// displayName = "SceneSelectionPass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "SceneSelectionPass", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentAlphaDepth, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.SceneSelection, -// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayerEditorSync, -// defines = CoreDefines.SceneSelection, -// keywords = CoreKeywords.HDBase, -// includes = StackLitIncludes.DepthOnly, -// }; - -// public static PassDescriptor DepthForwardOnly = new PassDescriptor() -// { -// // // Code path for WRITE_NORMAL_BUFFER -// // See StackLit.hlsl:ConvertSurfaceDataToNormalData() -// // which ShaderPassDepthOnly uses: we need to add proper interpolators dependencies depending on WRITE_NORMAL_BUFFER. -// // In our case WRITE_NORMAL_BUFFER is always enabled here. -// // Also, we need to add PixelShaderSlots dependencies for everything potentially used there. -// // See AddPixelShaderSlotsForWriteNormalBufferPasses() - -// // Definition -// displayName = "DepthForwardOnly", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "DepthForwardOnly", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentDepthMotionVectors, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.DepthOnly, -// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, -// defines = CoreDefines.DepthMotionVectors, -// keywords = CoreKeywords.DepthMotionVectorsNoNormal, -// includes = StackLitIncludes.DepthOnly, -// }; - -// public static PassDescriptor MotionVectors = new PassDescriptor() -// { -// // Definition -// displayName = "MotionVectors", -// referenceName = "SHADERPASS_MOTION_VECTORS", -// lightMode = "MotionVectors", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentDepthMotionVectors, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.MotionVectors, -// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, -// defines = CoreDefines.DepthMotionVectors, -// keywords = CoreKeywords.DepthMotionVectorsNoNormal, -// includes = StackLitIncludes.MotionVectors, -// }; - -// public static PassDescriptor Distortion = new PassDescriptor() -// { -// // Definition -// displayName = "DistortionVectors", -// referenceName = "SHADERPASS_DISTORTION", -// lightMode = "DistortionVectors", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentDistortion, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = StackLitRenderStates.Distortion, -// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, -// keywords = CoreKeywords.HDBase, -// includes = StackLitIncludes.Distortion, -// }; - -// public static PassDescriptor TransparentDepthPrepass = new PassDescriptor() -// { -// // Definition -// displayName = "TransparentDepthPrepass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "TransparentDepthPrepass", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentTransparentDepthPrepass, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.TransparentDepthPrePass, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.TransparentDepthPrepass, -// keywords = CoreKeywords.HDBase, -// includes = StackLitIncludes.DepthOnly, -// }; - -// public static PassDescriptor ForwardOnly = new PassDescriptor() -// { -// // Definition -// displayName = "ForwardOnly", -// referenceName = "SHADERPASS_FORWARD", -// lightMode = "ForwardOnly", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = CoreRequiredFields.LitFull, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.Forward, -// pragmas = StackLitPragmas.DotsInstancedInV2OnlyRenderingLayer, -// defines = CoreDefines.Forward, -// keywords = CoreKeywords.Forward, -// includes = StackLitIncludes.ForwardOnly, -// }; - -// public static PassDescriptor TransparentDepthPostpass = new PassDescriptor() -// { -// // Definition -// displayName = "TransparentDepthPostpass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "TransparentDepthPostpass", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentTransparentDepthPostpass, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.TransparentDepthPostPass, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// defines = CoreDefines.ShaderGraphRaytracingHigh, -// keywords = CoreKeywords.HDBase, -// includes = StackLitIncludes.DepthOnly, -// }; - -// public static PassDescriptor RaytracingIndirect = new PassDescriptor() -// { -// // Definition -// displayName = "IndirectDXR", -// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", -// lightMode = "IndirectDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = StackLitDefines.RaytracingIndirect, -// keywords = CoreKeywords.RaytracingIndirect, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingIndirect }, -// }; - -// public static PassDescriptor RaytracingVisibility = new PassDescriptor() -// { -// // Definition -// displayName = "VisibilityDXR", -// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", -// lightMode = "VisibilityDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = StackLitDefines.RaytracingVisibility, -// keywords = CoreKeywords.RaytracingVisiblity, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingVisibility }, -// }; - -// public static PassDescriptor RaytracingForward = new PassDescriptor() -// { -// // Definition -// displayName = "ForwardDXR", -// referenceName = "SHADERPASS_RAYTRACING_FORWARD", -// lightMode = "ForwardDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = StackLitDefines.RaytracingForward, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingForward }, -// }; - -// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() -// { -// // Definition -// displayName = "GBufferDXR", -// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", -// lightMode = "GBufferDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Port Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = StackLitDefines.RaytracingGBuffer, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RayTracingGBuffer }, -// }; - -// public static PassDescriptor RaytracingSubSurface = new PassDescriptor() -// { -// //Definition -// displayName = "SubSurfaceDXR", -// referenceName = "SHADERPASS_RAYTRACING_SUB_SURFACE", -// lightMode = "SubSurfaceDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// //Port mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = StackLitBlockMasks.FragmentForward, - -// //Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// defines = StackLitDefines.RaytracingGBuffer, -// keywords = CoreKeywords.RaytracingGBufferForward, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.StackLit, HDFields.ShaderPass.RaytracingSubSurface }, -// }; -// } -// #endregion - -// #region PortMasks -// static class StackLitBlockMasks -// { -// public static BlockFieldDescriptor[] VertexPosition = new BlockFieldDescriptor[] -// { -// BlockFields.VertexDescription.Position, -// }; - -// public static BlockFieldDescriptor[] FragmentMETA = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// HDBlockFields.SurfaceDescription.BentNormal, -// HDBlockFields.SurfaceDescription.Tangent, -// HDBlockFields.SurfaceDescription.SubsurfaceMask, -// HDBlockFields.SurfaceDescription.Thickness, -// HDBlockFields.SurfaceDescription.DiffusionProfileHash, -// HDBlockFields.SurfaceDescription.IridescenceMask, -// HDBlockFields.SurfaceDescription.IridescenceThickness, -// HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIR, -// HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIRClamp, -// BlockFields.SurfaceDescription.Specular, -// HDBlockFields.SurfaceDescription.DielectricIor, -// BlockFields.SurfaceDescription.Metallic, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Smoothness, -// HDBlockFields.SurfaceDescription.SmoothnessB, -// BlockFields.SurfaceDescription.Occlusion, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.Anisotropy, -// HDBlockFields.SurfaceDescription.AnisotropyB, -// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, -// HDBlockFields.SurfaceDescription.SpecularAAThreshold, -// HDBlockFields.SurfaceDescription.CoatSmoothness, -// HDBlockFields.SurfaceDescription.CoatIor, -// HDBlockFields.SurfaceDescription.CoatThickness, -// HDBlockFields.SurfaceDescription.CoatExtinction, -// HDBlockFields.SurfaceDescription.CoatNormal, -// HDBlockFields.SurfaceDescription.CoatMask, -// HDBlockFields.SurfaceDescription.LobeMix, -// HDBlockFields.SurfaceDescription.Haziness, -// HDBlockFields.SurfaceDescription.HazeExtent, -// HDBlockFields.SurfaceDescription.HazyGlossMaxDielectricF0, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// HDBlockFields.SurfaceDescription.SOFixupVisibilityRatioThreshold, -// HDBlockFields.SurfaceDescription.SOFixupStrengthFactor, -// HDBlockFields.SurfaceDescription.SOFixupMaxAddedRoughness, -// }; - -// public static BlockFieldDescriptor[] FragmentAlphaDepth = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentDepthMotionVectors = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.DepthOffset, -// // StackLitMasterNode.coat -// HDBlockFields.SurfaceDescription.CoatSmoothness, -// HDBlockFields.SurfaceDescription.CoatNormal, -// // !StackLitMasterNode.coat -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// HDBlockFields.SurfaceDescription.LobeMix, -// BlockFields.SurfaceDescription.Smoothness, -// HDBlockFields.SurfaceDescription.SmoothnessB, -// // StackLitMasterNode.geometricSpecularAA -// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, -// HDBlockFields.SurfaceDescription.SpecularAAThreshold, -// }; - -// public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.Distortion, -// HDBlockFields.SurfaceDescription.DistortionBlur, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentTransparentDepthPrepass = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, -// HDBlockFields.SurfaceDescription.DepthOffset, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// BlockFields.SurfaceDescription.Smoothness, -// }; - -// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// BlockFields.SurfaceDescription.NormalTS, -// BlockFields.SurfaceDescription.NormalWS, -// BlockFields.SurfaceDescription.NormalOS, -// HDBlockFields.SurfaceDescription.BentNormal, -// HDBlockFields.SurfaceDescription.Tangent, -// HDBlockFields.SurfaceDescription.SubsurfaceMask, -// HDBlockFields.SurfaceDescription.Thickness, -// HDBlockFields.SurfaceDescription.DiffusionProfileHash, -// HDBlockFields.SurfaceDescription.IridescenceMask, -// HDBlockFields.SurfaceDescription.IridescenceThickness, -// HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIR, -// HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIRClamp, -// BlockFields.SurfaceDescription.Specular, -// HDBlockFields.SurfaceDescription.DielectricIor, -// BlockFields.SurfaceDescription.Metallic, -// BlockFields.SurfaceDescription.Emission, -// BlockFields.SurfaceDescription.Smoothness, -// HDBlockFields.SurfaceDescription.SmoothnessB, -// BlockFields.SurfaceDescription.Occlusion, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.Anisotropy, -// HDBlockFields.SurfaceDescription.AnisotropyB, -// HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, -// HDBlockFields.SurfaceDescription.SpecularAAThreshold, -// HDBlockFields.SurfaceDescription.CoatSmoothness, -// HDBlockFields.SurfaceDescription.CoatIor, -// HDBlockFields.SurfaceDescription.CoatThickness, -// HDBlockFields.SurfaceDescription.CoatExtinction, -// HDBlockFields.SurfaceDescription.CoatNormal, -// HDBlockFields.SurfaceDescription.CoatMask, -// HDBlockFields.SurfaceDescription.LobeMix, -// HDBlockFields.SurfaceDescription.Haziness, -// HDBlockFields.SurfaceDescription.HazeExtent, -// HDBlockFields.SurfaceDescription.HazyGlossMaxDielectricF0, -// HDBlockFields.SurfaceDescription.SpecularOcclusion, -// HDBlockFields.SurfaceDescription.SOFixupVisibilityRatioThreshold, -// HDBlockFields.SurfaceDescription.SOFixupStrengthFactor, -// HDBlockFields.SurfaceDescription.SOFixupMaxAddedRoughness, -// HDBlockFields.SurfaceDescription.BakedGI, -// HDBlockFields.SurfaceDescription.BakedBackGI, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; - -// public static BlockFieldDescriptor[] FragmentTransparentDepthPostpass = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, -// HDBlockFields.SurfaceDescription.DepthOffset, -// }; -// } -// #endregion - -// #region RenderStates -// static class StackLitRenderStates -// { -// public static RenderStateCollection ShadowCaster = new RenderStateCollection -// { -// { RenderState.Blend(Blend.One, Blend.Zero) }, -// { RenderState.ZWrite(ZWrite.On) }, -// { RenderState.ZClip(CoreRenderStates.Uniforms.zClip) }, -// { RenderState.ColorMask("ColorMask 0") }, -// }; - -// public static RenderStateCollection Distortion = new RenderStateCollection -// { -// { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, -// { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, -// { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, -// { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, -// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, -// { RenderState.ZWrite(ZWrite.Off) }, -// { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, -// { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, -// { RenderState.Stencil(new StencilDescriptor() -// { -// WriteMask = $"{(int)StencilUsage.DistortionVectors}", -// Ref = $"{(int)StencilUsage.DistortionVectors}", -// Comp = "Always", -// Pass = "Replace", -// }) }, -// }; -// } -// #endregion - -// #region Defines -// static class StackLitDefines -// { -// public static DefineCollection RaytracingForward = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 0 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; - -// public static DefineCollection RaytracingIndirect = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; - -// public static DefineCollection RaytracingGBuffer = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// }; - -// public static DefineCollection RaytracingVisibility = new DefineCollection -// { -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// }; - -// public static DefineCollection RaytracingPathTracing = new DefineCollection -// { -// { CoreKeywordDescriptors.Shadow, 0 }, -// { RayTracingNode.GetRayTracingKeyword(), 0 }, -// { CoreKeywordDescriptors.HasLightloop, 1 }, -// }; -// } -// #endregion - -// #region Pragmas -// static class StackLitPragmas -// { -// public static PragmaCollection DotsInstancedInV2OnlyRenderingLayer = new PragmaCollection -// { -// { CorePragmas.Basic }, -// { Pragma.MultiCompileInstancing }, -// { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) }, -// #if ENABLE_HYBRID_RENDERER_V2 -// { Pragma.DOTSInstancing }, -// { Pragma.InstancingOptions(InstancingOptions.NoLodFade) }, -// #endif -// }; - -// public static PragmaCollection DotsInstancedInV2OnlyRenderingLayerEditorSync = new PragmaCollection -// { -// { CorePragmas.Basic }, -// { Pragma.MultiCompileInstancing }, -// { Pragma.InstancingOptions(InstancingOptions.RenderingLayer) }, -// { Pragma.EditorSyncCompilation }, -// #if ENABLE_HYBRID_RENDERER_V2 -// { Pragma.DOTSInstancing }, -// { Pragma.InstancingOptions(InstancingOptions.NoLodFade) }, -// #endif -// }; -// } -// #endregion - -// #region Includes -// static class StackLitIncludes -// { -// const string kSpecularOcclusionDef = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/SphericalCapPivot/SpecularOcclusionDef.hlsl"; -// const string kStackLitDecalData = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLitDecalData.hlsl"; - -// public static IncludeCollection Common = new IncludeCollection -// { -// { kSpecularOcclusionDef, IncludeLocation.Pregraph }, -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, -// { CoreIncludes.kStackLit, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, -// { kStackLitDecalData, IncludeLocation.Pregraph }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// }; - -// public static IncludeCollection Meta = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection DepthOnly = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection MotionVectors = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection Distortion = new IncludeCollection -// { -// { Common }, -// { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection ForwardOnly = new IncludeCollection -// { -// { kSpecularOcclusionDef, IncludeLocation.Pregraph }, -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kNormalSurfaceGradient, IncludeLocation.Pregraph }, -// { CoreIncludes.kLighting, IncludeLocation.Pregraph }, -// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph }, -// { CoreIncludes.kStackLit, IncludeLocation.Pregraph }, -// { CoreIncludes.kLightLoop, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, -// { kStackLitDecalData, IncludeLocation.Pregraph }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// { CoreIncludes.kPassForward, IncludeLocation.Postgraph }, -// }; -// } -// #endregion } } 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 faf9db61506..896f773ee4b 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 @@ -18,8 +18,6 @@ sealed partial class HDUnlitSubTarget : SurfaceSubTarget, IRequiresData displayName = "Unlit"; // Templates - // TODO: Why do the raytracing passes use the template for the pipeline agnostic Unlit master node? - // TODO: This should be resolved so we can delete the second pass template protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/HDUnlitPass.template"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Unlit; protected override string renderType => HDRenderTypeTags.HDUnlitShader.ToString(); @@ -68,17 +66,6 @@ protected override SubShaderDescriptor GetSubShaderDescriptor() forwardUnlit.descriptor.includes.Add(CoreIncludes.kPunctualLightCommon, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true)); forwardUnlit.descriptor.includes.Add(CoreIncludes.kHDShadowLoop, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true)); - // { CoreIncludes.CorePregraph }, -// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// { CoreIncludes.kHDShadow, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, -// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, -// { CoreIncludes.kPunctualLightCommon, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, -// { CoreIncludes.kHDShadowLoop, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, -// { kPassForwardUnlit, IncludeLocation.Postgraph }, - - return descriptor; } } @@ -127,561 +114,5 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera // Stencil state for unlit: HDSubShaderUtilities.AddStencilShaderProperties(collector, systemData, null, false); } - -// #region SubShaders -// static class SubShaders -// { -// public static SubShaderDescriptor Unlit = new SubShaderDescriptor() -// { -// pipelineTag = HDRenderPipeline.k_ShaderTagName, -// generatesPreview = true, -// passes = new PassCollection -// { -// { UnlitPasses.ShadowCaster }, -// { UnlitPasses.META }, -// { UnlitPasses.SceneSelection }, -// { UnlitPasses.DepthForwardOnly }, -// { UnlitPasses.MotionVectors }, -// { UnlitPasses.Distortion, new FieldCondition(HDFields.TransparentDistortion, true) }, -// { UnlitPasses.ForwardOnly }, -// }, -// }; - -// public static SubShaderDescriptor UnlitRaytracing = new SubShaderDescriptor() -// { -// pipelineTag = HDRenderPipeline.k_ShaderTagName, -// generatesPreview = false, -// passes = new PassCollection -// { -// { UnlitPasses.RaytracingIndirect, new FieldCondition(Fields.IsPreview, false) }, -// { UnlitPasses.RaytracingVisibility, new FieldCondition(Fields.IsPreview, false) }, -// { UnlitPasses.RaytracingForward, new FieldCondition(Fields.IsPreview, false) }, -// { UnlitPasses.RaytracingGBuffer, new FieldCondition(Fields.IsPreview, false) }, -// { UnlitPasses.RaytracingPathTracing, new FieldCondition(Fields.IsPreview, false) }, -// }, -// }; -// } -// #endregion - -// #region Passes -// static class UnlitPasses -// { -// public static PassDescriptor META = new PassDescriptor() -// { -// // Definition -// displayName = "META", -// referenceName = "SHADERPASS_LIGHT_TRANSPORT", -// lightMode = "META", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validPixelBlocks = UnlitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = new FieldCollection(){ CoreRequiredFields.Meta, HDFields.SubShader.Unlit }, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.Meta, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = CoreKeywords.HDBase, -// includes = UnlitIncludes.Meta, -// }; - -// public static PassDescriptor ShadowCaster = new PassDescriptor() -// { -// // Definition -// displayName = "ShadowCaster", -// referenceName = "SHADERPASS_SHADOWS", -// lightMode = "ShadowCaster", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.ShadowCaster, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = CoreKeywords.HDBase, -// includes = UnlitIncludes.DepthOnly, -// }; - -// public static PassDescriptor SceneSelection = new PassDescriptor() -// { -// // Definition -// displayName = "SceneSelectionPass", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "SceneSelectionPass", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = UnlitRenderStates.SceneSelection, -// pragmas = CorePragmas.DotsInstancedInV2OnlyEditorSync, -// defines = CoreDefines.SceneSelection, -// keywords = CoreKeywords.HDBase, -// includes = UnlitIncludes.DepthOnly, -// }; - -// public static PassDescriptor DepthForwardOnly = new PassDescriptor() -// { -// // Definition -// displayName = "DepthForwardOnly", -// referenceName = "SHADERPASS_DEPTH_ONLY", -// lightMode = "DepthForwardOnly", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = UnlitRenderStates.DepthForwardOnly, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = UnlitKeywords.DepthMotionVectors, -// includes = UnlitIncludes.DepthOnly, -// }; - -// public static PassDescriptor MotionVectors = new PassDescriptor() -// { -// // Definition -// displayName = "MotionVectors", -// referenceName = "SHADERPASS_MOTION_VECTORS", -// lightMode = "MotionVectors", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = UnlitBlockMasks.FragmentOnlyAlpha, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = new FieldCollection(){ CoreRequiredFields.PositionRWS, HDFields.SubShader.Unlit }, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = UnlitRenderStates.MotionVectors, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = UnlitKeywords.DepthMotionVectors, -// includes = UnlitIncludes.MotionVectors, -// }; - -// public static PassDescriptor Distortion = new PassDescriptor() -// { -// // Definition -// displayName = "DistortionVectors", -// referenceName = "SHADERPASS_DISTORTION", -// lightMode = "DistortionVectors", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = UnlitBlockMasks.FragmentDistortion, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = UnlitRenderStates.Distortion, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = CoreKeywords.HDBase, -// includes = UnlitIncludes.Distortion, -// }; - -// public static PassDescriptor ForwardOnly = new PassDescriptor() -// { -// // Definition -// displayName = "ForwardOnly", -// referenceName = "SHADERPASS_FORWARD_UNLIT", -// lightMode = "ForwardOnly", -// useInPreview = true, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = UnlitBlockMasks.FragmentForward, - -// // Collections -// structs = CoreStructCollections.Default, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit }, -// fieldDependencies = CoreFieldDependencies.Default, -// renderStates = CoreRenderStates.Forward, -// pragmas = CorePragmas.DotsInstancedInV2Only, -// keywords = UnlitKeywords.Forward, -// includes = UnlitIncludes.ForwardOnly, - -// virtualTextureFeedback = true, -// }; - -// public static PassDescriptor RaytracingIndirect = new PassDescriptor() -// { -// // Definition -// displayName = "IndirectDXR", -// referenceName = "SHADERPASS_RAYTRACING_INDIRECT", -// lightMode = "IndirectDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = UnlitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// keywords = CoreKeywords.HDBase, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingIndirect }, -// }; - -// public static PassDescriptor RaytracingVisibility = new PassDescriptor() -// { -// // Definition -// displayName = "VisibilityDXR", -// referenceName = "SHADERPASS_RAYTRACING_VISIBILITY", -// lightMode = "VisibilityDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = UnlitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// includes = CoreIncludes.Raytracing, -// keywords = CoreKeywords.RaytracingVisiblity, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingVisibility }, -// }; - -// public static PassDescriptor RaytracingForward = new PassDescriptor() -// { -// // Definition -// displayName = "ForwardDXR", -// referenceName = "SHADERPASS_RAYTRACING_FORWARD", -// lightMode = "ForwardDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = UnlitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// keywords = CoreKeywords.HDBase, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingForward }, -// }; - -// public static PassDescriptor RaytracingGBuffer = new PassDescriptor() -// { -// // Definition -// displayName = "GBufferDXR", -// referenceName = "SHADERPASS_RAYTRACING_GBUFFER", -// lightMode = "GBufferDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = UnlitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// keywords = CoreKeywords.HDBase, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RayTracingGBuffer }, -// }; - -// public static PassDescriptor RaytracingPathTracing = new PassDescriptor() -// { -// //Definition -// displayName = "PathTracingDXR", -// referenceName = "SHADERPASS_PATH_TRACING", -// lightMode = "PathTracingDXR", -// useInPreview = false, - -// // Template -// passTemplatePath = passTemplatePath, -// sharedTemplateDirectory = HDTarget.sharedTemplateDirectory, - -// // Block Mask -// validVertexBlocks = CoreBlockMasks.Vertex, -// validPixelBlocks = UnlitBlockMasks.FragmentDefault, - -// // Collections -// structs = CoreStructCollections.Default, -// fieldDependencies = CoreFieldDependencies.Default, -// pragmas = CorePragmas.RaytracingBasic, -// keywords = CoreKeywords.HDBaseNoCrossFade, -// includes = CoreIncludes.Raytracing, -// requiredFields = new FieldCollection(){ HDFields.SubShader.Unlit, HDFields.ShaderPass.RaytracingPathTracing }, -// }; -// } -// #endregion - -// #region BlockMasks -// static class UnlitBlockMasks -// { -// public static BlockFieldDescriptor[] FragmentDefault = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// BlockFields.SurfaceDescription.Emission, -// }; - -// public static BlockFieldDescriptor[] FragmentOnlyAlpha = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// }; - -// public static BlockFieldDescriptor[] FragmentDistortion = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// HDBlockFields.SurfaceDescription.Distortion, -// HDBlockFields.SurfaceDescription.DistortionBlur, -// }; - -// public static BlockFieldDescriptor[] FragmentForward = new BlockFieldDescriptor[] -// { -// BlockFields.SurfaceDescription.BaseColor, -// BlockFields.SurfaceDescription.Alpha, -// BlockFields.SurfaceDescription.AlphaClipThreshold, -// BlockFields.SurfaceDescription.Emission, -// HDBlockFields.SurfaceDescription.ShadowTint, -// }; -// } -// #endregion - -// #region RenderStates -// static class UnlitRenderStates -// { -// public static RenderStateCollection SceneSelection = new RenderStateCollection -// { -// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, -// { RenderState.ZWrite(ZWrite.On) }, -// { RenderState.ColorMask("ColorMask 0") }, -// }; - -// // Caution: When using MSAA we have normal and depth buffer bind. -// // Unlit objects need to NOT write in normal buffer (or write 0) - Disable color mask for this RT -// // Note: ShaderLab doesn't allow to have a variable on the second parameter of ColorMask -// // - When MSAA: disable target 1 (normal buffer) -// // - When no MSAA: disable target 0 (normal buffer) and 1 (unused) -// public static RenderStateCollection DepthForwardOnly = new RenderStateCollection -// { -// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, -// { RenderState.ZWrite(ZWrite.On) }, -// { RenderState.ColorMask("ColorMask [_ColorMaskNormal]") }, -// { RenderState.ColorMask("ColorMask 0 1") }, -// { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, -// { RenderState.Stencil(new StencilDescriptor() -// { -// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDepth, -// Ref = CoreRenderStates.Uniforms.stencilRefDepth, -// Comp = "Always", -// Pass = "Replace", -// }) }, -// }; - -// // Caution: When using MSAA we have motion vector, normal and depth buffer bind. -// // Mean unlit object need to not write in it (or write 0) - Disable color mask for this RT -// // This is not a problem in no MSAA mode as there is no buffer bind -// public static RenderStateCollection MotionVectors = new RenderStateCollection -// { -// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, -// { RenderState.ZWrite(ZWrite.On) }, -// { RenderState.ColorMask("ColorMask [_ColorMaskNormal] 1") }, -// { RenderState.ColorMask("ColorMask 0 2") }, -// { RenderState.AlphaToMask(CoreRenderStates.Uniforms.alphaToMask), new FieldCondition(Fields.AlphaToMask, true) }, -// { RenderState.Stencil(new StencilDescriptor() -// { -// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskMV, -// Ref = CoreRenderStates.Uniforms.stencilRefMV, -// Comp = "Always", -// Pass = "Replace", -// }) }, -// }; - -// public static RenderStateCollection Distortion = new RenderStateCollection -// { -// { RenderState.Blend(Blend.One, Blend.One, Blend.One, Blend.One), new FieldCondition(HDFields.DistortionAdd, true) }, -// { RenderState.Blend(Blend.DstColor, Blend.Zero, Blend.DstAlpha, Blend.Zero), new FieldCondition(HDFields.DistortionMultiply, true) }, -// { RenderState.Blend(Blend.One, Blend.Zero, Blend.One, Blend.Zero), new FieldCondition(HDFields.DistortionReplace, true) }, -// { RenderState.BlendOp(BlendOp.Add, BlendOp.Add) }, -// { RenderState.Cull(CoreRenderStates.Uniforms.cullMode) }, -// { RenderState.ZWrite(ZWrite.Off) }, -// { RenderState.ZTest(ZTest.Always), new FieldCondition(HDFields.DistortionDepthTest, false) }, -// { RenderState.ZTest(ZTest.LEqual), new FieldCondition(HDFields.DistortionDepthTest, true) }, -// { RenderState.Stencil(new StencilDescriptor() -// { -// WriteMask = CoreRenderStates.Uniforms.stencilWriteMaskDistortionVec, -// Ref = CoreRenderStates.Uniforms.stencilRefDistortionVec, -// Comp = "Always", -// Pass = "Replace", -// }) }, -// }; -// } -// #endregion - -// #region Defines -// static class UnlitDefines -// { -// public static DefineCollection RaytracingForward = new DefineCollection -// { -// { RayTracingNode.GetRayTracingKeyword(), 0 }, -// }; - -// public static DefineCollection RaytracingIndirect = new DefineCollection -// { -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// }; - -// public static DefineCollection RaytracingVisibility = new DefineCollection -// { -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// }; - -// public static DefineCollection RaytracingGBuffer = new DefineCollection -// { -// { RayTracingNode.GetRayTracingKeyword(), 1 }, -// }; -// } -// #endregion - -// #region Keywords -// static class UnlitKeywords -// { -// public static KeywordCollection DepthMotionVectors = new KeywordCollection -// { -// { CoreKeywords.HDBase }, -// { CoreKeywordDescriptors.WriteMsaaDepth }, -// { CoreKeywordDescriptors.AlphaToMask, new FieldCondition(Fields.AlphaToMask, true) }, -// }; - -// public static KeywordCollection Forward = new KeywordCollection -// { -// { CoreKeywords.HDBase }, -// { CoreKeywordDescriptors.DebugDisplay }, -// { CoreKeywordDescriptors.Shadow, new FieldCondition(HDFields.EnableShadowMatte, true) }, -// }; -// } -// #endregion - -// #region Includes -// static class UnlitIncludes -// { -// const string kPassForwardUnlit = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassForwardUnlit.hlsl"; - -// public static IncludeCollection Meta = new IncludeCollection -// { -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// { CoreIncludes.kPassLightTransport, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection DepthOnly = new IncludeCollection -// { -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// { CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection MotionVectors = new IncludeCollection -// { -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// { CoreIncludes.kPassMotionVectors, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection Distortion = new IncludeCollection -// { -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// { CoreIncludes.kDisortionVectors, IncludeLocation.Postgraph }, -// }; - -// public static IncludeCollection ForwardOnly = new IncludeCollection -// { -// { CoreIncludes.CorePregraph }, -// { CoreIncludes.kUnlit, IncludeLocation.Pregraph }, -// { CoreIncludes.CoreUtility }, -// { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, -// { CoreIncludes.kHDShadow, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, -// { CoreIncludes.kLightLoopDef, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, -// { CoreIncludes.kPunctualLightCommon, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, -// { CoreIncludes.kHDShadowLoop, IncludeLocation.Pregraph, new FieldCondition(HDFields.EnableShadowMatte, true) }, -// { kPassForwardUnlit, IncludeLocation.Postgraph }, -// }; -// } -// #endregion } } From f7ac83018d30a7fe9c0f7bbe1e0eb4d20ee6ce68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Fri, 5 Jun 2020 11:16:06 +0200 Subject: [PATCH 23/30] Fix anisotropy indent level --- .../Editor/Material/ShaderGraph/SurfaceSubTarget.cs | 2 -- .../StackLit/ShaderGraph/StackLitSurfaceOptionPropertyBlock.cs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) 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 a9f3d626e8a..e9310192ec6 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 @@ -44,8 +44,6 @@ protected override string renderQueue protected abstract string subShaderInclude { get; } protected virtual string postDecalsInclude => null; protected abstract FieldDescriptor subShaderField { get; } - // Maybe we should rename it custom forward pass include ? - // protected virtual string postGraphInclude => null; public override void Setup(ref TargetSetupContext context) { 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 index 62d171fcd2d..d0ca6631734 100644 --- 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 @@ -37,7 +37,7 @@ protected override void CreatePropertyGUI() // Material type enables: context.AddLabel("Material Core Features", 0); - AddProperty("Anisotropy", () => stackLitData.anisotropy, (newValue) => stackLitData.anisotropy = newValue); + AddProperty("Anisotropy", () => stackLitData.anisotropy, (newValue) => stackLitData.anisotropy = newValue, 1); 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); From 4834837f739db8edc5a7ec62dbd9c34ace781a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Fri, 5 Jun 2020 12:55:39 +0200 Subject: [PATCH 24/30] Fixed yamato compilation issue --- .../Editor/Material/ShaderGraph/SurfaceSubTarget.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e9310192ec6..786bbed2c4a 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 @@ -150,7 +150,7 @@ SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor passDescriptor.sharedTemplateDirectory = HDTarget.sharedTemplateDirectory; IncludeCollection finalIncludes = new IncludeCollection(); - var includeList = passDescriptor.includes.Select(i => i.descriptor).ToList(); + var includeList = passDescriptor.includes.Select(include => include.descriptor).ToList(); // Replace include placeholders if necessary: foreach (var include in passDescriptor.includes) From 25cb3f795b985f9bdc02e7eb6b3261f351d208cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Fri, 5 Jun 2020 14:47:00 +0200 Subject: [PATCH 25/30] Fixed stacklit and raytracing prepass shader issues --- .../Editor/Material/ShaderGraph/HDShaderPasses.cs | 2 +- .../Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.cs | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index 376ab98f650..6b1e3fc614c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -783,7 +783,7 @@ public static PassDescriptor GenerateLitRaytracingPrepass() { CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.CoreUtility }, { CoreIncludes.kDecalUtilities, IncludeLocation.Pregraph }, - { CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph }, + { CoreIncludes.kPostDecalsPlaceholder, IncludeLocation.Pregraph }, { CoreIncludes.kShaderGraphFunctions, IncludeLocation.Pregraph }, { CoreIncludes.kPassConstant, IncludeLocation.Postgraph }, }; 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 c987df8759a..10a34c78216 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 @@ -233,10 +233,6 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(HDBlockFields.SurfaceDescription.IridescenceThickness, stackLitData.iridescence); context.AddBlock(HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIR, stackLitData.iridescence && stackLitData.coat); context.AddBlock(HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIRClamp, stackLitData.iridescence && stackLitData.coat); - - // Specular AA - context.AddBlock(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, lightingData.specularAA); - context.AddBlock(HDBlockFields.SurfaceDescription.SpecularAAThreshold, lightingData.specularAA); } protected override void AddInspectorPropertyBlocks(SubTargetPropertiesGUI blockList) From 47f37894854c43617be90faf683b13fbb5bbbc57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Mon, 8 Jun 2020 16:28:57 +0200 Subject: [PATCH 26/30] Invert pass order --- .../Editor/Material/ShaderGraph/SurfaceSubTarget.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 786bbed2c4a..ca854fc93f9 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 @@ -71,8 +71,8 @@ PassCollection GetPasses() var passes = new PassCollection { // Common "surface" passes - HDShaderPasses.GenerateSceneSelection(supportLighting), HDShaderPasses.GenerateShadowCaster(supportLighting), + HDShaderPasses.GenerateSceneSelection(supportLighting), HDShaderPasses.GenerateMETA(supportLighting), HDShaderPasses.GenerateMotionVectors(supportLighting), { HDShaderPasses.GenerateBackThenFront(supportLighting), new FieldCondition(HDFields.TransparentBackFace, true)}, From c99ad0bc7ccd608bffbc9d93b040cd731dd70eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Mon, 8 Jun 2020 18:05:55 +0200 Subject: [PATCH 27/30] Fixed shadow matte --- .../Material/ShaderGraph/HDShaderPasses.cs | 17 +++++++++-------- .../Material/ShaderGraph/SurfaceSubTarget.cs | 9 ++++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index 6b1e3fc614c..c22cc960e23 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -135,7 +135,6 @@ static public PassDescriptor GenerateShadowCaster(bool supportLighting) pragmas = CorePragmas.DotsInstancedInV2Only, keywords = CoreKeywords.HDBase, includes = GenerateIncludes(), - requiredFields = supportLighting ? null : UnlitFieldCollection, }; IncludeCollection GenerateIncludes() @@ -159,11 +158,6 @@ IncludeCollection GenerateIncludes() } } - public static FieldCollection UnlitFieldCollection = new FieldCollection - { - HDFields.SubShader.Unlit, - }; - #endregion #region META pass @@ -357,11 +351,11 @@ public static PassDescriptor GenereateForwardOnlyPass(bool supportLighting) useInPreview = true, // Collections - requiredFields = CoreRequiredFields.LitFull, + requiredFields = supportLighting ? CoreRequiredFields.LitFull : null, renderStates = CoreRenderStates.Forward, pragmas = CorePragmas.DotsInstancedInV2Only, defines = supportLighting ? CoreDefines.Forward : null, - keywords = CoreKeywords.Forward, + keywords = supportLighting ? CoreKeywords.Forward : UnlitForwardKeywords, includes = GenerateIncludes(), }; @@ -395,6 +389,13 @@ IncludeCollection GenerateIncludes() } } + public static KeywordCollection UnlitForwardKeywords = new KeywordCollection + { + { CoreKeywords.HDBase }, + { CoreKeywordDescriptors.DebugDisplay }, + { CoreKeywordDescriptors.Shadow, new FieldCondition(HDFields.EnableShadowMatte, true) }, + }; + #endregion #region Back then front pass 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 ca854fc93f9..2042f6d416c 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 @@ -72,8 +72,8 @@ PassCollection GetPasses() { // Common "surface" passes HDShaderPasses.GenerateShadowCaster(supportLighting), - HDShaderPasses.GenerateSceneSelection(supportLighting), HDShaderPasses.GenerateMETA(supportLighting), + HDShaderPasses.GenerateSceneSelection(supportLighting), HDShaderPasses.GenerateMotionVectors(supportLighting), { HDShaderPasses.GenerateBackThenFront(supportLighting), new FieldCondition(HDFields.TransparentBackFace, true)}, { HDShaderPasses.GenerateTransparentDepthPostpass(supportLighting), new FieldCondition(HDFields.TransparentDepthPostPass, true) }, @@ -168,8 +168,11 @@ SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor // Replace valid pixel blocks by automatic thing so we don't have to write them var tmpCtx = new TargetActiveBlockContext(new List(), passDescriptor); GetActiveBlocks(ref tmpCtx); - passDescriptor.validPixelBlocks = tmpCtx.activeBlocks.Where(b => b.shaderStage == ShaderStage.Fragment).ToArray(); - passDescriptor.validVertexBlocks = tmpCtx.activeBlocks.Where(b => b.shaderStage == ShaderStage.Vertex).ToArray(); + if (passDescriptor.validPixelBlocks == null) + passDescriptor.validPixelBlocks = tmpCtx.activeBlocks.Where(b => b.shaderStage == ShaderStage.Fragment).ToArray(); + if (passDescriptor.validVertexBlocks == null) + // passDescriptor.validVertexBlocks = tmpCtx.activeBlocks.Where(b => b.shaderStage == ShaderStage.Vertex).ToArray(); + passDescriptor.validVertexBlocks = CoreBlockMasks.Vertex; // Set default values for HDRP "surface" passes: if (passDescriptor.structs == null) From 50e9fe34479219582f1b3d83cf563740b2a8caa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Mon, 8 Jun 2020 18:15:13 +0200 Subject: [PATCH 28/30] Enable virtual texturing in forward only --- .../Editor/Material/ShaderGraph/HDShaderPasses.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index c22cc960e23..e80ffc03f25 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -223,6 +223,8 @@ public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting) defines = supportLighting ? CoreDefines.DepthMotionVectors : null, keywords = CoreKeywords.DepthMotionVectorsNoNormal, includes = GenerateIncludes(), + + virtualTextureFeedback = true, }; FieldCollection GenerateRequiredFields() From 65b04f12361ed09d34455a48003e88a5ccf25f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Mon, 8 Jun 2020 18:20:29 +0200 Subject: [PATCH 29/30] Wrong emplacement for virtual texture feedback --- .../Editor/Material/ShaderGraph/HDShaderPasses.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index e80ffc03f25..769da5ef8be 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -223,8 +223,6 @@ public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting) defines = supportLighting ? CoreDefines.DepthMotionVectors : null, keywords = CoreKeywords.DepthMotionVectorsNoNormal, includes = GenerateIncludes(), - - virtualTextureFeedback = true, }; FieldCollection GenerateRequiredFields() @@ -359,6 +357,8 @@ public static PassDescriptor GenereateForwardOnlyPass(bool supportLighting) defines = supportLighting ? CoreDefines.Forward : null, keywords = supportLighting ? CoreKeywords.Forward : UnlitForwardKeywords, includes = GenerateIncludes(), + + virtualTextureFeedback = supportLighting ? false : true, }; IncludeCollection GenerateIncludes() From 0ebf59f8e56add13078de41433aef38f330f2b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Leli=C3=A8vre?= Date: Tue, 9 Jun 2020 12:30:36 +0200 Subject: [PATCH 30/30] Fixed unwanted require field list modification --- .../Material/ShaderGraph/SurfaceSubTarget.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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 2042f6d416c..78d482831de 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 @@ -149,9 +149,18 @@ SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor passDescriptor.passTemplatePath = templatePath; passDescriptor.sharedTemplateDirectory = HDTarget.sharedTemplateDirectory; + // Add the subShader to enable fields that depends on it + var originalRequireFields = passDescriptor.requiredFields; + // Duplicate require fields to avoid unwanted shared list modification + passDescriptor.requiredFields = new FieldCollection(); + if (originalRequireFields != null) + foreach (var field in originalRequireFields) + passDescriptor.requiredFields.Add(field.field); + passDescriptor.requiredFields.Add(subShaderField); + IncludeCollection finalIncludes = new IncludeCollection(); var includeList = passDescriptor.includes.Select(include => include.descriptor).ToList(); - + // Replace include placeholders if necessary: foreach (var include in passDescriptor.includes) { @@ -180,11 +189,6 @@ SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShaderDescriptor if (passDescriptor.fieldDependencies == null) passDescriptor.fieldDependencies = CoreFieldDependencies.Default; - // Add the subShader to enable fields that depends on it - if (passDescriptor.requiredFields == null) - passDescriptor.requiredFields = new FieldCollection(); - passDescriptor.requiredFields.Add(subShaderField); - finalPasses.Add(passDescriptor, passes[i].fieldConditions); }