Skip to content

Commit

Permalink
[2021][ShaderGraph] Precision backport fix
Browse files Browse the repository at this point in the history
Backport to fix some of our shaderlab code gen so that it made half precision explicit in all circumstances, this makes it compile correctly for mobile devices.
  • Loading branch information
Esmeralda Salamone authored and Evergreen committed Apr 9, 2024
1 parent ef6b886 commit fd82bba
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected override string ConcreteSlotValueAsVariable()
var channelCount = SlotValueHelper.GetChannelCount(concreteValueType);
string values = NodeUtils.FloatToShaderValue(value.x);
if (channelCount == 1)
return values;
return string.Format("$precision({0})", values);
for (var i = 1; i < channelCount; i++)
values += ", " + NodeUtils.FloatToShaderValue(value[i]);
return string.Format("$precision{0}({1})", channelCount, values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public override VisualElement InstantiateControl()

protected override string ConcreteSlotValueAsVariable()
{
return NodeUtils.FloatToShaderValue(value);
return string.Format("$precision({0})", NodeUtils.FloatToShaderValue(value));
}

public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public void MaterialSlotReturnsValidDefaultValue()
Assert.AreEqual(expected, result);

m_NodeA.slot1.value = 6;
result = m_NodeA.slot1.GetDefaultValue(GenerationMode.ForReals);
Assert.AreEqual("6", result);
result = m_NodeA.slot1.GetDefaultValue(GenerationMode.ForReals, ConcretePrecision.Half);
Assert.AreEqual("half(6)", result);

m_NodeA.slot2.value = new Vector4(6, 6, 6, 1);
result = m_NodeA.slot2.GetDefaultValue(GenerationMode.ForReals, ConcretePrecision.Half);
Expand Down

0 comments on commit fd82bba

Please sign in to comment.