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..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 @@ -15,14 +15,16 @@ 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"; + public static string passTemplatePath => $"{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(); 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; @@ -84,8 +86,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(); @@ -575,6 +575,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/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/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.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs index 948f9d206d1..5427da12051 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 @@ -31,7 +31,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary { - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Eye/ShaderGraph/EyePass.template"; + public EyeSubTarget() => displayName = "Eye"; + + 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; + protected override string subShaderInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Eye/Eye.hlsl"; + protected override FieldDescriptor subShaderField => HDFields.SubShader.Eye; - public EyeSubTarget() => displayName = "Eye"; + protected override bool supportRaytracing => false; + protected override bool requireSplitLighting => eyeData.subsurfaceScattering; EyeData m_EyeData; @@ -36,20 +41,14 @@ 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); + context.AddField(HDFields.SubsurfaceScattering, eyeData.subsurfaceScattering && systemData.surfaceType != SurfaceType.Transparent); context.AddField(HDFields.DoAlphaTest, systemData.alphaTest && context.pass.validPixelBlocks.Contains(BlockFields.SurfaceDescription.AlphaClipThreshold)); } @@ -58,13 +57,11 @@ 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, 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) @@ -73,293 +70,7 @@ 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 - -#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 + protected override int ComputeMaterialNeedsUpdateHash() + => base.ComputeMaterialNeedsUpdateHash() * 23 + eyeData.subsurfaceScattering.GetHashCode(); } } 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 2fd7d88dfb2..b96846064e9 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 @@ -29,7 +29,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary { - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Fabric/ShaderGraph/FabricPass.template"; - public FabricSubTarget() => displayName = "Fabric"; + 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; + 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; @@ -37,10 +39,14 @@ public FabricData fabricData set => m_FabricData = value; } - protected override IEnumerable EnumerateSubShaders() + protected override SubShaderDescriptor GetRaytracingSubShaderDescriptor() { - yield return SubShaders.Fabric; - yield return SubShaders.FabricRaytracing; + var descriptor = base.GetRaytracingSubShaderDescriptor(); + + if (fabricData.subsurfaceScattering) + descriptor.passes.Add(HDShaderPasses.GenerateRaytracingSubsurface()); + + return descriptor; } public override void GetFields(ref TargetFieldContext context) @@ -48,10 +54,9 @@ 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); + 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); @@ -62,10 +67,9 @@ 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, 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 @@ -82,564 +86,7 @@ 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.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 + protected override int ComputeMaterialNeedsUpdateHash() + => base.ComputeMaterialNeedsUpdateHash() * 23 + fabricData.subsurfaceScattering.GetHashCode(); } } 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.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.Migration.cs index c2ee7c09669..3e07eedddf4 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 @@ -31,7 +31,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary { - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Hair/ShaderGraph/HairPass.template"; + public HairSubTarget() => displayName = "Hair"; + + 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; + protected override string subShaderInclude => CoreIncludes.kHair; + protected override FieldDescriptor subShaderField => HDFields.SubShader.Hair; + protected override bool requireSplitLighting => false; - public HairSubTarget() => displayName = "Hair"; HairData m_HairData; @@ -36,23 +40,12 @@ 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: - // Make sure that we don't end up in an unsupported configuration - lightingData.subsurfaceScattering = false; - base.GetFields(ref context); var descs = context.blocks.Select(x => x.descriptor); // 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, descs.Contains(HDBlockFields.SurfaceDescription.HairStrandDirection) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.HairStrandDirection)); context.AddField(HDFields.RimTransmissionIntensity, descs.Contains(HDBlockFields.SurfaceDescription.RimTransmissionIntensity) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.RimTransmissionIntensity)); @@ -75,7 +68,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); @@ -91,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.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs index 63881ad6511..d0bfe618e05 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 @@ -113,7 +113,7 @@ void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary { - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Lit/ShaderGraph/LitPass.template"; - - public HDLitSubTarget() => displayName = "Lit"; - - protected override string customInspector => "Rendering.HighDefinition.HDLitGUI"; - protected override string subTargetAssetGuid => "caab952c840878340810cca27417971c"; // HDLitSubTarget.cs - protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; - HDLitData m_LitData; HDLitData IRequiresData.data @@ -37,11 +29,42 @@ public HDLitData litData set => m_LitData = value; } - // Iterate over the sub passes available in the shader - protected override IEnumerable EnumerateSubShaders() + public HDLitSubTarget() => displayName = "Lit"; + + 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; + protected override string subShaderInclude => CoreIncludes.kLit; + + // 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(); + + descriptor.passes.Add(HDShaderPasses.GenerateLitDepthOnly()); + descriptor.passes.Add(HDShaderPasses.GenerateGBuffer()); + descriptor.passes.Add(HDShaderPasses.GenerateLitForward()); + descriptor.passes.Add(HDShaderPasses.GenerateLitRaytracingPrepass()); + + return descriptor; + } + + protected override SubShaderDescriptor GetRaytracingSubShaderDescriptor() { - yield return SubShaders.Lit; - yield return SubShaders.LitRaytracing; + var descriptor = base.GetRaytracingSubShaderDescriptor(); + + if (litData.materialType == HDLitData.MaterialType.SubsurfaceScattering) + descriptor.passes.Add(HDShaderPasses.GenerateRaytracingSubsurface()); + + return descriptor; } public override void GetFields(ref TargetFieldContext context) @@ -53,8 +76,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 @@ -67,9 +88,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); @@ -98,7 +116,6 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) // Vertex base.GetActiveBlocks(ref context); - AddDistortionBlocks(ref context); // Common context.AddBlock(HDBlockFields.SurfaceDescription.CoatMask, litData.clearCoat); @@ -150,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/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/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..769da5ef8be --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -0,0 +1,1024 @@ +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 supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "DistortionVectors", + referenceName = "SHADERPASS_DISTORTION", + lightMode = "DistortionVectors", + useInPreview = true, + + // Collections + 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) }, + { 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", + }) } + }; + } + + 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.kDisortionVectors, IncludeLocation.Postgraph); + + return includes; + } + } + + +#endregion + +#region Scene Selection Pass + + public static PassDescriptor GenerateSceneSelection(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "SceneSelectionPass", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "SceneSelectionPass", + useInPreview = false, + + // Collections + renderStates = CoreRenderStates.SceneSelection, + pragmas = CorePragmas.DotsInstancedInV1AndV2EditorSync, + defines = CoreDefines.SceneSelection, + 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; + } + } + +#endregion + +#region Shadow Caster Pass + + static public PassDescriptor GenerateShadowCaster(bool supportLighting) + { + return new PassDescriptor() + { + // Definition + displayName = "ShadowCaster", + referenceName = "SHADERPASS_SHADOWS", + lightMode = "ShadowCaster", + useInPreview = false, + + // Collections + renderStates = CoreRenderStates.ShadowCaster, + pragmas = CorePragmas.DotsInstancedInV2Only, + 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; + } + } + +#endregion + +#region META pass + + public static PassDescriptor GenerateMETA(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "META", + referenceName = "SHADERPASS_LIGHT_TRANSPORT", + lightMode = "META", + useInPreview = false, + + // Collections + requiredFields = CoreRequiredFields.Meta, + renderStates = CoreRenderStates.Meta, + 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.kPassLightTransport, IncludeLocation.Postgraph); + + return includes; + } + } + +#endregion + +#region Depth Forward Only + + public static PassDescriptor GenerateDepthForwardOnlyPass(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "DepthForwardOnly", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "DepthForwardOnly", + useInPreview = true, + + // Collections + requiredFields = GenerateRequiredFields(), + renderStates = CoreRenderStates.DepthOnly, + pragmas = CorePragmas.DotsInstancedInV2Only, + defines = supportLighting ? CoreDefines.DepthMotionVectors : null, + 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 (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.kShaderGraphFunctions, IncludeLocation.Pregraph); + includes.Add(CoreIncludes.kPassDepthOnly, IncludeLocation.Postgraph); + + return includes; + } + } + +#endregion + +#region Motion Vectors + + public static PassDescriptor GenerateMotionVectors(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "MotionVectors", + referenceName = "SHADERPASS_MOTION_VECTORS", + lightMode = "MotionVectors", + useInPreview = false, + + // Collections + requiredFields = CoreRequiredFields.LitFull, + renderStates = GenerateRenderState(), + defines = supportLighting ? CoreDefines.DepthMotionVectors : null, + 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; + } + } + + +#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, + + // Collections + requiredFields = supportLighting ? CoreRequiredFields.LitFull : null, + renderStates = CoreRenderStates.Forward, + pragmas = CorePragmas.DotsInstancedInV2Only, + defines = supportLighting ? CoreDefines.Forward : null, + keywords = supportLighting ? CoreKeywords.Forward : UnlitForwardKeywords, + includes = GenerateIncludes(), + + virtualTextureFeedback = supportLighting ? false : true, + }; + + 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 KeywordCollection UnlitForwardKeywords = new KeywordCollection + { + { CoreKeywords.HDBase }, + { CoreKeywordDescriptors.DebugDisplay }, + { CoreKeywordDescriptors.Shadow, new FieldCondition(HDFields.EnableShadowMatte, true) }, + }; + +#endregion + +#region Back then front pass + + public static PassDescriptor GenerateBackThenFront(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "TransparentBackface", + referenceName = supportLighting ? "SHADERPASS_FORWARD" : "SHADERPASS_FORWARD_UNLIT", + lightMode = "TransparentBackface", + useInPreview = true, + + // Collections + requiredFields = CoreRequiredFields.LitMinimal, + 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; + } + } + +#endregion + +#region Transparent Depth Prepass + + public static PassDescriptor GenerateTransparentDepthPrepass(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "TransparentDepthPrepass", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "TransparentDepthPrepass", + useInPreview = true, + + // Collections + requiredFields = TransparentDepthPrepassFields, + 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, + }; + +#endregion + +#region Transparent Depth Postpass + + public static PassDescriptor GenerateTransparentDepthPostpass(bool supportLighting) + { + return new PassDescriptor + { + // Definition + displayName = "TransparentDepthPostpass", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "TransparentDepthPostpass", + useInPreview = true, + + // Collections + 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; + } + } + +#endregion + +#region Lit DepthOnly + + public static PassDescriptor GenerateLitDepthOnly() + { + return new PassDescriptor + { + displayName = "DepthOnly", + referenceName = "SHADERPASS_DEPTH_ONLY", + lightMode = "DepthOnly", + useInPreview = true, + + // Collections + requiredFields = CoreRequiredFields.LitFull, + 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, + + // Collections + requiredFields = CoreRequiredFields.LitMinimal, + 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, + + // Collections + requiredFields = CoreRequiredFields.LitMinimal, + 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, + + // Collections + 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.kPostDecalsPlaceholder, 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) + { + return new PassDescriptor + { + // Definition + displayName = "IndirectDXR", + referenceName = "SHADERPASS_RAYTRACING_INDIRECT", + lightMode = "IndirectDXR", + useInPreview = false, + + // Collections + pragmas = CorePragmas.RaytracingBasic, + defines = supportLighting ? GenerateDefines() : null, + keywords = CoreKeywords.RaytracingIndirect, + includes = CoreIncludes.Raytracing, + requiredFields = new FieldCollection(){ HDFields.ShaderPass.RaytracingIndirect }, + }; + + DefineCollection GenerateDefines() + { + return new DefineCollection + { + { Defines.shadowLow }, + { Defines.raytracingLow }, + { CoreKeywordDescriptors.HasLightloop, 1 }, + }; + } + } + +#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 + 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 + { + { Defines.raytracingLow }, + }; + +#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 + 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 + { + { Defines.shadowLow }, + { RayTracingNode.GetRayTracingKeyword(), 0 }, + { CoreKeywordDescriptors.HasLightloop, 1 }, + }; + +#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 + 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 + { + { Defines.shadowLow }, + { Defines.raytracingLow }, + }; + +#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 + 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 + { + { Defines.shadowLow }, + { RayTracingNode.GetRayTracingKeyword(), 0 }, + { CoreKeywordDescriptors.HasLightloop, 1 }, + }; + +#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 + pragmas = CorePragmas.RaytracingBasic, + defines = RaytracingSubsurfaceDefines, + keywords = CoreKeywords.RaytracingGBufferForward, + includes = CoreIncludes.Raytracing, + requiredFields = new FieldCollection(){ HDFields.ShaderPass.RaytracingSubSurface }, + }; + } + + public static DefineCollection RaytracingSubsurfaceDefines = new DefineCollection + { + { 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 + + } +} \ 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/HDSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs index 8b6096e3b13..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 @@ -47,6 +47,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; @@ -58,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 95c9d89a3b9..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 @@ -23,14 +23,20 @@ LightingData IRequiresData.data set => m_LightingData = value; } - protected override string renderType => HDRenderTypeTags.HDLitShader.ToString(); - public LightingData lightingData { get => m_LightingData; set => m_LightingData = value; } + 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); @@ -47,12 +53,17 @@ 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; } + 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; + + protected abstract bool requireSplitLighting { get; } + public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); @@ -82,6 +93,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) @@ -114,7 +129,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); } } } 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 440e0171e24..fa15dec0812 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 0a4c9f31bcd..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 @@ -35,11 +35,177 @@ protected override string renderQueue get => HDRenderQueue.GetShaderTagValue(HDRenderQueue.ChangeType(systemData.renderingPass, systemData.sortPriority, systemData.alphaTest)); } + protected virtual bool supportForward => false; + protected virtual bool supportLighting => false; + protected virtual bool supportDistortion => false; + protected virtual bool supportPathtracing => false; + protected virtual bool supportRaytracing => true; + + protected abstract string subShaderInclude { get; } + protected virtual string postDecalsInclude => null; + protected abstract FieldDescriptor subShaderField { get; } + + 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()); + 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 + HDShaderPasses.GenerateShadowCaster(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) }, + }; + + if (supportLighting) + { + passes.Add(HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ + new FieldCondition(HDFields.TransparentDepthPrePass, true), + new FieldCondition(HDFields.DisableSSRTransparent, true) }); + passes.Add(HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ + new FieldCondition(HDFields.TransparentDepthPrePass, true), + new FieldCondition(HDFields.DisableSSRTransparent, false) }); + passes.Add(HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition[]{ + new FieldCondition(HDFields.TransparentDepthPrePass, false), + new FieldCondition(HDFields.DisableSSRTransparent, false) }); + } + else + { + passes.Add(HDShaderPasses.GenerateTransparentDepthPrepass(supportLighting), new FieldCondition(HDFields.TransparentDepthPrePass, true)); + } + + if (supportForward) + { + passes.Add(HDShaderPasses.GenerateDepthForwardOnlyPass(supportLighting)); + passes.Add(HDShaderPasses.GenereateForwardOnlyPass(supportLighting)); + } + if (supportDistortion) + passes.Add(HDShaderPasses.GenerateDistortionPass(supportLighting), new FieldCondition(HDFields.TransparentDistortion, true)); + + return passes; + } + } + + protected virtual SubShaderDescriptor GetRaytracingSubShaderDescriptor() + { + return new SubShaderDescriptor + { + generatesPreview = false, + passes = GetPasses(), + }; + + 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)); + }; + + if (supportPathtracing) + passes.Add(HDShaderPasses.GeneratePathTracing(supportLighting)); + + return passes; + } + } + + 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; + + // 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) + { + if (include.descriptor.value == CoreIncludes.kPassPlaceholder) + include.descriptor.value = subShaderInclude; + if (include.descriptor.value == CoreIncludes.kPostDecalsPlaceholder) + include.descriptor.value = postDecalsInclude; + + 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 + var tmpCtx = new TargetActiveBlockContext(new List(), passDescriptor); + GetActiveBlocks(ref tmpCtx); + 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) + passDescriptor.structs = CoreStructCollections.Default; + if (passDescriptor.fieldDependencies == null) + passDescriptor.fieldDependencies = CoreFieldDependencies.Default; + + finalPasses.Add(passDescriptor, passes[i].fieldConditions); + } + + subShaderDescriptor.passes = finalPasses; + + return subShaderDescriptor; + } + 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) + 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); @@ -85,6 +251,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); @@ -98,9 +267,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); @@ -163,7 +338,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera systemData.blendMode, systemData.sortPriority, builtinData.alphaToMask, - systemData.zWrite, + systemData.transparentZWrite, systemData.transparentCullMode, systemData.zTest, builtinData.backThenFrontRendering, @@ -176,12 +351,13 @@ 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); 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 60919f77fec..a091f9b8ad9 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 @@ -29,7 +29,7 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary { - const string kAssetGuid = "5f7ba34a143e67647b202a662748dae3"; - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/StackLit/ShaderGraph/StackLitPass.template"; + public StackLitSubTarget() => displayName = "StackLit"; + + 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; + 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; - public StackLitSubTarget() => displayName = "StackLit"; + protected override bool supportDistortion => true; + protected override bool requireSplitLighting => stackLitData.subsurfaceScattering; StackLitData m_StackLitData; @@ -40,121 +45,15 @@ public StackLitData stackLitData set => m_StackLitData = value; } - protected override IEnumerable EnumerateSubShaders() + protected override SubShaderDescriptor GetRaytracingSubShaderDescriptor() { - 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 + var descriptor = base.GetRaytracingSubShaderDescriptor(); - // 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!! + if (stackLitData.subsurfaceScattering) + descriptor.passes.Add(HDShaderPasses.GenerateRaytracingSubsurface()); - // 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 + return descriptor; + } public override void GetFields(ref TargetFieldContext context) { @@ -163,8 +62,6 @@ public override void GetFields(ref TargetFieldContext context) var descs = context.blocks.Select(x => x.descriptor); // StackLit specific properties - context.AddField(HDStructFields.FragInputs.IsFrontFace, systemData.doubleSidedMode != DoubleSidedMode.Disabled && !context.pass.Equals(StackLitSubTarget.StackLitPasses.MotionVectors)); - // Material context.AddField(HDFields.Anisotropy, stackLitData.anisotropy); context.AddField(HDFields.Coat, stackLitData.coat); @@ -176,7 +73,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); @@ -287,17 +184,13 @@ public override void GetFields(ref TargetFieldContext context) public override void GetActiveBlocks(ref TargetActiveBlockContext context) { base.GetActiveBlocks(ref context); - AddDistortionBlocks(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, 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); @@ -340,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) @@ -425,738 +314,7 @@ public static bool SpecularOcclusionConeFixupMethodModifiesRoughness(StackLitDat || soConeFixupMethod == StackLitData.SpecularOcclusionConeFixupMethod.BoostAndTilt); } -#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 + protected override int ComputeMaterialNeedsUpdateHash() + => base.ComputeMaterialNeedsUpdateHash() * 23 + stackLitData.subsurfaceScattering.GetHashCode(); } } 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..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); @@ -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/HDUnlitDistortionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Unlit/ShaderGraph/HDUnlitDistortionPropertyBlock.cs index b52e23c356c..fbc86bfcb56 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,7 +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); base.CreatePropertyGUI(); } } 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 87f43f75dfc..55ae144d56e 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 @@ -13,7 +13,7 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph { - sealed partial class HDUnlitSubTarget : SurfaceSubTarget, ILegacyTarget, IRequiresData + sealed partial class HDUnlitSubTarget : ILegacyTarget { public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary blockMap) { @@ -43,7 +43,7 @@ void UpgradeUnlitMasterNode(UnlitMasterNode1 unlitMasterNode, out Dictionary + sealed partial class HDUnlitSubTarget : SurfaceSubTarget, IRequiresData { + public HDUnlitSubTarget() => 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 - static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Unlit/ShaderGraph/HDUnlitPass.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"; + protected override FieldDescriptor subShaderField => HDFields.SubShader.Unlit; + protected override string subShaderInclude => CoreIncludes.kUnlit; - public HDUnlitSubTarget() => displayName = "Unlit"; + protected override bool supportDistortion => true; + protected override bool supportForward => true; + protected override bool supportPathtracing => true; HDUnlitData m_UnlitData; @@ -40,16 +44,35 @@ 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 && builtinData.distortion) + { + return new SubShaderDescriptor + { + generatesPreview = true, + passes = new PassCollection{ { HDShaderPasses.GenerateDistortionPass(false), new FieldCondition(HDFields.TransparentDistortion, true) } } + }; + } + else + { + 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)); + + return descriptor; + } } public override void GetFields(ref TargetFieldContext context) { base.GetFields(ref context); - AddDistortionFields(ref context); // Unlit specific properties context.AddField(HDFields.EnableShadowMatte, unlitData.enableShadowMatte); @@ -59,7 +82,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); @@ -90,563 +112,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera } // Stencil state for unlit: - 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 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 }, - }; + HDSubShaderUtilities.AddStencilShaderProperties(collector, systemData, null, false); } -#endregion } } 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 be0eb8f1caf..a3d734b28e8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDFields.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDFields.cs @@ -178,6 +178,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 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 e4501c685b3..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; } @@ -111,7 +109,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 +121,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 386c85790a1..1bc32474d61 100644 --- a/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/ShaderGraph/HDTarget.cs @@ -991,14 +991,19 @@ 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 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 { 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 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; diff --git a/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs b/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs index 6fcd4975a30..d59fc5d8a0a 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 4ad3d8221e1..9e19284cae9 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,