Skip to content

Commit fa607fd

Browse files
Antoine Lelievresebastienlagarde
andauthored
Refactor keyword system in ShaderGraph (#1181)
* Refactor the keyword system in ShaderGraph * Move geometric AA to respective master node Co-authored-by: Sebastien Lagarde <[email protected]>
1 parent 6c250d7 commit fa607fd

File tree

13 files changed

+238
-301
lines changed

13 files changed

+238
-301
lines changed

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

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,19 @@ sealed partial class DecalSubTarget : HDSubTarget, ILegacyTarget, IRequiresData<
1818
{
1919
public DecalSubTarget() => displayName = "Decal";
2020

21-
public static string passTemplatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Decal/ShaderGraph/DecalPass.template";
22-
23-
static string[] passTemplateMaterialDirectories = new string[]
21+
protected override string templatePath => $"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/Decal/ShaderGraph/DecalPass.template";
22+
protected override string[] templateMaterialDirectories => new string[]
2423
{
2524
$"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/ShaderGraph/Templates",
2625
$"{HDUtils.GetHDRenderPipelinePath()}Editor/Material/ShaderGraph/Templates/"
2726
};
28-
29-
protected override string templatePath => passTemplatePath;
30-
protected override string[] templateMaterialDirectories => passTemplateMaterialDirectories;
3127
protected override string subTargetAssetGuid => "3ec927dfcb5d60e4883b2c224857b6c2";
3228
protected override string customInspector => "Rendering.HighDefinition.DecalGUI";
3329
protected override string renderType => HDRenderTypeTags.Opaque.ToString();
3430
protected override string renderQueue => HDRenderQueue.GetShaderTagValue(HDRenderQueue.ChangeType(HDRenderQueue.RenderQueueType.Opaque, decalData.drawOrder, false, false));
3531
protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit;
32+
protected override FieldDescriptor subShaderField => new FieldDescriptor(kSubShader, "Decal Subshader", "");
33+
protected override string subShaderInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.hlsl";
3634

3735
// Material Data
3836
DecalData m_DecalData;
@@ -53,7 +51,12 @@ public DecalData decalData
5351

5452
protected override IEnumerable<SubShaderDescriptor> EnumerateSubShaders()
5553
{
56-
yield return SubShaders.Decal;
54+
yield return PostProcessSubShader(SubShaders.Decal);
55+
}
56+
57+
protected override void CollectPassKeywords(ref PassDescriptor pass)
58+
{
59+
pass.keywords.Add(CoreKeywordDescriptors.AlphaTest, new FieldCondition(Fields.AlphaTest, true));
5760
}
5861

5962
public static FieldDescriptor AffectsAlbedo = new FieldDescriptor(kMaterial, "AffectsAlbedo", "_MATERIAL_AFFECTS_ALBEDO 1");
@@ -127,7 +130,6 @@ static class SubShaders
127130
{
128131
public static SubShaderDescriptor Decal = new SubShaderDescriptor()
129132
{
130-
pipelineTag = HDRenderPipeline.k_ShaderTagName,
131133
generatesPreview = true,
132134
passes = new PassCollection
133135
{
@@ -156,10 +158,6 @@ public static class DecalPasses
156158
lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferProjector3RT],
157159
useInPreview = false,
158160

159-
// Template
160-
passTemplatePath = passTemplatePath,
161-
sharedTemplateDirectories = passTemplateMaterialDirectories,
162-
163161
// Port mask
164162
validPixelBlocks = DecalBlockMasks.FragmentDefault,
165163

@@ -180,10 +178,6 @@ public static class DecalPasses
180178
lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferProjector4RT],
181179
useInPreview = false,
182180

183-
// Template
184-
passTemplatePath = passTemplatePath,
185-
sharedTemplateDirectories = passTemplateMaterialDirectories,
186-
187181
// Port mask
188182
validPixelBlocks = DecalBlockMasks.FragmentDefault,
189183

@@ -206,10 +200,6 @@ public static class DecalPasses
206200
lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_ProjectorEmissive],
207201
useInPreview = false,
208202

209-
// Template
210-
passTemplatePath = passTemplatePath,
211-
sharedTemplateDirectories = passTemplateMaterialDirectories,
212-
213203
// Port mask
214204
validPixelBlocks = DecalBlockMasks.FragmentEmissive,
215205

@@ -231,10 +221,6 @@ public static class DecalPasses
231221
lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferMesh3RT],
232222
useInPreview = false,
233223

234-
// Template
235-
passTemplatePath = passTemplatePath,
236-
sharedTemplateDirectories = passTemplateMaterialDirectories,
237-
238224
// Port mask
239225
validPixelBlocks = DecalBlockMasks.FragmentDefault,
240226

@@ -258,10 +244,6 @@ public static class DecalPasses
258244
lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_DBufferMesh4RT],
259245
useInPreview = false,
260246

261-
// Template
262-
passTemplatePath = passTemplatePath,
263-
sharedTemplateDirectories = passTemplateMaterialDirectories,
264-
265247
// Port mask
266248
validPixelBlocks = DecalBlockMasks.FragmentDefault,
267249

@@ -285,10 +267,6 @@ public static class DecalPasses
285267
lightMode = DecalSystem.s_MaterialSGDecalPassNames[(int)DecalSystem.MaterialSGDecalPass.ShaderGraph_MeshEmissive],
286268
useInPreview = false,
287269

288-
// Template
289-
passTemplatePath = passTemplatePath,
290-
sharedTemplateDirectories = passTemplateMaterialDirectories,
291-
292270
// Port mask
293271
validPixelBlocks = DecalBlockMasks.FragmentMeshEmissive,
294272

@@ -311,10 +289,6 @@ public static class DecalPasses
311289
lightMode = "ForwardOnly",
312290
useInPreview = true,
313291

314-
// Template
315-
passTemplatePath = passTemplatePath,
316-
sharedTemplateDirectories = passTemplateMaterialDirectories,
317-
318292
// Port mask
319293
validPixelBlocks = DecalBlockMasks.FragmentMeshEmissive,
320294

@@ -592,7 +566,6 @@ static class Descriptors
592566
};
593567
}
594568
#endregion
595-
// protected override IncludeCollection subShaderIncludes => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Decal/Decal.hlsl";
596569

597570
#region Includes
598571
static class DecalIncludes

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public override void GetFields(ref TargetFieldContext context)
5959
context.AddField(Eye, eyeData.materialType == EyeData.MaterialType.Eye);
6060
context.AddField(EyeCinematic, eyeData.materialType == EyeData.MaterialType.EyeCinematic);
6161
context.AddField(SubsurfaceScattering, eyeData.subsurfaceScattering && systemData.surfaceType != SurfaceType.Transparent);
62+
63+
context.AddField(SpecularAA, lightingData.specularAA &&
64+
context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAThreshold) &&
65+
context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance));
6266
}
6367

6468
public override void GetActiveBlocks(ref TargetActiveBlockContext context)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public override void GetFields(ref TargetFieldContext context)
7070
context.AddField(SubsurfaceScattering, fabricData.subsurfaceScattering && systemData.surfaceType != SurfaceType.Transparent);
7171
context.AddField(Transmission, fabricData.transmission);
7272
context.AddField(EnergyConservingSpecular, fabricData.energyConservingSpecular);
73+
74+
context.AddField(SpecularAA, lightingData.specularAA &&
75+
context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAThreshold) &&
76+
context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance));
7377
}
7478

7579
public override void GetActiveBlocks(ref TargetActiveBlockContext context)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ public override void GetFields(ref TargetFieldContext context)
119119
context.AddField(ClearCoat, litData.clearCoat); // Enable clear coat material feature
120120
context.AddField(Tangent, descs.Contains(HDBlockFields.SurfaceDescription.Tangent) && context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.Tangent));
121121
context.AddField(RayTracing, litData.rayTracing);
122+
123+
context.AddField(SpecularAA, lightingData.specularAA &&
124+
context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAThreshold) &&
125+
context.pass.validPixelBlocks.Contains(HDBlockFields.SurfaceDescription.SpecularAAScreenSpaceVariance));
122126
}
123127

124128
public override void GetActiveBlocks(ref TargetActiveBlockContext context)

0 commit comments

Comments
 (0)