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 }, }; }
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 HDUnlitSettingsView(HDUnlitMasterNode node) { m_Node = node; PropertySheet ps = new PropertySheet(); int indentLevel = 0; ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => { row.Add(new EnumField(SurfaceType.Opaque), (field) => { field.value = m_Node.surfaceType; field.RegisterValueChangedCallback(ChangeSurfaceType); }); }); ++indentLevel; switch (m_Node.surfaceType) { case SurfaceType.Opaque: ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => { var valueList = HDSubShaderUtilities.GetRenderingPassList(true, true); row.Add(new PopupField <HDRenderQueue.RenderQueueType>(valueList, HDRenderQueue.RenderQueueType.Opaque, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => { field.value = HDRenderQueue.GetOpaqueEquivalent(m_Node.renderingPass); field.RegisterValueChangedCallback(ChangeRenderingPass); }); }); break; case SurfaceType.Transparent: ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => { Enum defaultValue; switch (m_Node.renderingPass) // Migration { default: //when deserializing without issue, we still need to init the default to something even if not used. case HDRenderQueue.RenderQueueType.Transparent: defaultValue = HDRenderQueue.TransparentRenderQueue.Default; break; case HDRenderQueue.RenderQueueType.PreRefraction: defaultValue = HDRenderQueue.TransparentRenderQueue.BeforeRefraction; break; } var valueList = HDSubShaderUtilities.GetRenderingPassList(false, true); row.Add(new PopupField <HDRenderQueue.RenderQueueType>(valueList, HDRenderQueue.RenderQueueType.Transparent, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => { field.value = HDRenderQueue.GetTransparentEquivalent(m_Node.renderingPass); field.RegisterValueChangedCallback(ChangeRenderingPass); }); }); break; default: throw new ArgumentException("Unknown SurfaceType"); } --indentLevel; if (m_Node.surfaceType == SurfaceType.Transparent) { ++indentLevel; ps.Add(new PropertyRow(CreateLabel("Blending Mode", indentLevel)), (row) => { row.Add(new EnumField(HDUnlitMasterNode.AlphaModeLit.Additive), (field) => { field.value = GetAlphaModeLit(m_Node.alphaMode); field.RegisterValueChangedCallback(ChangeBlendMode); }); }); m_SortPiorityField = new IntegerField(); ps.Add(new PropertyRow(CreateLabel("Sorting Priority", indentLevel)), (row) => { row.Add(m_SortPiorityField, (field) => { field.value = m_Node.sortPriority; field.RegisterValueChangedCallback(ChangeSortPriority); }); }); ps.Add(new PropertyRow(CreateLabel("Receive Fog", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.transparencyFog.isOn; toggle.OnToggleChanged(ChangeTransparencyFog); }); }); ps.Add(new PropertyRow(CreateLabel("Distortion", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.distortion.isOn; toggle.OnToggleChanged(ChangeDistortion); }); }); if (m_Node.distortion.isOn) { ++indentLevel; ps.Add(new PropertyRow(CreateLabel("Mode", indentLevel)), (row) => { row.Add(new EnumField(DistortionMode.Add), (field) => { field.value = m_Node.distortionMode; field.RegisterValueChangedCallback(ChangeDistortionMode); }); }); ps.Add(new PropertyRow(CreateLabel("Distortion Only", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.distortionOnly.isOn; toggle.OnToggleChanged(ChangeDistortionOnly); }); }); ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.distortionDepthTest.isOn; toggle.OnToggleChanged(ChangeDistortionDepthTest); }); }); --indentLevel; } --indentLevel; } ps.Add(new PropertyRow(new Label("Double-Sided")), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.doubleSided.isOn; toggle.OnToggleChanged(ChangeDoubleSided); }); }); ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.alphaTest.isOn; toggle.OnToggleChanged(ChangeAlphaTest); }); }); Add(ps); }
public HDLitSettingsView(HDLitMasterNode node) : base(node) { m_Node = node; PropertySheet ps = new PropertySheet(); int indentLevel = 0; ps.Add(new PropertyRow(CreateLabel("Surface Type", indentLevel)), (row) => { row.Add(new EnumField(SurfaceType.Opaque), (field) => { field.value = m_Node.surfaceType; field.RegisterValueChangedCallback(ChangeSurfaceType); }); }); ++indentLevel; switch (m_Node.surfaceType) { case SurfaceType.Opaque: ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => { var valueList = HDSubShaderUtilities.GetRenderingPassList(true, false); row.Add(new PopupField <HDRenderQueue.RenderQueueType>(valueList, HDRenderQueue.RenderQueueType.Opaque, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => { field.value = HDRenderQueue.GetOpaqueEquivalent(m_Node.renderingPass); field.RegisterValueChangedCallback(ChangeRenderingPass); }); }); break; case SurfaceType.Transparent: ps.Add(new PropertyRow(CreateLabel("Rendering Pass", indentLevel)), (row) => { Enum defaultValue; switch (m_Node.renderingPass) // Migration { default: //when deserializing without issue, we still need to init the default to something even if not used. case HDRenderQueue.RenderQueueType.Transparent: defaultValue = HDRenderQueue.TransparentRenderQueue.Default; break; case HDRenderQueue.RenderQueueType.PreRefraction: defaultValue = HDRenderQueue.TransparentRenderQueue.BeforeRefraction; break; } var valueList = HDSubShaderUtilities.GetRenderingPassList(false, false); row.Add(new PopupField <HDRenderQueue.RenderQueueType>(valueList, HDRenderQueue.RenderQueueType.Transparent, HDSubShaderUtilities.RenderQueueName, HDSubShaderUtilities.RenderQueueName), (field) => { field.value = HDRenderQueue.GetTransparentEquivalent(m_Node.renderingPass); field.RegisterValueChangedCallback(ChangeRenderingPass); }); }); break; default: throw new ArgumentException("Unknown SurfaceType"); } --indentLevel; if (m_Node.surfaceType == SurfaceType.Transparent) { ++indentLevel; if (!m_Node.HasRefraction()) { ps.Add(new PropertyRow(CreateLabel("Blending Mode", indentLevel)), (row) => { row.Add(new EnumField(HDLitMasterNode.AlphaModeLit.Additive), (field) => { field.value = GetAlphaModeLit(m_Node.alphaMode); field.RegisterValueChangedCallback(ChangeBlendMode); }); }); ++indentLevel; ps.Add(new PropertyRow(CreateLabel("Preserve Specular Lighting", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.blendPreserveSpecular.isOn; toggle.OnToggleChanged(ChangeBlendPreserveSpecular); }); }); --indentLevel; } m_SortPriorityField = new IntegerField(); ps.Add(new PropertyRow(CreateLabel("Sorting Priority", indentLevel)), (row) => { row.Add(m_SortPriorityField, (field) => { field.value = m_Node.sortPriority; field.RegisterValueChangedCallback(ChangeSortPriority); }); }); ps.Add(new PropertyRow(CreateLabel("Receive Fog", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.transparencyFog.isOn; toggle.OnToggleChanged(ChangeTransparencyFog); }); }); ps.Add(new PropertyRow(CreateLabel("Back Then Front Rendering", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.backThenFrontRendering.isOn; toggle.OnToggleChanged(ChangeBackThenFrontRendering); }); }); ps.Add(new PropertyRow(CreateLabel("Transparent Depth Prepass", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.alphaTestDepthPrepass.isOn; toggle.OnToggleChanged(ChangeAlphaTestPrepass); }); }); ps.Add(new PropertyRow(CreateLabel("Transparent Depth Postpass", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.alphaTestDepthPostpass.isOn; toggle.OnToggleChanged(ChangeAlphaTestPostpass); }); }); ps.Add(new PropertyRow(CreateLabel("Transparent Writes Motion Vector", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.transparentWritesMotionVec.isOn; toggle.OnToggleChanged(ChangeTransparentWritesMotionVec); }); }); if (m_Node.renderingPass != HDRenderQueue.RenderQueueType.PreRefraction) { ps.Add(new PropertyRow(CreateLabel("Refraction Model", indentLevel)), (row) => { row.Add(new EnumField(ScreenSpaceRefraction.RefractionModel.None), (field) => { field.value = m_Node.refractionModel; field.RegisterValueChangedCallback(ChangeRefractionModel); }); }); } ps.Add(new PropertyRow(CreateLabel("Distortion", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.distortion.isOn; toggle.OnToggleChanged(ChangeDistortion); }); }); if (m_Node.distortion.isOn) { ++indentLevel; ps.Add(new PropertyRow(CreateLabel("Distortion Blend Mode", indentLevel)), (row) => { row.Add(new EnumField(DistortionMode.Add), (field) => { field.value = m_Node.distortionMode; field.RegisterValueChangedCallback(ChangeDistortionMode); }); }); ps.Add(new PropertyRow(CreateLabel("Distortion Depth Test", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.distortionDepthTest.isOn; toggle.OnToggleChanged(ChangeDistortionDepthTest); }); }); --indentLevel; } ps.Add(new PropertyRow(CreateLabel("Depth Write", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.zWrite.isOn; toggle.OnToggleChanged(ChangeZWrite); }); }); if (m_Node.doubleSidedMode == DoubleSidedMode.Disabled) { ps.Add(new PropertyRow(CreateLabel("Cull Mode", indentLevel)), (row) => { row.Add(new EnumField(m_Node.transparentCullMode), (e) => { e.value = m_Node.transparentCullMode; e.RegisterValueChangedCallback(ChangeTransparentCullMode); }); }); } ps.Add(new PropertyRow(CreateLabel("Depth Test", indentLevel)), (row) => { row.Add(new EnumField(m_Node.zTest), (e) => { e.value = m_Node.zTest; e.RegisterValueChangedCallback(ChangeZTest); }); }); --indentLevel; } ps.Add(new PropertyRow(CreateLabel("Double-Sided", indentLevel)), (row) => { row.Add(new EnumField(DoubleSidedMode.Disabled), (field) => { field.value = m_Node.doubleSidedMode; field.RegisterValueChangedCallback(ChangeDoubleSidedMode); }); }); ps.Add(new PropertyRow(CreateLabel("Fragment Normal Space", indentLevel)), (row) => { row.Add(new EnumField(NormalDropOffSpace.Tangent), (field) => { field.value = m_Node.normalDropOffSpace; field.RegisterValueChangedCallback(ChangeSpaceOfNormalDropOffMode); }); }); ps.Add(new PropertyRow(CreateLabel("Alpha Clipping", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.alphaTest.isOn; toggle.OnToggleChanged(ChangeAlphaTest); }); }); if (m_Node.alphaTest.isOn) { ++indentLevel; ps.Add(new PropertyRow(CreateLabel("Use Shadow Threshold", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.alphaTestShadow.isOn; toggle.OnToggleChanged(ChangeAlphaTestShadow); }); }); --indentLevel; } ps.Add(new PropertyRow(CreateLabel("Material Type", indentLevel)), (row) => { row.Add(new EnumField(HDLitMasterNode.MaterialType.Standard), (field) => { field.value = m_Node.materialType; field.RegisterValueChangedCallback(ChangeMaterialType); }); }); ++indentLevel; if (m_Node.materialType == HDLitMasterNode.MaterialType.SubsurfaceScattering) { ps.Add(new PropertyRow(CreateLabel("Transmission", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.sssTransmission.isOn; toggle.OnToggleChanged(ChangeSSSTransmission); }); }); } if (m_Node.materialType == HDLitMasterNode.MaterialType.SpecularColor) { ps.Add(new PropertyRow(CreateLabel("Energy Conserving Specular", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.energyConservingSpecular.isOn; toggle.OnToggleChanged(ChangeEnergyConservingSpecular); }); }); } --indentLevel; ps.Add(new PropertyRow(CreateLabel("Receive Decals", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.receiveDecals.isOn; toggle.OnToggleChanged(ChangeDecal); }); }); ps.Add(new PropertyRow(CreateLabel("Receive SSR", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.receiveSSR.isOn; toggle.OnToggleChanged(ChangeSSR); }); }); ps.Add(new PropertyRow(CreateLabel("Add Precomputed Velocity", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.addPrecomputedVelocity.isOn; toggle.OnToggleChanged(ChangeAddPrecomputedVelocity); }); }); ps.Add(new PropertyRow(CreateLabel("Geometric Specular AA", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.specularAA.isOn; toggle.OnToggleChanged(ChangeSpecularAA); }); }); ps.Add(new PropertyRow(CreateLabel("Specular Occlusion Mode", indentLevel)), (row) => { row.Add(new EnumField(SpecularOcclusionMode.Off), (field) => { field.value = m_Node.specularOcclusionMode; field.RegisterValueChangedCallback(ChangeSpecularOcclusionMode); }); }); ps.Add(new PropertyRow(CreateLabel("Override Baked GI", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.overrideBakedGI.isOn; toggle.OnToggleChanged(ChangeoverrideBakedGI); }); }); ps.Add(new PropertyRow(CreateLabel("Depth Offset", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.depthOffset.isOn; toggle.OnToggleChanged(ChangeDepthOffset); }); }); ps.Add(new PropertyRow(CreateLabel("DOTS instancing", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.dotsInstancing.isOn; toggle.OnToggleChanged(ChangeDotsInstancing); }); }); ps.Add(new PropertyRow(CreateLabel("Support LOD CrossFade", indentLevel)), (row) => { row.Add(new Toggle(), (toggle) => { toggle.value = m_Node.supportLodCrossFade.isOn; toggle.OnToggleChanged(ChangeSupportLODCrossFade); }); }); Add(ps); Add(GetShaderGUIOverridePropertySheet()); }
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); } }