Skip to content

Commit 5df2e04

Browse files
alexandret-unityEvergreen
authored andcommitted
UUM-115301: Fixed ability to use SampleTextureElement multiple times
1 parent 570c539 commit 5df2e04

1 file changed

Lines changed: 33 additions & 10 deletions

File tree

Packages/com.unity.shadergraph/Editor/Data/Nodes/UI/SampleElementTextureNode.cs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEditor.Graphing;
23
using UnityEditor.Rendering.UITK.ShaderGraph;
34
using UnityEngine;
@@ -6,7 +7,7 @@ namespace UnityEditor.ShaderGraph
67
{
78
[Title("UI", "Sample Element Texture")]
89
[SubTargetFilter(typeof(IUISubTarget))]
9-
class SampleElementTextureNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireUITK
10+
class SampleElementTextureNode : AbstractMaterialNode, IGeneratesFunction, IGeneratesBodyCode, IMayRequireUITK
1011
{
1112

1213
public const int UV0Id = 0;
@@ -61,22 +62,44 @@ public override void UpdateNodeAfterDeserialization()
6162
});
6263
}
6364

65+
public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
66+
{
67+
registry.ProvideFunction("UIE_SAMPLE4", sb =>
68+
{
69+
sb.AppendLine(@"#define UIE_SAMPLE4(index) \");
70+
sb.AppendLine(@" c0 = UNITY_SAMPLE_TEX2D(_Texture##index, uv0); \");
71+
sb.AppendLine(@" c1 = UNITY_SAMPLE_TEX2D(_Texture##index, uv1); \");
72+
sb.AppendLine(@" c2 = UNITY_SAMPLE_TEX2D(_Texture##index, uv2); \");
73+
sb.AppendLine(@" c3 = UNITY_SAMPLE_TEX2D(_Texture##index, uv3);");
74+
sb.AppendLine("");
75+
sb.AppendLine("void SampleTextureSlot4(half index, float2 uv0, float2 uv1, float2 uv2, float2 uv3, out float4 c0, out float4 c1, out float4 c2, out float4 c3)");
76+
using (sb.BlockScope())
77+
{
78+
sb.AppendLine("UIE_BRANCH(UIE_SAMPLE4)");
79+
}
80+
});
81+
}
82+
6483
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
6584
{
6685
sb.AppendLine("$precision4 {0};", GetVariableNameForSlot(Color0SlotId));
6786
sb.AppendLine("$precision4 {0};", GetVariableNameForSlot(Color1SlotId));
6887
sb.AppendLine("$precision4 {0};", GetVariableNameForSlot(Color2SlotId));
6988
sb.AppendLine("$precision4 {0};", GetVariableNameForSlot(Color3SlotId));
7089

71-
sb.Append("#define UIE_SAMPLEX(index) ");
72-
sb.Append("{0} = UNITY_SAMPLE_TEX2D(_Texture##index, {1});", GetVariableNameForSlot(Color0SlotId), GetSlotValue(UV0Id, generationMode));
73-
sb.Append("{0} = UNITY_SAMPLE_TEX2D(_Texture##index, {1});", GetVariableNameForSlot(Color1SlotId), GetSlotValue(UV1Id, generationMode));
74-
sb.Append("{0} = UNITY_SAMPLE_TEX2D(_Texture##index, {1});", GetVariableNameForSlot(Color2SlotId), GetSlotValue(UV2Id, generationMode));
75-
sb.Append("{0} = UNITY_SAMPLE_TEX2D(_Texture##index, {1});", GetVariableNameForSlot(Color3SlotId), GetSlotValue(UV3Id, generationMode));
76-
sb.AppendLine("");
77-
78-
sb.AppendLine("half index = IN.typeTexSettings.y;");
79-
sb.AppendLine("UIE_BRANCH(UIE_SAMPLEX)");
90+
using (sb.BlockScope())
91+
{
92+
sb.AppendLine("half Unity_UIE_TextureSlotIndex = IN.typeTexSettings.y;");
93+
sb.AppendLine("SampleTextureSlot4(Unity_UIE_TextureSlotIndex, {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7});",
94+
GetSlotValue(UV0Id, generationMode),
95+
GetSlotValue(UV1Id, generationMode),
96+
GetSlotValue(UV2Id, generationMode),
97+
GetSlotValue(UV3Id, generationMode),
98+
GetVariableNameForSlot(Color0SlotId),
99+
GetVariableNameForSlot(Color1SlotId),
100+
GetVariableNameForSlot(Color2SlotId),
101+
GetVariableNameForSlot(Color3SlotId));
102+
}
80103
}
81104

82105
public bool RequiresUITK(ShaderStageCapability stageCapability)

0 commit comments

Comments
 (0)