Skip to content

Commit 664fe24

Browse files
Revert "Revert "Move shadergraph properties (#1214)""
This reverts commit 958486d.
1 parent 0ba9c99 commit 664fe24

File tree

12 files changed

+98
-54
lines changed

12 files changed

+98
-54
lines changed

com.unity.render-pipelines.high-definition/Editor/Material/Eye/ShaderGraph/EyeSubTarget.Migration.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
2727
// Previous master node wasn't having any renderingPass. Assign it correctly now.
2828
systemData.renderingPass = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent;
2929
systemData.alphaTest = eyeMasterNode.m_AlphaTest;
30-
systemData.transparentDepthPrepass = eyeMasterNode.m_AlphaTestDepthPrepass;
31-
systemData.transparentDepthPostpass = eyeMasterNode.m_AlphaTestDepthPostpass;
3230
systemData.sortPriority = eyeMasterNode.m_SortPriority;
3331
systemData.doubleSidedMode = eyeMasterNode.m_DoubleSidedMode;
3432
systemData.transparentZWrite = eyeMasterNode.m_ZWrite;
3533
systemData.transparentCullMode = eyeMasterNode.m_transparentCullMode;
3634
systemData.zTest = eyeMasterNode.m_ZTest;
37-
systemData.supportLodCrossFade = eyeMasterNode.m_SupportLodCrossFade;
3835
systemData.dotsInstancing = eyeMasterNode.m_DOTSInstancing;
3936
systemData.materialNeedsUpdateHash = eyeMasterNode.m_MaterialNeedsUpdateHash;
4037

38+
builtinData.transparentDepthPrepass = eyeMasterNode.m_AlphaTestDepthPrepass;
39+
builtinData.transparentDepthPostpass = eyeMasterNode.m_AlphaTestDepthPostpass;
40+
builtinData.supportLodCrossFade = eyeMasterNode.m_SupportLodCrossFade;
4141
builtinData.transparencyFog = eyeMasterNode.m_TransparencyFog;
4242
builtinData.addPrecomputedVelocity = eyeMasterNode.m_AddPrecomputedVelocity;
4343
builtinData.depthOffset = eyeMasterNode.m_depthOffset;

com.unity.render-pipelines.high-definition/Editor/Material/Fabric/ShaderGraph/FabricSubTarget.Migration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
3232
systemData.transparentZWrite = fabricMasterNode.m_ZWrite;
3333
systemData.transparentCullMode = fabricMasterNode.m_transparentCullMode;
3434
systemData.zTest = fabricMasterNode.m_ZTest;
35-
systemData.supportLodCrossFade = fabricMasterNode.m_SupportLodCrossFade;
3635
systemData.dotsInstancing = fabricMasterNode.m_DOTSInstancing;
3736
systemData.materialNeedsUpdateHash = fabricMasterNode.m_MaterialNeedsUpdateHash;
3837

38+
builtinData.supportLodCrossFade = fabricMasterNode.m_SupportLodCrossFade;
3939
builtinData.transparencyFog = fabricMasterNode.m_TransparencyFog;
4040
builtinData.addPrecomputedVelocity = fabricMasterNode.m_AddPrecomputedVelocity;
4141
builtinData.depthOffset = fabricMasterNode.m_depthOffset;

com.unity.render-pipelines.high-definition/Editor/Material/Hair/ShaderGraph/HairSubTarget.Migration.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
2727
// Previous master node wasn't having any renderingPass. Assign it correctly now.
2828
systemData.renderingPass = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent;
2929
systemData.alphaTest = hairMasterNode.m_AlphaTest;
30-
systemData.transparentDepthPrepass = hairMasterNode.m_AlphaTestDepthPrepass;
31-
systemData.transparentDepthPostpass = hairMasterNode.m_AlphaTestDepthPostpass;
3230
systemData.sortPriority = hairMasterNode.m_SortPriority;
3331
systemData.doubleSidedMode = hairMasterNode.m_DoubleSidedMode;
3432
systemData.transparentZWrite = hairMasterNode.m_ZWrite;
3533
systemData.transparentCullMode = hairMasterNode.m_transparentCullMode;
3634
systemData.zTest = hairMasterNode.m_ZTest;
37-
systemData.supportLodCrossFade = hairMasterNode.m_SupportLodCrossFade;
3835
systemData.dotsInstancing = hairMasterNode.m_DOTSInstancing;
3936
systemData.materialNeedsUpdateHash = hairMasterNode.m_MaterialNeedsUpdateHash;
4037

38+
builtinData.supportLodCrossFade = hairMasterNode.m_SupportLodCrossFade;
39+
builtinData.transparentDepthPrepass = hairMasterNode.m_AlphaTestDepthPrepass;
40+
builtinData.transparentDepthPostpass = hairMasterNode.m_AlphaTestDepthPostpass;
4141
builtinData.transparencyFog = hairMasterNode.m_TransparencyFog;
4242
builtinData.transparentWritesMotionVec = hairMasterNode.m_TransparentWritesMotionVec;
4343
builtinData.addPrecomputedVelocity = hairMasterNode.m_AddPrecomputedVelocity;
@@ -96,9 +96,9 @@ bool AdditionalSlotMaskTests(HairMasterNode1.SlotMask slotMask)
9696
case HairMasterNode1.SlotMask.AlphaClipThreshold:
9797
return systemData.alphaTest;
9898
case HairMasterNode1.SlotMask.AlphaClipThresholdDepthPrepass:
99-
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.transparentDepthPrepass;
99+
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPrepass;
100100
case HairMasterNode1.SlotMask.AlphaClipThresholdDepthPostpass:
101-
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.transparentDepthPostpass;
101+
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPostpass;
102102
case HairMasterNode1.SlotMask.AlphaClipThresholdShadow:
103103
return systemData.alphaTest && builtinData.alphaTestShadow;
104104
default:

com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.Migration.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ void UpgradePBRMasterNode(PBRMasterNode1 pbrMasterNode, out Dictionary<BlockFiel
4141
systemData.doubleSidedMode = pbrMasterNode.m_TwoSided ? DoubleSidedMode.Enabled : DoubleSidedMode.Disabled;
4242
// Previous master node wasn't having any renderingPass. Assign it correctly now.
4343
systemData.renderingPass = systemData.surfaceType == SurfaceType.Opaque ? HDRenderQueue.RenderQueueType.Opaque : HDRenderQueue.RenderQueueType.Transparent;
44-
systemData.alphaTest = HDSubShaderUtilities.UpgradeLegacyAlphaClip(pbrMasterNode);
4544
systemData.dotsInstancing = false;
45+
systemData.alphaTest = HDSubShaderUtilities.UpgradeLegacyAlphaClip(pbrMasterNode);
4646
builtinData.addPrecomputedVelocity = false;
4747
lightingData.blendPreserveSpecular = false;
4848
lightingData.normalDropOffSpace = pbrMasterNode.m_NormalDropOffSpace;
@@ -109,17 +109,17 @@ void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary<Blo
109109
if (systemData.renderingPass == HDRenderQueue.RenderQueueType.Background)
110110
systemData.renderingPass = HDRenderQueue.RenderQueueType.Opaque;
111111
systemData.alphaTest = hdLitMasterNode.m_AlphaTest;
112-
systemData.transparentDepthPrepass = hdLitMasterNode.m_AlphaTestDepthPrepass;
113-
systemData.transparentDepthPostpass = hdLitMasterNode.m_AlphaTestDepthPostpass;
114112
systemData.sortPriority = hdLitMasterNode.m_SortPriority;
115113
systemData.doubleSidedMode = hdLitMasterNode.m_DoubleSidedMode;
116114
systemData.transparentZWrite = hdLitMasterNode.m_ZWrite;
117115
systemData.transparentCullMode = hdLitMasterNode.m_transparentCullMode;
118116
systemData.zTest = hdLitMasterNode.m_ZTest;
119-
systemData.supportLodCrossFade = hdLitMasterNode.m_SupportLodCrossFade;
120117
systemData.dotsInstancing = hdLitMasterNode.m_DOTSInstancing;
121118
systemData.materialNeedsUpdateHash = hdLitMasterNode.m_MaterialNeedsUpdateHash;
122119

120+
builtinData.transparentDepthPrepass = hdLitMasterNode.m_AlphaTestDepthPrepass;
121+
builtinData.transparentDepthPostpass = hdLitMasterNode.m_AlphaTestDepthPostpass;
122+
builtinData.supportLodCrossFade = hdLitMasterNode.m_SupportLodCrossFade;
123123
builtinData.transparencyFog = hdLitMasterNode.m_TransparencyFog;
124124
builtinData.distortion = hdLitMasterNode.m_Distortion;
125125
builtinData.distortionMode = hdLitMasterNode.m_DistortionMode;
@@ -204,9 +204,9 @@ bool AdditionalSlotMaskTests(HDLitMasterNode1.SlotMask slotMask)
204204
case HDLitMasterNode1.SlotMask.AlphaThreshold:
205205
return systemData.alphaTest;
206206
case HDLitMasterNode1.SlotMask.AlphaThresholdDepthPrepass:
207-
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.transparentDepthPrepass;
207+
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPrepass;
208208
case HDLitMasterNode1.SlotMask.AlphaThresholdDepthPostpass:
209-
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.transparentDepthPostpass;
209+
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPostpass;
210210
case HDLitMasterNode1.SlotMask.AlphaThresholdShadow:
211211
return systemData.alphaTest && builtinData.alphaTestShadow;
212212
default:

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/AdvancedOptionsPropertyBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected override void CreatePropertyGUI()
3131
AddProperty(specularOcclusionModeText, () => lightingData.specularOcclusionMode, (newValue) => lightingData.specularOcclusionMode = newValue);
3232
AddProperty(Styles.overrideBakedGI, () => lightingData.overrideBakedGI, (newValue) => lightingData.overrideBakedGI = newValue);
3333
}
34-
AddProperty(Styles.supportLodCrossFade, () => systemData.supportLodCrossFade, (newValue) => systemData.supportLodCrossFade = newValue);
34+
AddProperty(Styles.supportLodCrossFade, () => builtinData.supportLodCrossFade, (newValue) => builtinData.supportLodCrossFade = newValue);
3535
AddProperty(addPrecomputedVelocityText, () => builtinData.addPrecomputedVelocity, (newValue) => builtinData.addPrecomputedVelocity = newValue);
3636
}
3737
}

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ public SystemData systemData
3333
set => m_SystemData = value;
3434
}
3535

36-
protected virtual int ComputeMaterialNeedsUpdateHash()
37-
{
38-
// Alpha test is currently the only property in system data to trigger the material upgrade script.
39-
int hash = systemData.alphaTest.GetHashCode();
40-
return hash;
41-
}
36+
protected virtual int ComputeMaterialNeedsUpdateHash() => 0;
4237

4338
public override bool IsActive() => true;
4439

@@ -97,6 +92,15 @@ public override void Setup(ref TargetSetupContext context)
9792
if (migrationSteps.Migrate(this))
9893
OnBeforeSerialize();
9994

95+
// Migration hack to have the case where SG doesn't have version yet but is already upgraded to the stack system
96+
if (!systemData.firstTimeMigrationExecuted)
97+
{
98+
// Force the initial migration step
99+
MigrateTo(ShaderGraphVersion.FirstTimeMigration);
100+
systemData.firstTimeMigrationExecuted = true;
101+
OnBeforeSerialize();
102+
}
103+
100104
foreach (var subShader in EnumerateSubShaders())
101105
{
102106
// patch render type and render queue from pass declaration:

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/ShaderGraphVersion.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph
99
public enum ShaderGraphVersion
1010
{
1111
Initial = 0,
12+
FirstTimeMigration = Initial,
1213
}
1314
}

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceOptionPropertyBlock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ protected override void CreatePropertyGUI()
6565
AddProperty(transparentCullModeText, () => systemData.transparentCullMode, (newValue) => systemData.transparentCullMode = newValue);
6666
AddProperty(transparentSortPriorityText, () => systemData.sortPriority, (newValue) => systemData.sortPriority = HDRenderQueue.ClampsTransparentRangePriority(newValue));
6767
AddProperty(transparentBackfaceEnableText, () => builtinData.backThenFrontRendering, (newValue) => builtinData.backThenFrontRendering = newValue);
68-
AddProperty(transparentDepthPrepassEnableText, () => systemData.transparentDepthPrepass, (newValue) => systemData.transparentDepthPrepass = newValue);
69-
AddProperty(transparentDepthPostpassEnableText, () => systemData.transparentDepthPostpass, (newValue) => systemData.transparentDepthPostpass = newValue);
68+
AddProperty(transparentDepthPrepassEnableText, () => builtinData.transparentDepthPrepass, (newValue) => builtinData.transparentDepthPrepass = newValue);
69+
AddProperty(transparentDepthPostpassEnableText, () => builtinData.transparentDepthPostpass, (newValue) => builtinData.transparentDepthPostpass = newValue);
7070
AddProperty(transparentWritingMotionVecText, () => builtinData.transparentWritesMotionVec, (newValue) => builtinData.transparentWritesMotionVec = newValue);
7171

7272
if (lightingData != null)

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/SurfaceSubTarget.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ protected override string renderQueue
4242
protected virtual bool supportDistortion => false;
4343
protected override bool supportRaytracing => true;
4444

45+
protected override int ComputeMaterialNeedsUpdateHash()
46+
{
47+
// Alpha test is currently the only property in buitin data to trigger the material upgrade script.
48+
int hash = systemData.alphaTest.GetHashCode();
49+
return hash;
50+
}
51+
4552
public override void Setup(ref TargetSetupContext context)
4653
{
4754
context.AddAssetDependencyPath(AssetDatabase.GUIDToAssetPath("f4df7e8f9b8c23648ae50cbca0221e47")); // SurfaceSubTarget.cs
@@ -194,15 +201,15 @@ public override void GetFields(ref TargetFieldContext context)
194201
context.AddField(HDFields.DoAlphaTestShadow, systemData.alphaTest && builtinData.alphaTestShadow && isShadowPass &&
195202
context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow));
196203
// Pre/post pass always use the specific alpha test provided for those pass
197-
context.AddField(HDFields.DoAlphaTestPrepass, systemData.alphaTest && systemData.transparentDepthPrepass && isTransparentDepthPrepass &&
204+
context.AddField(HDFields.DoAlphaTestPrepass, systemData.alphaTest && builtinData.transparentDepthPrepass && isTransparentDepthPrepass &&
198205
context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass));
199206

200207
// Features & Misc
201-
context.AddField(Fields.LodCrossFade, systemData.supportLodCrossFade);
208+
context.AddField(Fields.LodCrossFade, builtinData.supportLodCrossFade);
202209
context.AddField(Fields.AlphaToMask, systemData.alphaTest);
203210
context.AddField(HDFields.TransparentBackFace, builtinData.backThenFrontRendering);
204-
context.AddField(HDFields.TransparentDepthPrePass, systemData.transparentDepthPrepass);
205-
context.AddField(HDFields.TransparentDepthPostPass, systemData.transparentDepthPostpass);
211+
context.AddField(HDFields.TransparentDepthPrePass, builtinData.transparentDepthPrepass);
212+
context.AddField(HDFields.TransparentDepthPostPass, builtinData.transparentDepthPostpass);
206213

207214
context.AddField(HDFields.DepthOffset, builtinData.depthOffset && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.DepthOffset));
208215

@@ -239,8 +246,8 @@ public override void GetActiveBlocks(ref TargetActiveBlockContext context)
239246
context.AddBlock(BlockFields.SurfaceDescription.AlphaClipThreshold, systemData.alphaTest);
240247

241248
// Alpha Test
242-
context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, systemData.alphaTest && systemData.transparentDepthPrepass);
243-
context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, systemData.alphaTest && systemData.transparentDepthPostpass);
249+
context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPrepass, systemData.alphaTest && builtinData.transparentDepthPrepass);
250+
context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdDepthPostpass, systemData.alphaTest && builtinData.transparentDepthPostpass);
244251
context.AddBlock(HDBlockFields.SurfaceDescription.AlphaClipThresholdShadow, systemData.alphaTest && builtinData.alphaTestShadow);
245252

246253
// Misc
@@ -306,7 +313,7 @@ public override void CollectShaderProperties(PropertyCollector collector, Genera
306313
// Common properties for all "surface" master nodes
307314
HDSubShaderUtilities.AddAlphaCutoffShaderProperties(collector, systemData.alphaTest, builtinData.alphaTestShadow);
308315
HDSubShaderUtilities.AddDoubleSidedProperty(collector, systemData.doubleSidedMode);
309-
HDSubShaderUtilities.AddPrePostPassProperties(collector, systemData.transparentDepthPrepass, systemData.transparentDepthPostpass);
316+
HDSubShaderUtilities.AddPrePostPassProperties(collector, builtinData.transparentDepthPrepass, builtinData.transparentDepthPostpass);
310317

311318
// Add all shader properties required by the inspector
312319
HDSubShaderUtilities.AddBlendingStatesShaderProperties(
@@ -343,5 +350,19 @@ public override void ProcessPreviewMaterial(Material material)
343350

344351
LightingShaderGraphGUI.SetupMaterialKeywordsAndPass(material);
345352
}
353+
354+
internal override void MigrateTo(ShaderGraphVersion version)
355+
{
356+
base.MigrateTo(version);
357+
358+
if (version == ShaderGraphVersion.FirstTimeMigration)
359+
{
360+
#pragma warning disable 618
361+
builtinData.transparentDepthPrepass = systemData.m_TransparentDepthPrepass;
362+
builtinData.transparentDepthPostpass = systemData.m_TransparentDepthPostpass;
363+
builtinData.supportLodCrossFade = systemData.m_SupportLodCrossFade;
364+
#pragma warning restore 618
365+
}
366+
}
346367
}
347368
}

com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/TargetData/BuiltinData.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,29 @@ public bool backThenFrontRendering
8585
get => m_BackThenFrontRendering;
8686
set => m_BackThenFrontRendering = value;
8787
}
88+
89+
[SerializeField]
90+
bool m_TransparentDepthPrepass;
91+
public bool transparentDepthPrepass
92+
{
93+
get => m_TransparentDepthPrepass;
94+
set => m_TransparentDepthPrepass = value;
95+
}
96+
97+
[SerializeField]
98+
bool m_TransparentDepthPostpass;
99+
public bool transparentDepthPostpass
100+
{
101+
get => m_TransparentDepthPostpass;
102+
set => m_TransparentDepthPostpass = value;
103+
}
104+
105+
[SerializeField]
106+
bool m_SupportLodCrossFade;
107+
public bool supportLodCrossFade
108+
{
109+
get => m_SupportLodCrossFade;
110+
set => m_SupportLodCrossFade = value;
111+
}
88112
}
89113
}

0 commit comments

Comments
 (0)