Skip to content

Commit a24f243

Browse files
committed
Fix culture issues when generating attributes defines in shaders (#40)
1 parent 3f567a8 commit a24f243

File tree

7 files changed

+20
-13
lines changed

7 files changed

+20
-13
lines changed

com.unity.visualeffectgraph/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1414
- SpawnIndex attribute returns correct value in update and outputs contexts
1515
- Disable Reset option in context menu for all VFXObject [Case 1251519](https://issuetracker.unity3d.com/product/unity/issues/guid/1251519/) & [Case 1251533](https://issuetracker.unity3d.com/product/unity/issues/guid/1251533/)
1616
- Avoid other NullReferenceException using property binders
17+
- Fix culture issues when generating attributes defines in shaders [Case 1222819](https://issuetracker.unity3d.com/product/unity/issues/guid/1222819/)
1718

1819
## [7.5.0] - 2020-06-08
1920

com.unity.visualeffectgraph/Editor/Compiler/VFXCodeGenerator.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
using Object = UnityEngine.Object;
1010
using System.Text.RegularExpressions;
11+
using System.Globalization;
1112

1213
namespace UnityEditor.VFX
1314
{
@@ -412,9 +413,9 @@ static private StringBuilder Build(VFXContext context, string templatePath, VFXC
412413
globalIncludeContent.WriteLine("#define VFX_PASSDEPTH_SELECTION (2)");
413414

414415
foreach (var attribute in allCurrentAttributes)
415-
globalIncludeContent.WriteLineFormat("#define VFX_USE_{0}_{1} 1", attribute.attrib.name.ToUpper(), "CURRENT");
416+
globalIncludeContent.WriteLineFormat("#define VFX_USE_{0}_{1} 1", attribute.attrib.name.ToUpper(CultureInfo.InvariantCulture), "CURRENT");
416417
foreach (var attribute in allSourceAttributes)
417-
globalIncludeContent.WriteLineFormat("#define VFX_USE_{0}_{1} 1", attribute.attrib.name.ToUpper(), "SOURCE");
418+
globalIncludeContent.WriteLineFormat("#define VFX_USE_{0}_{1} 1", attribute.attrib.name.ToUpper(CultureInfo.InvariantCulture), "SOURCE");
418419

419420
foreach (var additionnalHeader in context.additionalDataHeaders)
420421
globalIncludeContent.WriteLine(additionnalHeader);

com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/Attribute/AttributeFromCurve.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using UnityEngine;
55
using UnityEngine.VFX;
6+
using System.Globalization;
67

78
namespace UnityEditor.VFX.Block
89
{
@@ -213,7 +214,7 @@ protected override IEnumerable<string> filteredOutSettings
213214

214215
static private string GenerateLocalAttributeName(string name)
215216
{
216-
return name[0].ToString().ToUpper() + name.Substring(1);
217+
return name[0].ToString().ToUpper(CultureInfo.InvariantCulture) + name.Substring(1);
217218
}
218219

219220
public override string source

com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/Attribute/SetCustomAttribute.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using UnityEngine;
55
using UnityEngine.VFX;
6+
using System.Globalization;
67

78
namespace UnityEditor.VFX.Block
89
{
@@ -80,7 +81,7 @@ public override IEnumerable<VFXAttributeInfo> attributes
8081

8182
static private string GenerateLocalAttributeName(string name)
8283
{
83-
return "_" + name[0].ToString().ToUpper() + name.Substring(1);
84+
return "_" + name[0].ToString().ToUpper(CultureInfo.InvariantCulture) + name.Substring(1);
8485
}
8586

8687
public override string source

com.unity.visualeffectgraph/Editor/Models/Blocks/Implementations/SetAttribute.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using UnityEngine;
66
using UnityEngine.VFX;
7+
using System.Globalization;
78

89
namespace UnityEditor.VFX.Block
910
{
@@ -188,7 +189,7 @@ public override IEnumerable<VFXAttributeInfo> attributes
188189

189190
static private string GenerateLocalAttributeName(string name)
190191
{
191-
return name[0].ToString().ToUpper() + name.Substring(1);
192+
return name[0].ToString().ToUpper(CultureInfo.InvariantCulture) + name.Substring(1);
192193
}
193194

194195
public override string source
@@ -306,7 +307,7 @@ protected override IEnumerable<VFXPropertyWithValue> inputProperties
306307
var attrib = currentAttribute;
307308

308309
VFXPropertyAttribute[] attr = null;
309-
var field = typeof(VFXAttribute).GetField(attrib.name.Substring(0, 1).ToUpper() + attrib.name.Substring(1), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
310+
var field = typeof(VFXAttribute).GetField(attrib.name.Substring(0, 1).ToUpper(CultureInfo.InvariantCulture) + attrib.name.Substring(1), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
310311

311312
TooltipAttribute tooltip = null;
312313

com.unity.visualeffectgraph/Editor/Models/Parameters/VFXAttributeParameter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using UnityEngine;
56

@@ -91,7 +92,7 @@ protected override IEnumerable<VFXPropertyWithValue> outputProperties
9192
{
9293
var attribute = VFXAttribute.Find(this.attribute);
9394

94-
var field = typeof(VFXAttribute).GetField(attribute.name.Substring(0, 1).ToUpper() + attribute.name.Substring(1), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
95+
var field = typeof(VFXAttribute).GetField(attribute.name.Substring(0, 1).ToUpper(CultureInfo.InvariantCulture) + attribute.name.Substring(1), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
9596

9697
TooltipAttribute tooltip = null;
9798

com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Globalization;
34
using System.Linq;
45
using System.Reflection;
56
using UnityEditor.ShaderGraph;
@@ -258,7 +259,7 @@ public override IEnumerable<string> additionalDefines
258259
{
259260
var portInfo = shaderGraph.GetOutput(port);
260261
if (!string.IsNullOrEmpty(portInfo.referenceName))
261-
yield return $"HAS_SHADERGRAPH_PARAM_{portInfo.referenceName.ToUpper()}";
262+
yield return $"HAS_SHADERGRAPH_PARAM_{portInfo.referenceName.ToUpper(CultureInfo.InvariantCulture)}";
262263
}
263264

264265
bool needsPosWS = false;
@@ -278,10 +279,10 @@ public override IEnumerable<string> additionalDefines
278279
bool hasNormalPort = pixelPorts.Any(t => t == ShaderGraphVfxAsset.NormalSlotId) && shaderGraph.HasOutput(ShaderGraphVfxAsset.NormalSlotId);
279280

280281
if (readsNormal || readsTangent || hasNormalPort) // needs normal
281-
yield return $"SHADERGRAPH_NEEDS_NORMAL_{kvPass.Key.ToUpper()}";
282+
yield return $"SHADERGRAPH_NEEDS_NORMAL_{kvPass.Key.ToUpper(CultureInfo.InvariantCulture)}";
282283

283284
if (readsTangent || hasNormalPort) // needs tangent
284-
yield return $"SHADERGRAPH_NEEDS_TANGENT_{kvPass.Key.ToUpper()}";
285+
yield return $"SHADERGRAPH_NEEDS_TANGENT_{kvPass.Key.ToUpper(CultureInfo.InvariantCulture)}";
285286

286287
needsPosWS |= graphCode.requirements.requiresPosition != NeededCoordinateSpace.None ||
287288
graphCode.requirements.requiresScreenPosition ||
@@ -413,7 +414,7 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep
413414
{
414415
var portInfo = shaderGraph.GetOutput(port);
415416
if (!string.IsNullOrEmpty(portInfo.referenceName))
416-
yield return new KeyValuePair<string, VFXShaderWriter>($"${{SHADERGRAPH_PARAM_{portInfo.referenceName.ToUpper()}}}", new VFXShaderWriter($"{portInfo.referenceName}_{portInfo.id}"));
417+
yield return new KeyValuePair<string, VFXShaderWriter>($"${{SHADERGRAPH_PARAM_{portInfo.referenceName.ToUpper(CultureInfo.InvariantCulture)}}}", new VFXShaderWriter($"{portInfo.referenceName}_{portInfo.id}"));
417418
}
418419

419420
foreach (var kvPass in graphCodes)
@@ -426,7 +427,7 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep
426427
if (graphCode.requirements.requiresDepthTexture)
427428
preProcess.WriteLine("#define REQUIRE_DEPTH_TEXTURE");
428429
preProcess.WriteLine("${VFXShaderGraphFunctionsInclude}\n");
429-
yield return new KeyValuePair<string, VFXShaderWriter>("${SHADERGRAPH_PIXEL_CODE_" + kvPass.Key.ToUpper() + "}", new VFXShaderWriter(preProcess.ToString() + graphCode.code));
430+
yield return new KeyValuePair<string, VFXShaderWriter>("${SHADERGRAPH_PIXEL_CODE_" + kvPass.Key.ToUpper(CultureInfo.InvariantCulture) + "}", new VFXShaderWriter(preProcess.ToString() + graphCode.code));
430431

431432
var callSG = new VFXShaderWriter("//Call Shader Graph\n");
432433
callSG.builder.AppendLine($"{shaderGraph.inputStructName} INSG = ({shaderGraph.inputStructName})0;");
@@ -547,7 +548,7 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep
547548
#endif");
548549
}
549550

550-
yield return new KeyValuePair<string, VFXShaderWriter>("${SHADERGRAPH_PIXEL_CALL_" + kvPass.Key.ToUpper() + "}", callSG);
551+
yield return new KeyValuePair<string, VFXShaderWriter>("${SHADERGRAPH_PIXEL_CALL_" + kvPass.Key.ToUpper(CultureInfo.InvariantCulture) + "}", callSG);
551552
}
552553
}
553554
}

0 commit comments

Comments
 (0)