Exemple #1
0
        void UpgradeUnlitMasterNode(UnlitMasterNode1 unlitMasterNode, out Dictionary <BlockFieldDescriptor, int> blockMap)
        {
            m_MigrateFromOldCrossPipelineSG = true;
            m_MigrateFromOldSG = true;

            // Set data
            systemData.surfaceType = (SurfaceType)unlitMasterNode.m_SurfaceType;
            systemData.blendMode   = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)unlitMasterNode.m_AlphaMode);
            // Previous master node wasn't having any renderingPass. Assign it correctly now.
            systemData.renderQueueType         = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent;
            systemData.doubleSidedMode         = unlitMasterNode.m_TwoSided ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled;
            systemData.alphaTest               = HDSubShaderUtilities.UpgradeLegacyAlphaClip(unlitMasterNode);
            systemData.dotsInstancing          = false;
            systemData.transparentZWrite       = false;
            builtinData.addPrecomputedVelocity = false;
            target.customEditorGUI             = unlitMasterNode.m_OverrideEnabled ? unlitMasterNode.m_ShaderGUIOverride : "";

            // Set blockmap
            blockMap = new Dictionary <BlockFieldDescriptor, int>()
            {
                { BlockFields.VertexDescription.Position, 9 },
                { BlockFields.VertexDescription.Normal, 10 },
                { BlockFields.VertexDescription.Tangent, 11 },
                { BlockFields.SurfaceDescription.BaseColor, 0 },
                { BlockFields.SurfaceDescription.Alpha, 7 },
                { BlockFields.SurfaceDescription.AlphaClipThreshold, 8 },
            };
        }
Exemple #2
0
        void UpgradeHDUnlitMasterNode(HDUnlitMasterNode1 hdUnlitMasterNode, out Dictionary <BlockFieldDescriptor, int> blockMap)
        {
            m_MigrateFromOldSG = true;

            // Set data
            systemData.surfaceType     = (SurfaceType)hdUnlitMasterNode.m_SurfaceType;
            systemData.blendMode       = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)hdUnlitMasterNode.m_AlphaMode);
            systemData.renderQueueType = HDRenderQueue.MigrateRenderQueueToHDRP10(hdUnlitMasterNode.m_RenderingPass);
            // Patch rendering pass in case the master node had an old configuration
            if (systemData.renderQueueType == HDRenderQueue.RenderQueueType.Background)
            {
                systemData.renderQueueType = HDRenderQueue.RenderQueueType.Opaque;
            }
            systemData.alphaTest           = hdUnlitMasterNode.m_AlphaTest;
            systemData.sortPriority        = hdUnlitMasterNode.m_SortPriority;
            systemData.doubleSidedMode     = hdUnlitMasterNode.m_DoubleSided ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled;
            systemData.transparentZWrite   = hdUnlitMasterNode.m_ZWrite;
            systemData.transparentCullMode = hdUnlitMasterNode.m_transparentCullMode;
            systemData.zTest          = hdUnlitMasterNode.m_ZTest;
            systemData.dotsInstancing = hdUnlitMasterNode.m_DOTSInstancing;

            builtinData.transparencyFog        = hdUnlitMasterNode.m_TransparencyFog;
            builtinData.distortion             = hdUnlitMasterNode.m_Distortion;
            builtinData.distortionMode         = hdUnlitMasterNode.m_DistortionMode;
            builtinData.distortionDepthTest    = hdUnlitMasterNode.m_DistortionDepthTest;
            builtinData.alphaToMask            = hdUnlitMasterNode.m_AlphaToMask;
            builtinData.addPrecomputedVelocity = hdUnlitMasterNode.m_AddPrecomputedVelocity;

            unlitData.distortionOnly    = hdUnlitMasterNode.m_DistortionOnly;
            unlitData.enableShadowMatte = hdUnlitMasterNode.m_EnableShadowMatte;
            target.customEditorGUI      = hdUnlitMasterNode.m_OverrideEnabled ? hdUnlitMasterNode.m_ShaderGUIOverride : "";

            // Set blockmap
            blockMap = new Dictionary <BlockFieldDescriptor, int>()
            {
                { BlockFields.VertexDescription.Position, 9 },
                { BlockFields.VertexDescription.Normal, 13 },
                { BlockFields.VertexDescription.Tangent, 14 },
                { BlockFields.SurfaceDescription.BaseColor, 0 },
                { BlockFields.SurfaceDescription.Alpha, 7 },
                { BlockFields.SurfaceDescription.AlphaClipThreshold, 8 },
                { BlockFields.SurfaceDescription.Emission, 12 },
            };

            // Distortion
            if (systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.Distortion, 10);
                blockMap.Add(HDBlockFields.SurfaceDescription.DistortionBlur, 11);
            }

            // Shadow Matte
            if (unlitData.enableShadowMatte)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.ShadowTint, 15);
            }
        }
        public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary <BlockFieldDescriptor, int> blockMap)
        {
            blockMap = null;
            if (!(masterNode is StackLitMasterNode1 stackLitMasterNode))
            {
                return(false);
            }

            m_MigrateFromOldSG = true;

            // Set data
            systemData.surfaceType = (SurfaceType)stackLitMasterNode.m_SurfaceType;
            systemData.blendMode   = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)stackLitMasterNode.m_AlphaMode);
            // Previous master node wasn't having any renderingPass. Assign it correctly now.
            systemData.renderingPass       = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent;
            systemData.alphaTest           = stackLitMasterNode.m_AlphaTest;
            systemData.sortPriority        = stackLitMasterNode.m_SortPriority;
            systemData.doubleSidedMode     = stackLitMasterNode.m_DoubleSidedMode;
            systemData.transparentZWrite   = stackLitMasterNode.m_ZWrite;
            systemData.transparentCullMode = stackLitMasterNode.m_transparentCullMode;
            systemData.zTest                   = stackLitMasterNode.m_ZTest;
            systemData.dotsInstancing          = stackLitMasterNode.m_DOTSInstancing;
            systemData.materialNeedsUpdateHash = stackLitMasterNode.m_MaterialNeedsUpdateHash;

            builtinData.supportLodCrossFade    = stackLitMasterNode.m_SupportLodCrossFade;
            builtinData.transparencyFog        = stackLitMasterNode.m_TransparencyFog;
            builtinData.distortion             = stackLitMasterNode.m_Distortion;
            builtinData.distortionMode         = stackLitMasterNode.m_DistortionMode;
            builtinData.distortionDepthTest    = stackLitMasterNode.m_DistortionDepthTest;
            builtinData.addPrecomputedVelocity = stackLitMasterNode.m_AddPrecomputedVelocity;
            builtinData.depthOffset            = stackLitMasterNode.m_depthOffset;
            builtinData.alphaToMask            = stackLitMasterNode.m_AlphaToMask;

            lightingData.normalDropOffSpace    = stackLitMasterNode.m_NormalDropOffSpace;
            lightingData.blendPreserveSpecular = stackLitMasterNode.m_BlendPreserveSpecular;
            lightingData.receiveDecals         = stackLitMasterNode.m_ReceiveDecals;
            lightingData.receiveSSR            = stackLitMasterNode.m_ReceiveSSR;
            lightingData.receiveSSRTransparent = stackLitMasterNode.m_ReceivesSSRTransparent;
            lightingData.overrideBakedGI       = stackLitMasterNode.m_overrideBakedGI;
            lightingData.specularAA            = stackLitMasterNode.m_GeometricSpecularAA;

            stackLitData.subsurfaceScattering            = stackLitMasterNode.m_SubsurfaceScattering;
            stackLitData.transmission                    = stackLitMasterNode.m_Transmission;
            stackLitData.energyConservingSpecular        = stackLitMasterNode.m_EnergyConservingSpecular;
            stackLitData.baseParametrization             = stackLitMasterNode.m_BaseParametrization;
            stackLitData.dualSpecularLobeParametrization = stackLitMasterNode.m_DualSpecularLobeParametrization;
            stackLitData.anisotropy             = stackLitMasterNode.m_Anisotropy;
            stackLitData.coat                   = stackLitMasterNode.m_Coat;
            stackLitData.coatNormal             = stackLitMasterNode.m_CoatNormal;
            stackLitData.dualSpecularLobe       = stackLitMasterNode.m_DualSpecularLobe;
            stackLitData.capHazinessWrtMetallic = stackLitMasterNode.m_CapHazinessWrtMetallic;
            stackLitData.iridescence            = stackLitMasterNode.m_Iridescence;
            stackLitData.screenSpaceSpecularOcclusionBaseMode   = (StackLitData.SpecularOcclusionBaseMode)stackLitMasterNode.m_ScreenSpaceSpecularOcclusionBaseMode;
            stackLitData.dataBasedSpecularOcclusionBaseMode     = (StackLitData.SpecularOcclusionBaseMode)stackLitMasterNode.m_DataBasedSpecularOcclusionBaseMode;
            stackLitData.screenSpaceSpecularOcclusionAOConeSize = (StackLitData.SpecularOcclusionAOConeSize)stackLitMasterNode.m_ScreenSpaceSpecularOcclusionAOConeSize;
            stackLitData.screenSpaceSpecularOcclusionAOConeDir  = (StackLitData.SpecularOcclusionAOConeDir)stackLitMasterNode.m_ScreenSpaceSpecularOcclusionAOConeDir;
            stackLitData.dataBasedSpecularOcclusionAOConeSize   = (StackLitData.SpecularOcclusionAOConeSize)stackLitMasterNode.m_DataBasedSpecularOcclusionAOConeSize;
            stackLitData.specularOcclusionConeFixupMethod       = (StackLitData.SpecularOcclusionConeFixupMethod)stackLitMasterNode.m_SpecularOcclusionConeFixupMethod;
            stackLitData.anisotropyForAreaLights       = stackLitMasterNode.m_AnisotropyForAreaLights;
            stackLitData.recomputeStackPerLight        = stackLitMasterNode.m_RecomputeStackPerLight;
            stackLitData.honorPerLightMinRoughness     = stackLitMasterNode.m_HonorPerLightMinRoughness;
            stackLitData.shadeBaseUsingRefractedAngles = stackLitMasterNode.m_ShadeBaseUsingRefractedAngles;
            stackLitData.debug   = stackLitMasterNode.m_Debug;
            stackLitData.devMode = stackLitMasterNode.m_DevMode;

            target.customEditorGUI = stackLitMasterNode.m_OverrideEnabled ? stackLitMasterNode.m_ShaderGUIOverride : "";

            // Set blockmap
            blockMap = new Dictionary <BlockFieldDescriptor, int>();
            blockMap.Add(BlockFields.VertexDescription.Position, StackLitMasterNode1.PositionSlotId);
            blockMap.Add(BlockFields.VertexDescription.Normal, StackLitMasterNode1.VertexNormalSlotId);
            blockMap.Add(BlockFields.VertexDescription.Tangent, StackLitMasterNode1.VertexTangentSlotId);

            // Handle mapping of Normal block specifically
            BlockFieldDescriptor normalBlock;

            switch (lightingData.normalDropOffSpace)
            {
            case NormalDropOffSpace.Object:
                normalBlock = BlockFields.SurfaceDescription.NormalOS;
                break;

            case NormalDropOffSpace.World:
                normalBlock = BlockFields.SurfaceDescription.NormalWS;
                break;

            default:
                normalBlock = BlockFields.SurfaceDescription.NormalTS;
                break;
            }
            blockMap.Add(normalBlock, StackLitMasterNode1.NormalSlotId);

            blockMap.Add(HDBlockFields.SurfaceDescription.BentNormal, StackLitMasterNode1.BentNormalSlotId);
            blockMap.Add(HDBlockFields.SurfaceDescription.Tangent, StackLitMasterNode1.TangentSlotId);
            blockMap.Add(BlockFields.SurfaceDescription.BaseColor, StackLitMasterNode1.BaseColorSlotId);

            if (stackLitData.baseParametrization == StackLit.BaseParametrization.BaseMetallic)
            {
                blockMap.Add(BlockFields.SurfaceDescription.Metallic, StackLitMasterNode1.MetallicSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.DielectricIor, StackLitMasterNode1.DielectricIorSlotId);
            }
            else if (stackLitData.baseParametrization == StackLit.BaseParametrization.SpecularColor)
            {
                blockMap.Add(BlockFields.SurfaceDescription.Specular, StackLitMasterNode1.SpecularColorSlotId);
            }

            blockMap.Add(BlockFields.SurfaceDescription.Smoothness, StackLitMasterNode1.SmoothnessASlotId);

            if (stackLitData.anisotropy)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.Anisotropy, StackLitMasterNode1.AnisotropyASlotId);
            }

            blockMap.Add(BlockFields.SurfaceDescription.Occlusion, StackLitMasterNode1.AmbientOcclusionSlotId);

            if (stackLitData.dataBasedSpecularOcclusionBaseMode == StackLitData.SpecularOcclusionBaseMode.Custom)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.SpecularOcclusion, StackLitMasterNode1.SpecularOcclusionSlotId);
            }

            if (SpecularOcclusionUsesBentNormal(stackLitData) && stackLitData.specularOcclusionConeFixupMethod != StackLitData.SpecularOcclusionConeFixupMethod.Off)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.SOFixupVisibilityRatioThreshold, StackLitMasterNode1.SOFixupVisibilityRatioThresholdSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.SOFixupStrengthFactor, StackLitMasterNode1.SOFixupStrengthFactorSlotId);

                if (SpecularOcclusionConeFixupMethodModifiesRoughness(stackLitData.specularOcclusionConeFixupMethod))
                {
                    blockMap.Add(HDBlockFields.SurfaceDescription.SOFixupMaxAddedRoughness, StackLitMasterNode1.SOFixupMaxAddedRoughnessSlotId);
                }
            }

            if (stackLitData.coat)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.CoatSmoothness, StackLitMasterNode1.CoatSmoothnessSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.CoatIor, StackLitMasterNode1.CoatIorSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.CoatThickness, StackLitMasterNode1.CoatThicknessSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.CoatExtinction, StackLitMasterNode1.CoatExtinctionSlotId);

                if (stackLitData.coatNormal)
                {
                    blockMap.Add(HDBlockFields.SurfaceDescription.CoatNormalTS, StackLitMasterNode1.CoatNormalSlotId);
                }

                blockMap.Add(HDBlockFields.SurfaceDescription.CoatMask, StackLitMasterNode1.CoatMaskSlotId);
            }

            if (stackLitData.dualSpecularLobe)
            {
                if (stackLitData.dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.Direct)
                {
                    blockMap.Add(HDBlockFields.SurfaceDescription.SmoothnessB, StackLitMasterNode1.SmoothnessBSlotId);
                    blockMap.Add(HDBlockFields.SurfaceDescription.LobeMix, StackLitMasterNode1.LobeMixSlotId);
                }
                else if (stackLitData.dualSpecularLobeParametrization == StackLit.DualSpecularLobeParametrization.HazyGloss)
                {
                    blockMap.Add(HDBlockFields.SurfaceDescription.Haziness, StackLitMasterNode1.HazinessSlotId);
                    blockMap.Add(HDBlockFields.SurfaceDescription.HazeExtent, StackLitMasterNode1.HazeExtentSlotId);

                    if (stackLitData.capHazinessWrtMetallic && stackLitData.baseParametrization == StackLit.BaseParametrization.BaseMetallic) // the later should be an assert really
                    {
                        blockMap.Add(HDBlockFields.SurfaceDescription.HazyGlossMaxDielectricF0, StackLitMasterNode1.HazyGlossMaxDielectricF0SlotId);
                    }
                }

                if (stackLitData.anisotropy)
                {
                    blockMap.Add(HDBlockFields.SurfaceDescription.AnisotropyB, StackLitMasterNode1.AnisotropyBSlotId);
                }
            }

            if (stackLitData.iridescence)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceMask, StackLitMasterNode1.IridescenceMaskSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceThickness, StackLitMasterNode1.IridescenceThicknessSlotId);

                if (stackLitData.coat)
                {
                    blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIR, StackLitMasterNode1.IridescenceCoatFixupTIRSlotId);
                    blockMap.Add(HDBlockFields.SurfaceDescription.IridescenceCoatFixupTIRClamp, StackLitMasterNode1.IridescenceCoatFixupTIRClampSlotId);
                }
            }

            if (stackLitData.subsurfaceScattering)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.SubsurfaceMask, StackLitMasterNode1.SubsurfaceMaskSlotId);
            }

            if (stackLitData.transmission)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.Thickness, StackLitMasterNode1.ThicknessSlotId);
            }

            if (stackLitData.subsurfaceScattering || stackLitData.transmission)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.DiffusionProfileHash, StackLitMasterNode1.DiffusionProfileHashSlotId);
            }

            blockMap.Add(BlockFields.SurfaceDescription.Alpha, StackLitMasterNode1.AlphaSlotId);

            if (systemData.alphaTest)
            {
                blockMap.Add(BlockFields.SurfaceDescription.AlphaClipThreshold, StackLitMasterNode1.AlphaClipThresholdSlotId);
            }

            blockMap.Add(BlockFields.SurfaceDescription.Emission, StackLitMasterNode1.EmissionSlotId);

            if (systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.Distortion, StackLitMasterNode1.DistortionSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.DistortionBlur, StackLitMasterNode1.DistortionBlurSlotId);
            }

            if (lightingData.specularAA)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, StackLitMasterNode1.SpecularAAScreenSpaceVarianceSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAThreshold, StackLitMasterNode1.SpecularAAThresholdSlotId);
            }

            if (lightingData.overrideBakedGI)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, StackLitMasterNode1.LightingSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, StackLitMasterNode1.BackLightingSlotId);
            }

            if (builtinData.depthOffset)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, StackLitMasterNode1.DepthOffsetSlotId);
            }

            return(true);
        }
        public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary <BlockFieldDescriptor, int> blockMap)
        {
            blockMap = null;
            if (!(masterNode is EyeMasterNode1 eyeMasterNode))
            {
                return(false);
            }

            m_MigrateFromOldSG = true;

            // Set data
            systemData.surfaceType = (SurfaceType)eyeMasterNode.m_SurfaceType;
            systemData.blendMode   = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)eyeMasterNode.m_AlphaMode);
            // Previous master node wasn't having any renderingPass. Assign it correctly now.
            systemData.renderQueueType     = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent;
            systemData.alphaTest           = eyeMasterNode.m_AlphaTest;
            systemData.sortPriority        = eyeMasterNode.m_SortPriority;
            systemData.doubleSidedMode     = eyeMasterNode.m_DoubleSidedMode;
            systemData.transparentZWrite   = eyeMasterNode.m_ZWrite;
            systemData.transparentCullMode = eyeMasterNode.m_transparentCullMode;
            systemData.zTest                   = eyeMasterNode.m_ZTest;
            systemData.dotsInstancing          = eyeMasterNode.m_DOTSInstancing;
            systemData.materialNeedsUpdateHash = eyeMasterNode.m_MaterialNeedsUpdateHash;

            builtinData.transparentDepthPrepass  = eyeMasterNode.m_AlphaTestDepthPrepass;
            builtinData.transparentDepthPostpass = eyeMasterNode.m_AlphaTestDepthPostpass;
            builtinData.supportLodCrossFade      = eyeMasterNode.m_SupportLodCrossFade;
            builtinData.transparencyFog          = eyeMasterNode.m_TransparencyFog;
            builtinData.addPrecomputedVelocity   = eyeMasterNode.m_AddPrecomputedVelocity;
            builtinData.depthOffset = eyeMasterNode.m_depthOffset;
            builtinData.alphaToMask = eyeMasterNode.m_AlphaToMask;

            lightingData.blendPreserveSpecular = eyeMasterNode.m_BlendPreserveSpecular;
            lightingData.receiveDecals         = eyeMasterNode.m_ReceiveDecals;
            lightingData.receiveSSR            = eyeMasterNode.m_ReceivesSSR;
            lightingData.receiveSSRTransparent = eyeMasterNode.m_ReceivesSSRTransparent;
            lightingData.specularOcclusionMode = eyeMasterNode.m_SpecularOcclusionMode;
            lightingData.overrideBakedGI       = eyeMasterNode.m_overrideBakedGI;

            eyeData.subsurfaceScattering = eyeMasterNode.m_SubsurfaceScattering;
            eyeData.materialType         = (EyeData.MaterialType)eyeMasterNode.m_MaterialType;
            target.customEditorGUI       = eyeMasterNode.m_OverrideEnabled ? eyeMasterNode.m_ShaderGUIOverride : "";

            // Convert SlotMask to BlockMap entries
            var blockMapLookup = new Dictionary <EyeMasterNode1.SlotMask, BlockFieldDescriptor>()
            {
                { EyeMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position },
                { EyeMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal },
                { EyeMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent },
                { EyeMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor },
                { EyeMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion },
                { EyeMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS },
                { EyeMasterNode1.SlotMask.IrisNormal, HDBlockFields.SurfaceDescription.IrisNormalTS },
                { EyeMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal },
                { EyeMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness },
                { EyeMasterNode1.SlotMask.IOR, HDBlockFields.SurfaceDescription.IOR },
                { EyeMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion },
                { EyeMasterNode1.SlotMask.Mask, HDBlockFields.SurfaceDescription.Mask },
                { EyeMasterNode1.SlotMask.DiffusionProfile, HDBlockFields.SurfaceDescription.DiffusionProfileHash },
                { EyeMasterNode1.SlotMask.SubsurfaceMask, HDBlockFields.SurfaceDescription.SubsurfaceMask },
                { EyeMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission },
                { EyeMasterNode1.SlotMask.Alpha, BlockFields.SurfaceDescription.Alpha },
                { EyeMasterNode1.SlotMask.AlphaClipThreshold, BlockFields.SurfaceDescription.AlphaClipThreshold },
            };

            // Legacy master node slots have additional slot conditions, test them here
            bool AdditionalSlotMaskTests(EyeMasterNode1.SlotMask slotMask)
            {
                switch (slotMask)
                {
                case EyeMasterNode1.SlotMask.SpecularOcclusion:
                    return(lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom);

                case EyeMasterNode1.SlotMask.DiffusionProfile:
                    return(eyeData.subsurfaceScattering);

                case EyeMasterNode1.SlotMask.SubsurfaceMask:
                    return(eyeData.subsurfaceScattering);

                case EyeMasterNode1.SlotMask.AlphaClipThreshold:
                    return(systemData.alphaTest);

                default:
                    return(true);
                }
            }

            // Set blockmap
            blockMap = new Dictionary <BlockFieldDescriptor, int>();
            foreach (EyeMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(EyeMasterNode1.SlotMask)))
            {
                if (eyeMasterNode.MaterialTypeUsesSlotMask(slotMask))
                {
                    if (!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor))
                    {
                        continue;
                    }

                    if (!AdditionalSlotMaskTests(slotMask))
                    {
                        continue;
                    }

                    var slotId = Mathf.Log((int)slotMask, 2);
                    blockMap.Add(blockFieldDescriptor, (int)slotId);
                }
            }

            // Override Baked GI
            if (lightingData.overrideBakedGI)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, EyeMasterNode1.LightingSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, EyeMasterNode1.BackLightingSlotId);
            }

            // Depth Offset
            if (builtinData.depthOffset)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, EyeMasterNode1.DepthOffsetSlotId);
            }

            return(true);
        }
        public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary <BlockFieldDescriptor, int> blockMap)
        {
            blockMap = null;
            if (!(masterNode is HairMasterNode1 hairMasterNode))
            {
                return(false);
            }

            m_MigrateFromOldSG = true;

            // Set data
            systemData.surfaceType = (SurfaceType)hairMasterNode.m_SurfaceType;
            systemData.blendMode   = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)hairMasterNode.m_AlphaMode);
            // Previous master node wasn't having any renderingPass. Assign it correctly now.
            systemData.renderQueueType     = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent;
            systemData.alphaTest           = hairMasterNode.m_AlphaTest;
            systemData.sortPriority        = hairMasterNode.m_SortPriority;
            systemData.doubleSidedMode     = hairMasterNode.m_DoubleSidedMode;
            systemData.transparentZWrite   = hairMasterNode.m_ZWrite;
            systemData.transparentCullMode = hairMasterNode.m_transparentCullMode;
            systemData.zTest                   = hairMasterNode.m_ZTest;
            systemData.dotsInstancing          = hairMasterNode.m_DOTSInstancing;
            systemData.materialNeedsUpdateHash = hairMasterNode.m_MaterialNeedsUpdateHash;

            builtinData.supportLodCrossFade        = hairMasterNode.m_SupportLodCrossFade;
            builtinData.transparentDepthPrepass    = hairMasterNode.m_AlphaTestDepthPrepass;
            builtinData.transparentDepthPostpass   = hairMasterNode.m_AlphaTestDepthPostpass;
            builtinData.transparencyFog            = hairMasterNode.m_TransparencyFog;
            builtinData.transparentWritesMotionVec = hairMasterNode.m_TransparentWritesMotionVec;
            builtinData.addPrecomputedVelocity     = hairMasterNode.m_AddPrecomputedVelocity;
            builtinData.depthOffset = hairMasterNode.m_depthOffset;

            builtinData.alphaTestShadow        = hairMasterNode.m_AlphaTestShadow;
            builtinData.backThenFrontRendering = hairMasterNode.m_BackThenFrontRendering;
            lightingData.blendPreserveSpecular = hairMasterNode.m_BlendPreserveSpecular;
            lightingData.receiveDecals         = hairMasterNode.m_ReceiveDecals;
            lightingData.receiveSSR            = hairMasterNode.m_ReceivesSSR;
            lightingData.receiveSSRTransparent = hairMasterNode.m_ReceivesSSRTransparent;
            lightingData.specularAA            = hairMasterNode.m_SpecularAA;
            lightingData.specularOcclusionMode = hairMasterNode.m_SpecularOcclusionMode;
            lightingData.overrideBakedGI       = hairMasterNode.m_overrideBakedGI;

            hairData.materialType  = (HairData.MaterialType)hairMasterNode.m_MaterialType;
            hairData.geometryType  = hairMasterNode.m_UseLightFacingNormal ? HairData.GeometryType.Strands : HairData.GeometryType.Cards;
            target.customEditorGUI = hairMasterNode.m_OverrideEnabled ? hairMasterNode.m_ShaderGUIOverride : "";

            // Convert SlotMask to BlockMap entries
            var blockMapLookup = new Dictionary <HairMasterNode1.SlotMask, BlockFieldDescriptor>()
            {
                { HairMasterNode1.SlotMask.Position, BlockFields.VertexDescription.Position },
                { HairMasterNode1.SlotMask.VertexNormal, BlockFields.VertexDescription.Normal },
                { HairMasterNode1.SlotMask.VertexTangent, BlockFields.VertexDescription.Tangent },
                { HairMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor },
                { HairMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion },
                { HairMasterNode1.SlotMask.Normal, BlockFields.SurfaceDescription.NormalTS },
                { HairMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal },
                { HairMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness },
                { HairMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion },
                { HairMasterNode1.SlotMask.Transmittance, HDBlockFields.SurfaceDescription.Transmittance },
                { HairMasterNode1.SlotMask.RimTransmissionIntensity, HDBlockFields.SurfaceDescription.RimTransmissionIntensity },
                { HairMasterNode1.SlotMask.HairStrandDirection, HDBlockFields.SurfaceDescription.HairStrandDirection },
                { HairMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission },
                { HairMasterNode1.SlotMask.Alpha, BlockFields.SurfaceDescription.Alpha },
                { HairMasterNode1.SlotMask.AlphaClipThreshold, BlockFields.SurfaceDescription.AlphaClipThreshold },
                { HairMasterNode1.SlotMask.AlphaClipThresholdDepthPrepass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass },
                { HairMasterNode1.SlotMask.AlphaClipThresholdDepthPostpass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass },
                { HairMasterNode1.SlotMask.AlphaClipThresholdShadow, HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow },
                { HairMasterNode1.SlotMask.SpecularTint, HDBlockFields.SurfaceDescription.SpecularTint },
                { HairMasterNode1.SlotMask.SpecularShift, HDBlockFields.SurfaceDescription.SpecularShift },
                { HairMasterNode1.SlotMask.SecondarySpecularTint, HDBlockFields.SurfaceDescription.SecondarySpecularTint },
                { HairMasterNode1.SlotMask.SecondarySmoothness, HDBlockFields.SurfaceDescription.SecondarySmoothness },
                { HairMasterNode1.SlotMask.SecondarySpecularShift, HDBlockFields.SurfaceDescription.SecondarySpecularShift },
            };

            // Legacy master node slots have additional slot conditions, test them here
            bool AdditionalSlotMaskTests(HairMasterNode1.SlotMask slotMask)
            {
                switch (slotMask)
                {
                case HairMasterNode1.SlotMask.SpecularOcclusion:
                    return(lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom);

                case HairMasterNode1.SlotMask.AlphaClipThreshold:
                    return(systemData.alphaTest);

                case HairMasterNode1.SlotMask.AlphaClipThresholdDepthPrepass:
                    return(systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPrepass);

                case HairMasterNode1.SlotMask.AlphaClipThresholdDepthPostpass:
                    return(systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPostpass);

                case HairMasterNode1.SlotMask.AlphaClipThresholdShadow:
                    return(systemData.alphaTest && builtinData.alphaTestShadow);

                default:
                    return(true);
                }
            }

            // Set blockmap
            blockMap = new Dictionary <BlockFieldDescriptor, int>();
            foreach (HairMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(HairMasterNode1.SlotMask)))
            {
                if (hairMasterNode.MaterialTypeUsesSlotMask(slotMask))
                {
                    if (!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor))
                    {
                        continue;
                    }

                    if (!AdditionalSlotMaskTests(slotMask))
                    {
                        continue;
                    }

                    var slotId = Mathf.Log((int)slotMask, 2);
                    blockMap.Add(blockFieldDescriptor, (int)slotId);
                }
            }

            // Specular AA
            if (lightingData.specularAA)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, HairMasterNode1.SpecularAAScreenSpaceVarianceSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAThreshold, HairMasterNode1.SpecularAAThresholdSlotId);
            }

            // Override Baked GI
            if (lightingData.overrideBakedGI)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, HairMasterNode1.LightingSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, HairMasterNode1.BackLightingSlotId);
            }

            // Depth Offset
            if (builtinData.depthOffset)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, HairMasterNode1.DepthOffsetSlotId);
            }

            return(true);
        }
        void UpgradePBRMasterNode(PBRMasterNode1 pbrMasterNode, out Dictionary <BlockFieldDescriptor, int> blockMap)
        {
            m_MigrateFromOldCrossPipelineSG = true;

            // Set data
            systemData.surfaceType     = (SurfaceType)pbrMasterNode.m_SurfaceType;
            systemData.blendMode       = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)pbrMasterNode.m_AlphaMode);
            systemData.doubleSidedMode = pbrMasterNode.m_TwoSided ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled;
            // Previous master node wasn't having any renderingPass. Assign it correctly now.
            systemData.renderingPass           = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent;
            systemData.dotsInstancing          = false;
            systemData.alphaTest               = HDSubShaderUtilities.UpgradeLegacyAlphaClip(pbrMasterNode);
            builtinData.addPrecomputedVelocity = false;
            lightingData.blendPreserveSpecular = false;
            lightingData.normalDropOffSpace    = pbrMasterNode.m_NormalDropOffSpace;
            lightingData.receiveDecals         = false;
            lightingData.receiveSSR            = true;
            lightingData.receiveSSRTransparent = false;
            litData.materialType               = pbrMasterNode.m_Model == PBRMasterNode1.Model.Specular ? HDLitData.MaterialType.SpecularColor : HDLitData.MaterialType.Standard;
            litData.energyConservingSpecular   = false;
            litData.clearCoat      = false;
            target.customEditorGUI = pbrMasterNode.m_OverrideEnabled ? pbrMasterNode.m_ShaderGUIOverride : "";
            // Handle mapping of Normal block specifically
            BlockFieldDescriptor normalBlock;

            switch (lightingData.normalDropOffSpace)
            {
            case NormalDropOffSpace.Object:
                normalBlock = BlockFields.SurfaceDescription.NormalOS;
                break;

            case NormalDropOffSpace.World:
                normalBlock = BlockFields.SurfaceDescription.NormalWS;
                break;

            default:
                normalBlock = BlockFields.SurfaceDescription.NormalTS;
                break;
            }

            // PBRMasterNode adds/removes Metallic/Specular based on settings
            BlockFieldDescriptor specularMetallicBlock;
            int specularMetallicId;

            if (litData.materialType == HDLitData.MaterialType.SpecularColor)
            {
                specularMetallicBlock = BlockFields.SurfaceDescription.Specular;
                specularMetallicId    = 3;
            }
            else
            {
                specularMetallicBlock = BlockFields.SurfaceDescription.Metallic;
                specularMetallicId    = 2;
            }

            // Set blockmap
            blockMap = new Dictionary <BlockFieldDescriptor, int>()
            {
                { BlockFields.VertexDescription.Position, 9 },
                { BlockFields.VertexDescription.Normal, 10 },
                { BlockFields.VertexDescription.Tangent, 11 },
                { BlockFields.SurfaceDescription.BaseColor, 0 },
                { normalBlock, 1 },
                { specularMetallicBlock, specularMetallicId },
                { BlockFields.SurfaceDescription.Emission, 4 },
                { BlockFields.SurfaceDescription.Smoothness, 5 },
                { BlockFields.SurfaceDescription.Occlusion, 6 },
                { BlockFields.SurfaceDescription.Alpha, 7 },
                { BlockFields.SurfaceDescription.AlphaClipThreshold, 8 },
            };
        }
        void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary <BlockFieldDescriptor, int> blockMap)
        {
            // Set data
            systemData.surfaceType   = (SurfaceType)hdLitMasterNode.m_SurfaceType;
            systemData.blendMode     = HDSubShaderUtilities.UpgradeLegacyAlphaModeToBlendMode((int)hdLitMasterNode.m_AlphaMode);
            systemData.renderingPass = hdLitMasterNode.m_RenderingPass;
            // Patch rendering pass in case the master node had an old configuration
            if (systemData.renderingPass == HDRenderQueue.RenderQueueType.Background)
            {
                systemData.renderingPass = HDRenderQueue.RenderQueueType.Opaque;
            }
            systemData.alphaTest           = hdLitMasterNode.m_AlphaTest;
            systemData.sortPriority        = hdLitMasterNode.m_SortPriority;
            systemData.doubleSidedMode     = hdLitMasterNode.m_DoubleSidedMode;
            systemData.transparentZWrite   = hdLitMasterNode.m_ZWrite;
            systemData.transparentCullMode = hdLitMasterNode.m_transparentCullMode;
            systemData.zTest                   = hdLitMasterNode.m_ZTest;
            systemData.dotsInstancing          = hdLitMasterNode.m_DOTSInstancing;
            systemData.materialNeedsUpdateHash = hdLitMasterNode.m_MaterialNeedsUpdateHash;

            builtinData.transparentDepthPrepass  = hdLitMasterNode.m_AlphaTestDepthPrepass;
            builtinData.transparentDepthPostpass = hdLitMasterNode.m_AlphaTestDepthPostpass;
            builtinData.supportLodCrossFade      = hdLitMasterNode.m_SupportLodCrossFade;
            builtinData.transparencyFog          = hdLitMasterNode.m_TransparencyFog;
            builtinData.distortion                 = hdLitMasterNode.m_Distortion;
            builtinData.distortionMode             = hdLitMasterNode.m_DistortionMode;
            builtinData.distortionDepthTest        = hdLitMasterNode.m_DistortionDepthTest;
            builtinData.transparentWritesMotionVec = hdLitMasterNode.m_TransparentWritesMotionVec;
            builtinData.addPrecomputedVelocity     = hdLitMasterNode.m_AddPrecomputedVelocity;
            builtinData.depthOffset                = hdLitMasterNode.m_depthOffset;
            builtinData.alphaToMask                = hdLitMasterNode.m_AlphaToMask;

            builtinData.alphaTestShadow        = hdLitMasterNode.m_AlphaTestShadow;
            builtinData.backThenFrontRendering = hdLitMasterNode.m_BackThenFrontRendering;
            lightingData.normalDropOffSpace    = hdLitMasterNode.m_NormalDropOffSpace;
            lightingData.blendPreserveSpecular = hdLitMasterNode.m_BlendPreserveSpecular;
            lightingData.receiveDecals         = hdLitMasterNode.m_ReceiveDecals;
            lightingData.receiveSSR            = hdLitMasterNode.m_ReceivesSSR;
            lightingData.receiveSSRTransparent = hdLitMasterNode.m_ReceivesSSRTransparent;
            lightingData.specularAA            = hdLitMasterNode.m_SpecularAA;
            lightingData.specularOcclusionMode = hdLitMasterNode.m_SpecularOcclusionMode;
            lightingData.overrideBakedGI       = hdLitMasterNode.m_overrideBakedGI;
            HDLitData.MaterialType materialType = (HDLitData.MaterialType)hdLitMasterNode.m_MaterialType;

            litData.clearCoat = UpgradeCoatMask(hdLitMasterNode);
            litData.energyConservingSpecular = hdLitMasterNode.m_EnergyConservingSpecular;
            litData.rayTracing      = hdLitMasterNode.m_RayTracing;
            litData.refractionModel = hdLitMasterNode.m_RefractionModel;
            litData.materialType    = materialType;
            litData.sssTransmission = hdLitMasterNode.m_SSSTransmission;

            target.customEditorGUI = hdLitMasterNode.m_OverrideEnabled ? hdLitMasterNode.m_ShaderGUIOverride : "";

            // Handle mapping of Normal block specifically
            BlockFieldDescriptor normalBlock;

            switch (lightingData.normalDropOffSpace)
            {
            case NormalDropOffSpace.Object:
                normalBlock = BlockFields.SurfaceDescription.NormalOS;
                break;

            case NormalDropOffSpace.World:
                normalBlock = BlockFields.SurfaceDescription.NormalWS;
                break;

            default:
                normalBlock = BlockFields.SurfaceDescription.NormalTS;
                break;
            }

            // Convert SlotMask to BlockMap entries
            var blockMapLookup = new Dictionary <HDLitMasterNode1.SlotMask, BlockFieldDescriptor>()
            {
                { HDLitMasterNode1.SlotMask.Albedo, BlockFields.SurfaceDescription.BaseColor },
                { HDLitMasterNode1.SlotMask.Normal, normalBlock },
                { HDLitMasterNode1.SlotMask.BentNormal, HDBlockFields.SurfaceDescription.BentNormal },
                { HDLitMasterNode1.SlotMask.Tangent, HDBlockFields.SurfaceDescription.Tangent },
                { HDLitMasterNode1.SlotMask.Anisotropy, HDBlockFields.SurfaceDescription.Anisotropy },
                { HDLitMasterNode1.SlotMask.SubsurfaceMask, HDBlockFields.SurfaceDescription.SubsurfaceMask },
                { HDLitMasterNode1.SlotMask.Thickness, HDBlockFields.SurfaceDescription.Thickness },
                { HDLitMasterNode1.SlotMask.DiffusionProfile, HDBlockFields.SurfaceDescription.DiffusionProfileHash },
                { HDLitMasterNode1.SlotMask.IridescenceMask, HDBlockFields.SurfaceDescription.IridescenceMask },
                { HDLitMasterNode1.SlotMask.IridescenceLayerThickness, HDBlockFields.SurfaceDescription.IridescenceThickness },
                { HDLitMasterNode1.SlotMask.Specular, BlockFields.SurfaceDescription.Specular },
                { HDLitMasterNode1.SlotMask.CoatMask, HDBlockFields.SurfaceDescription.CoatMask },
                { HDLitMasterNode1.SlotMask.Metallic, BlockFields.SurfaceDescription.Metallic },
                { HDLitMasterNode1.SlotMask.Smoothness, BlockFields.SurfaceDescription.Smoothness },
                { HDLitMasterNode1.SlotMask.Occlusion, BlockFields.SurfaceDescription.Occlusion },
                { HDLitMasterNode1.SlotMask.SpecularOcclusion, HDBlockFields.SurfaceDescription.SpecularOcclusion },
                { HDLitMasterNode1.SlotMask.Emission, BlockFields.SurfaceDescription.Emission },
                { HDLitMasterNode1.SlotMask.Alpha, BlockFields.SurfaceDescription.Alpha },
                { HDLitMasterNode1.SlotMask.AlphaThreshold, BlockFields.SurfaceDescription.AlphaClipThreshold },
                { HDLitMasterNode1.SlotMask.AlphaThresholdDepthPrepass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass },
                { HDLitMasterNode1.SlotMask.AlphaThresholdDepthPostpass, HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass },
                { HDLitMasterNode1.SlotMask.AlphaThresholdShadow, HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow },
            };

            // Legacy master node slots have additional slot conditions, test them here
            bool AdditionalSlotMaskTests(HDLitMasterNode1.SlotMask slotMask)
            {
                switch (slotMask)
                {
                case HDLitMasterNode1.SlotMask.Thickness:
                    return(litData.sssTransmission || litData.materialType == HDLitData.MaterialType.Translucent);

                case HDLitMasterNode1.SlotMask.SpecularOcclusion:
                    return(lightingData.specularOcclusionMode == SpecularOcclusionMode.Custom);

                case HDLitMasterNode1.SlotMask.AlphaThreshold:
                    return(systemData.alphaTest);

                case HDLitMasterNode1.SlotMask.AlphaThresholdDepthPrepass:
                    return(systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPrepass);

                case HDLitMasterNode1.SlotMask.AlphaThresholdDepthPostpass:
                    return(systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPostpass);

                case HDLitMasterNode1.SlotMask.AlphaThresholdShadow:
                    return(systemData.alphaTest && builtinData.alphaTestShadow);

                default:
                    return(true);
                }
            }

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

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

                if (coatMaskSlot == null)
                {
                    return(false);
                }

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

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

            // First handle vertex blocks. We ran out of SlotMask bits for VertexNormal and VertexTangent
            // so do all Vertex blocks here to maintain correct block order (Position is not in blockMapLookup)
            blockMap.Add(BlockFields.VertexDescription.Position, HDLitMasterNode1.PositionSlotId);
            blockMap.Add(BlockFields.VertexDescription.Normal, HDLitMasterNode1.VertexNormalSlotID);
            blockMap.Add(BlockFields.VertexDescription.Tangent, HDLitMasterNode1.VertexTangentSlotID);

            // Now handle the SlotMask cases
            foreach (HDLitMasterNode1.SlotMask slotMask in Enum.GetValues(typeof(HDLitMasterNode1.SlotMask)))
            {
                if (hdLitMasterNode.MaterialTypeUsesSlotMask(slotMask))
                {
                    if (!blockMapLookup.TryGetValue(slotMask, out var blockFieldDescriptor))
                    {
                        continue;
                    }

                    if (!AdditionalSlotMaskTests(slotMask))
                    {
                        continue;
                    }

                    var slotId = Mathf.Log((int)slotMask, 2);
                    blockMap.Add(blockFieldDescriptor, (int)slotId);
                }
            }

            // Specular AA
            if (lightingData.specularAA)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance, HDLitMasterNode1.SpecularAAScreenSpaceVarianceSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.SpecularAAThreshold, HDLitMasterNode1.SpecularAAThresholdSlotId);
            }

            // Refraction
            bool hasRefraction = (systemData.surfaceType == SurfaceType.Transparent && systemData.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction && litData.refractionModel != ScreenSpaceRefraction.RefractionModel.None);

            if (hasRefraction)
            {
                if (!blockMap.TryGetValue(HDBlockFields.SurfaceDescription.Thickness, out _))
                {
                    blockMap.Add(HDBlockFields.SurfaceDescription.Thickness, HDLitMasterNode1.ThicknessSlotId);
                }

                blockMap.Add(HDBlockFields.SurfaceDescription.RefractionIndex, HDLitMasterNode1.RefractionIndexSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.RefractionColor, HDLitMasterNode1.RefractionColorSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.RefractionDistance, HDLitMasterNode1.RefractionDistanceSlotId);
            }

            // Distortion
            bool hasDistortion = (systemData.surfaceType == SurfaceType.Transparent && builtinData.distortion);

            if (hasDistortion)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.Distortion, HDLitMasterNode1.DistortionSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.DistortionBlur, HDLitMasterNode1.DistortionBlurSlotId);
            }

            // Override Baked GI
            if (lightingData.overrideBakedGI)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.BakedGI, HDLitMasterNode1.LightingSlotId);
                blockMap.Add(HDBlockFields.SurfaceDescription.BakedBackGI, HDLitMasterNode1.BackLightingSlotId);
            }

            // Depth Offset (Removed from SlotMask because of missing bits)
            if (builtinData.depthOffset)
            {
                blockMap.Add(HDBlockFields.SurfaceDescription.DepthOffset, HDLitMasterNode1.DepthOffsetSlotId);
            }
        }