Skip to content

Move shadergraph properties #1214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
// 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 = eyeMasterNode.m_AlphaTest;
systemData.transparentDepthPrepass = eyeMasterNode.m_AlphaTestDepthPrepass;
systemData.transparentDepthPostpass = eyeMasterNode.m_AlphaTestDepthPostpass;
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.supportLodCrossFade = eyeMasterNode.m_SupportLodCrossFade;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
systemData.transparentZWrite = fabricMasterNode.m_ZWrite;
systemData.transparentCullMode = fabricMasterNode.m_transparentCullMode;
systemData.zTest = fabricMasterNode.m_ZTest;
systemData.supportLodCrossFade = fabricMasterNode.m_SupportLodCrossFade;
systemData.dotsInstancing = fabricMasterNode.m_DOTSInstancing;
systemData.materialNeedsUpdateHash = fabricMasterNode.m_MaterialNeedsUpdateHash;

builtinData.supportLodCrossFade = fabricMasterNode.m_SupportLodCrossFade;
builtinData.transparencyFog = fabricMasterNode.m_TransparencyFog;
builtinData.addPrecomputedVelocity = fabricMasterNode.m_AddPrecomputedVelocity;
builtinData.depthOffset = fabricMasterNode.m_depthOffset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ public bool TryUpgradeFromMasterNode(IMasterNode1 masterNode, out Dictionary<Blo
// 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 = hairMasterNode.m_AlphaTest;
systemData.transparentDepthPrepass = hairMasterNode.m_AlphaTestDepthPrepass;
systemData.transparentDepthPostpass = hairMasterNode.m_AlphaTestDepthPostpass;
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.supportLodCrossFade = hairMasterNode.m_SupportLodCrossFade;
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;
Expand Down Expand Up @@ -96,9 +96,9 @@ bool AdditionalSlotMaskTests(HairMasterNode1.SlotMask slotMask)
case HairMasterNode1.SlotMask.AlphaClipThreshold:
return systemData.alphaTest;
case HairMasterNode1.SlotMask.AlphaClipThresholdDepthPrepass:
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.transparentDepthPrepass;
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPrepass;
case HairMasterNode1.SlotMask.AlphaClipThresholdDepthPostpass:
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.transparentDepthPostpass;
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPostpass;
case HairMasterNode1.SlotMask.AlphaClipThresholdShadow:
return systemData.alphaTest && builtinData.alphaTestShadow;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ void UpgradePBRMasterNode(PBRMasterNode1 pbrMasterNode, out Dictionary<BlockFiel
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.alphaTest = HDSubShaderUtilities.UpgradeLegacyAlphaClip(pbrMasterNode);
systemData.dotsInstancing = false;
systemData.alphaTest = HDSubShaderUtilities.UpgradeLegacyAlphaClip(pbrMasterNode);
builtinData.addPrecomputedVelocity = false;
lightingData.blendPreserveSpecular = false;
lightingData.normalDropOffSpace = pbrMasterNode.m_NormalDropOffSpace;
Expand Down Expand Up @@ -109,17 +109,17 @@ void UpgradeHDLitMasterNode(HDLitMasterNode1 hdLitMasterNode, out Dictionary<Blo
if (systemData.renderingPass == HDRenderQueue.RenderQueueType.Background)
systemData.renderingPass = HDRenderQueue.RenderQueueType.Opaque;
systemData.alphaTest = hdLitMasterNode.m_AlphaTest;
systemData.transparentDepthPrepass = hdLitMasterNode.m_AlphaTestDepthPrepass;
systemData.transparentDepthPostpass = hdLitMasterNode.m_AlphaTestDepthPostpass;
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.supportLodCrossFade = hdLitMasterNode.m_SupportLodCrossFade;
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;
Expand Down Expand Up @@ -204,9 +204,9 @@ bool AdditionalSlotMaskTests(HDLitMasterNode1.SlotMask slotMask)
case HDLitMasterNode1.SlotMask.AlphaThreshold:
return systemData.alphaTest;
case HDLitMasterNode1.SlotMask.AlphaThresholdDepthPrepass:
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.transparentDepthPrepass;
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPrepass;
case HDLitMasterNode1.SlotMask.AlphaThresholdDepthPostpass:
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && systemData.transparentDepthPostpass;
return systemData.surfaceType == SurfaceType.Transparent && systemData.alphaTest && builtinData.transparentDepthPostpass;
case HDLitMasterNode1.SlotMask.AlphaThresholdShadow:
return systemData.alphaTest && builtinData.alphaTestShadow;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override void CreatePropertyGUI()
AddProperty(specularOcclusionModeText, () => 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ namespace UnityEditor.Rendering.HighDefinition.ShaderGraph
public enum ShaderGraphVersion
{
Initial = 0,
FirstTimeMigration = Initial,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Loading