diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs index 581652235c7..6d4ded6341a 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs @@ -27,17 +27,17 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary lightingData.specularOcclusionMode, (newValue) => lightingData.specularOcclusionMode = newValue); AddProperty(Styles.overrideBakedGI, () => lightingData.overrideBakedGI, (newValue) => lightingData.overrideBakedGI = newValue); } - AddProperty(Styles.supportLodCrossFade, () => systemData.supportLodCrossFade, (newValue) => systemData.supportLodCrossFade = newValue); + AddProperty(Styles.supportLodCrossFade, () => builtinData.supportLodCrossFade, (newValue) => builtinData.supportLodCrossFade = newValue); AddProperty(addPrecomputedVelocityText, () => builtinData.addPrecomputedVelocity, (newValue) => builtinData.addPrecomputedVelocity = newValue); } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs index b16eea5f1ca..3664233f5f1 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs @@ -33,12 +33,7 @@ public SystemData systemData set => m_SystemData = value; } - protected virtual int ComputeMaterialNeedsUpdateHash() - { - // Alpha test is currently the only property in system data to trigger the material upgrade script. - int hash = systemData.alphaTest.GetHashCode(); - return hash; - } + protected virtual int ComputeMaterialNeedsUpdateHash() => 0; public override bool IsActive() => true; @@ -97,6 +92,15 @@ public override void Setup(ref TargetSetupContext context) if (migrationSteps.Migrate(this)) OnBeforeSerialize(); + // Migration hack to have the case where SG doesn't have version yet but is already upgraded to the stack system + if (!systemData.firstTimeMigrationExecuted) + { + // Force the initial migration step + MigrateTo(ShaderGraphVersion.FirstTimeMigration); + systemData.firstTimeMigrationExecuted = true; + OnBeforeSerialize(); + } + foreach (var subShader in EnumerateSubShaders()) { // patch render type and render queue from pass declaration: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs index 1864ea0f241..35e55f3d8d6 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs @@ -9,5 +9,6 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph public enum ShaderGraphVersion { Initial = 0, + FirstTimeMigration = Initial, } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs index 6070ce58960..b3a8aac07c8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs @@ -65,8 +65,8 @@ protected override void CreatePropertyGUI() AddProperty(transparentCullModeText, () => systemData.transparentCullMode, (newValue) => systemData.transparentCullMode = newValue); AddProperty(transparentSortPriorityText, () => systemData.sortPriority, (newValue) => systemData.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(newValue)); AddProperty(transparentBackfaceEnableText, () => builtinData.backThenFrontRendering, (newValue) => builtinData.backThenFrontRendering = newValue); - AddProperty(transparentDepthPrepassEnableText, () => systemData.transparentDepthPrepass, (newValue) => systemData.transparentDepthPrepass = newValue); - AddProperty(transparentDepthPostpassEnableText, () => systemData.transparentDepthPostpass, (newValue) => systemData.transparentDepthPostpass = newValue); + AddProperty(transparentDepthPrepassEnableText, () => builtinData.transparentDepthPrepass, (newValue) => builtinData.transparentDepthPrepass = newValue); + AddProperty(transparentDepthPostpassEnableText, () => builtinData.transparentDepthPostpass, (newValue) => builtinData.transparentDepthPostpass = newValue); AddProperty(transparentWritingMotionVecText, () => builtinData.transparentWritesMotionVec, (newValue) => builtinData.transparentWritesMotionVec = newValue); if (lightingData != null) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs index d20a3fd2290..5aa154d37d2 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs @@ -42,6 +42,13 @@ protected override string renderQueue protected virtual bool supportDistortion => false; protected override bool supportRaytracing => true; + protected override int ComputeMaterialNeedsUpdateHash() + { + // Alpha test is currently the only property in buitin data to trigger the material upgrade script. + int hash = systemData.alphaTest.GetHashCode(); + return hash; + } + public override void Setup(ref TargetSetupContext context) { context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath("f4df7e8f9b8c23648ae50cbca0221e47")); // SurfaceSubTarget.cs @@ -194,15 +201,15 @@ public override void GetFields(ref TargetFieldContext context) context.AddField(HDFields.DoAlphaTestShadow, systemData.alphaTest && builtinData.alphaTestShadow && isShadowPass && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow)); // Pre/post pass always use the specific alpha test provided for those pass - context.AddField(HDFields.DoAlphaTestPrepass, systemData.alphaTest && systemData.transparentDepthPrepass && isTransparentDepthPrepass && + context.AddField(HDFields.DoAlphaTestPrepass, systemData.alphaTest && builtinData.transparentDepthPrepass && isTransparentDepthPrepass && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass)); // Features & Misc - context.AddField(Fields.LodCrossFade, systemData.supportLodCrossFade); + context.AddField(Fields.LodCrossFade, builtinData.supportLodCrossFade); context.AddField(Fields.AlphaToMask, systemData.alphaTest); context.AddField(HDFields.TransparentBackFace, builtinData.backThenFrontRendering); - context.AddField(HDFields.TransparentDepthPrePass, systemData.transparentDepthPrepass); - context.AddField(HDFields.TransparentDepthPostPass, systemData.transparentDepthPostpass); + context.AddField(HDFields.TransparentDepthPrePass, builtinData.transparentDepthPrepass); + context.AddField(HDFields.TransparentDepthPostPass, builtinData.transparentDepthPostpass); context.AddField(HDFields.DepthOffset, builtinData.depthOffset && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.DepthOffset)); @@ -239,8 +246,8 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context) context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, systemData.alphaTest); // Alpha Test - context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, systemData.alphaTest && systemData.transparentDepthPrepass); - context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, systemData.alphaTest && systemData.transparentDepthPostpass); + context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, systemData.alphaTest && builtinData.transparentDepthPrepass); + context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, systemData.alphaTest && builtinData.transparentDepthPostpass); context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, systemData.alphaTest && builtinData.alphaTestShadow); // Misc @@ -306,7 +313,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera // Common properties for all "surface" master nodes HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, builtinData.alphaTestShadow); HDSubShaderUtilities.AddDoubleSidedProperty(collector, systemData.doubleSidedMode); - HDSubShaderUtilities.AddPrePostPassProperties(collector, systemData.transparentDepthPrepass, systemData.transparentDepthPostpass); + HDSubShaderUtilities.AddPrePostPassProperties(collector, builtinData.transparentDepthPrepass, builtinData.transparentDepthPostpass); // Add all shader properties required by the inspector HDSubShaderUtilities.AddBlendingStatesShaderProperties( @@ -343,5 +350,19 @@ public override void ProcessPreviewMaterial(Material material) LightingShaderGraphGUI.SetupMaterialKeywordsAndPass(material); } + + internal override void MigrateTo(ShaderGraphVersion version) + { + base.MigrateTo(version); + + if (version == ShaderGraphVersion.FirstTimeMigration) + { +#pragma warning disable 618 + builtinData.transparentDepthPrepass = systemData.m_TransparentDepthPrepass; + builtinData.transparentDepthPostpass = systemData.m_TransparentDepthPostpass; + builtinData.supportLodCrossFade = systemData.m_SupportLodCrossFade; +#pragma warning restore 618 + } + } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/BuiltinData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/BuiltinData.cs index 9631c205651..d6e530607bd 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/BuiltinData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/BuiltinData.cs @@ -85,5 +85,29 @@ public bool backThenFrontRendering get => m_BackThenFrontRendering; set => m_BackThenFrontRendering = value; } + + [SerializeField] + bool m_TransparentDepthPrepass; + public bool transparentDepthPrepass + { + get => m_TransparentDepthPrepass; + set => m_TransparentDepthPrepass = value; + } + + [SerializeField] + bool m_TransparentDepthPostpass; + public bool transparentDepthPostpass + { + get => m_TransparentDepthPostpass; + set => m_TransparentDepthPostpass = value; + } + + [SerializeField] + bool m_SupportLodCrossFade; + public bool supportLodCrossFade + { + get => m_SupportLodCrossFade; + set => m_SupportLodCrossFade = value; + } } } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs index dc6acf729c6..6df41be68da 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/SystemData.cs @@ -90,21 +90,14 @@ public bool alphaTest set => m_AlphaTest = value; } - [SerializeField] - bool m_TransparentDepthPrepass; - public bool transparentDepthPrepass - { - get => m_TransparentDepthPrepass; - set => m_TransparentDepthPrepass = value; - } + [SerializeField, Obsolete("Keep for migration")] + internal bool m_TransparentDepthPrepass; - [SerializeField] - bool m_TransparentDepthPostpass; - public bool transparentDepthPostpass - { - get => m_TransparentDepthPostpass; - set => m_TransparentDepthPostpass = value; - } + [SerializeField, Obsolete("Keep for migration")] + internal bool m_TransparentDepthPostpass; + + [SerializeField, Obsolete("Keep for migration")] + internal bool m_SupportLodCrossFade; [SerializeField] DoubleSidedMode m_DoubleSidedMode; @@ -114,14 +107,6 @@ public DoubleSidedMode doubleSidedMode set => m_DoubleSidedMode = value; } - [SerializeField] - bool m_SupportLodCrossFade; - public bool supportLodCrossFade - { - get => m_SupportLodCrossFade; - set => m_SupportLodCrossFade = value; - } - // TODO: This was on HDUnlitMaster but not used anywhere // TODO: On HDLit it adds the field `HDFields.DotsInstancing` // TODO: Should this be added properly to HDUnlit? @@ -141,6 +126,15 @@ public ShaderGraphVersion version set => m_Version = value; } + [SerializeField] + bool m_FirstTimeMigrationExecuted = false; + public bool firstTimeMigrationExecuted + { + get => m_FirstTimeMigrationExecuted; + set => m_FirstTimeMigrationExecuted = value; + } + + [SerializeField] internal int inspectorFoldoutMask; } diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs index e3beab194e2..cc644d73c9f 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/StackLit/ShaderGraph/StackLitSubTarget.Migration.cs @@ -32,10 +32,10 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary