Skip to content

Commit 22fa8d2

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.0] [UUM-78849] Add an option to include Custom Function Node source using #include_with_pragmas
https://jira.unity3d.com/browse/UUM-78849 This PR addresses the issue by: - Defaulting the behavior to `#include_with_pragmas` to restore Shader Graph's previous behavior - Adding a toggle to choose between `#include` and `#include_with_pragmas` on Custom Function Nodes
1 parent 4b7629d commit 22fa8d2

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

Packages/com.unity.shadergraph/Editor/Data/Nodes/Utility/CustomFunctionNode.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ public string functionSource
124124
set => m_FunctionSource = value;
125125
}
126126

127+
[SerializeField]
128+
private bool m_FunctionSourceUsePragmas = true;
129+
130+
public bool functionSourceUsePragmas
131+
{
132+
get => m_FunctionSourceUsePragmas;
133+
set => m_FunctionSourceUsePragmas = value;
134+
}
135+
127136
[SerializeField]
128137
string m_FunctionBody = k_DefaultFunctionBody;
129138

@@ -264,7 +273,7 @@ public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode gener
264273
if (string.IsNullOrEmpty(path))
265274
path = functionSource;
266275

267-
registry.RequiresIncludePath(path);
276+
registry.RequiresIncludePath(path, shouldIncludeWithPragmas: functionSourceUsePragmas);
268277
break;
269278
case HlslSourceType.String:
270279
registry.ProvideFunction(hlslFunctionName, builder =>

Packages/com.unity.shadergraph/Editor/Drawing/Views/HlslFunctionView.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal class HlslFunctionView : VisualElement
1515
private EnumField m_Type;
1616
private TextField m_FunctionName;
1717
private ObjectField m_FunctionSource;
18+
private Toggle m_FunctionSourceUsePragmas;
1819
private TextField m_FunctionBody;
1920

2021
internal HlslFunctionView(CustomFunctionNode node)
@@ -85,6 +86,21 @@ private void Draw(CustomFunctionNode node)
8586
}
8687
});
8788

89+
m_FunctionSourceUsePragmas = new Toggle
90+
{
91+
value = node.functionSourceUsePragmas
92+
};
93+
m_FunctionSourceUsePragmas.RegisterValueChangedCallback(s =>
94+
{
95+
if (s.newValue != node.functionSourceUsePragmas)
96+
{
97+
node.owner.owner.RegisterCompleteObjectUndo("Change Function Source Pragma Usage");
98+
node.functionSourceUsePragmas = s.newValue;
99+
node.ValidateNode();
100+
node.Dirty(ModificationScope.Graph);
101+
}
102+
});
103+
88104
m_FunctionBody = new TextField { value = node.functionBody, multiline = true };
89105
m_FunctionBody.AddToClassList("sg-hlsl-function-view__body");
90106
m_FunctionBody.verticalScrollerVisibility = ScrollerVisibility.Auto;
@@ -133,6 +149,15 @@ private void Draw(CustomFunctionNode node)
133149
sourceRow.Add(m_FunctionSource);
134150
}
135151
Add(sourceRow);
152+
153+
VisualElement functionSourceUsePragmasRow = new VisualElement() { name = "Row" };
154+
{
155+
functionSourceUsePragmasRow.Add(new Label("Use Pragmas"));
156+
functionSourceUsePragmasRow.Add(m_FunctionSourceUsePragmas);
157+
functionSourceUsePragmasRow.tooltip = "Determines whether or not Unity pragmas from the included file will be used in the generated shader.";
158+
}
159+
Add(functionSourceUsePragmasRow);
160+
136161
break;
137162
case HlslSourceType.String:
138163
VisualElement bodyRow = new VisualElement() { name = "Row" };

0 commit comments

Comments
 (0)