Skip to content

Commit 820dc41

Browse files
Esmeralda SalamoneEvergreen
authored andcommitted
[ShaderGraph] Allow nested keyword definitions to generate properly in final shader
1 parent 8d5c735 commit 820dc41

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

Packages/com.unity.shadergraph/Editor/Data/Graphs/GraphData.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,12 +1371,33 @@ public void CollectShaderProperties(PropertyCollector collector, GenerationMode
13711371
}
13721372
}
13731373

1374+
private static void CollectSubgraphKeywordsR(KeywordCollector collector, SubGraphAsset asset)
1375+
{
1376+
if (asset is null || !asset.isValid || asset.isNull)
1377+
return;
1378+
1379+
foreach(var keyword in asset.keywords)
1380+
{
1381+
collector.AddShaderKeyword(keyword);
1382+
}
1383+
foreach(var guid in asset.children)
1384+
{
1385+
var path = AssetDatabase.GUIDToAssetPath(guid);
1386+
var child = AssetDatabase.LoadAssetAtPath<SubGraphAsset>(path);
1387+
CollectSubgraphKeywordsR(collector, child);
1388+
}
1389+
}
1390+
13741391
public void CollectShaderKeywords(KeywordCollector collector, GenerationMode generationMode)
13751392
{
13761393
foreach (var keyword in keywords)
13771394
{
13781395
collector.AddShaderKeyword(keyword);
13791396
}
1397+
foreach(var node in GetNodes<SubGraphNode>())
1398+
{
1399+
CollectSubgraphKeywordsR(collector, node.asset);
1400+
}
13801401

13811402
// Alwways calculate permutations when collecting
13821403
collector.CalculateKeywordPermutations();

Packages/com.unity.shadergraph/Editor/Data/SubGraph/SubGraphAsset.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class SubGraphAsset : ScriptableObject, ISerializationCallbackReceiver
8383

8484
public string assetGuid;
8585

86+
public bool isNull => m_SubGraphData == null;
87+
8688
public ShaderGraphRequirements requirements;
8789

8890
public string path;

0 commit comments

Comments
 (0)