Skip to content

Commit 142d301

Browse files
committed
Fix culture issues when generating attributes defines in shaders (#40)
1 parent 53d8f77 commit 142d301

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
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2323
- SpawnIndex attribute returns correct value in update and outputs contexts
2424
- 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/)
2525
- Avoid other NullReferenceException using property binders
26+
- Fix culture issues when generating attributes defines in shaders [Case 1222819](https://issuetracker.unity3d.com/product/unity/issues/guid/1222819/)
2627

2728
## [9.0.0] - 2020-07-09
2829

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
{
@@ -418,9 +419,9 @@ static private StringBuilder Build(VFXContext context, string templatePath, VFXC
418419
globalIncludeContent.WriteLine("#define VFX_PASSDEPTH_SELECTION (2)");
419420

420421
foreach (var attribute in allCurrentAttributes)
421-
globalIncludeContent.WriteLineFormat("#define VFX_USE_{0}_{1} 1", attribute.attrib.name.ToUpper(), "CURRENT");
422+
globalIncludeContent.WriteLineFormat("#define VFX_USE_{0}_{1} 1", attribute.attrib.name.ToUpper(CultureInfo.InvariantCulture), "CURRENT");
422423
foreach (var attribute in allSourceAttributes)
423-
globalIncludeContent.WriteLineFormat("#define VFX_USE_{0}_{1} 1", attribute.attrib.name.ToUpper(), "SOURCE");
424+
globalIncludeContent.WriteLineFormat("#define VFX_USE_{0}_{1} 1", attribute.attrib.name.ToUpper(CultureInfo.InvariantCulture), "SOURCE");
424425

425426
foreach (var additionnalHeader in context.additionalDataHeaders)
426427
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
VFXPropertyAttributes attr = new VFXPropertyAttributes();
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;
@@ -269,7 +270,7 @@ public override IEnumerable<string> additionalDefines
269270
{
270271
var portInfo = shaderGraph.GetOutput(port);
271272
if (!string.IsNullOrEmpty(portInfo.referenceName))
272-
yield return $"HAS_SHADERGRAPH_PARAM_{portInfo.referenceName.ToUpper()}";
273+
yield return $"HAS_SHADERGRAPH_PARAM_{portInfo.referenceName.ToUpper(CultureInfo.InvariantCulture)}";
273274
}
274275

275276
bool needsPosWS = false;
@@ -289,10 +290,10 @@ public override IEnumerable<string> additionalDefines
289290
bool hasNormalPort = pixelPorts.Any(t => t == ShaderGraphVfxAsset.NormalSlotId) && shaderGraph.HasOutput(ShaderGraphVfxAsset.NormalSlotId);
290291

291292
if (readsNormal || readsTangent || hasNormalPort) // needs normal
292-
yield return $"SHADERGRAPH_NEEDS_NORMAL_{kvPass.Key.ToUpper()}";
293+
yield return $"SHADERGRAPH_NEEDS_NORMAL_{kvPass.Key.ToUpper(CultureInfo.InvariantCulture)}";
293294

294295
if (readsTangent || hasNormalPort) // needs tangent
295-
yield return $"SHADERGRAPH_NEEDS_TANGENT_{kvPass.Key.ToUpper()}";
296+
yield return $"SHADERGRAPH_NEEDS_TANGENT_{kvPass.Key.ToUpper(CultureInfo.InvariantCulture)}";
296297

297298
needsPosWS |= graphCode.requirements.requiresPosition != NeededCoordinateSpace.None ||
298299
graphCode.requirements.requiresScreenPosition ||
@@ -429,7 +430,7 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep
429430
{
430431
var portInfo = shaderGraph.GetOutput(port);
431432
if (!string.IsNullOrEmpty(portInfo.referenceName))
432-
yield return new KeyValuePair<string, VFXShaderWriter>($"${{SHADERGRAPH_PARAM_{portInfo.referenceName.ToUpper()}}}", new VFXShaderWriter($"{portInfo.referenceName}_{portInfo.id}"));
433+
yield return new KeyValuePair<string, VFXShaderWriter>($"${{SHADERGRAPH_PARAM_{portInfo.referenceName.ToUpper(CultureInfo.InvariantCulture)}}}", new VFXShaderWriter($"{portInfo.referenceName}_{portInfo.id}"));
433434
}
434435

435436
foreach (var kvPass in graphCodes)
@@ -442,7 +443,7 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep
442443
if (graphCode.requirements.requiresDepthTexture)
443444
preProcess.WriteLine("#define REQUIRE_DEPTH_TEXTURE");
444445
preProcess.WriteLine("${VFXShaderGraphFunctionsInclude}\n");
445-
yield return new KeyValuePair<string, VFXShaderWriter>("${SHADERGRAPH_PIXEL_CODE_" + kvPass.Key.ToUpper() + "}", new VFXShaderWriter(preProcess.ToString() + graphCode.code));
446+
yield return new KeyValuePair<string, VFXShaderWriter>("${SHADERGRAPH_PIXEL_CODE_" + kvPass.Key.ToUpper(CultureInfo.InvariantCulture) + "}", new VFXShaderWriter(preProcess.ToString() + graphCode.code));
446447

447448
var callSG = new VFXShaderWriter("//Call Shader Graph\n");
448449
callSG.builder.AppendLine($"{shaderGraph.inputStructName} INSG = ({shaderGraph.inputStructName})0;");
@@ -563,7 +564,7 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep
563564
#endif");
564565
}
565566

566-
yield return new KeyValuePair<string, VFXShaderWriter>("${SHADERGRAPH_PIXEL_CALL_" + kvPass.Key.ToUpper() + "}", callSG);
567+
yield return new KeyValuePair<string, VFXShaderWriter>("${SHADERGRAPH_PIXEL_CALL_" + kvPass.Key.ToUpper(CultureInfo.InvariantCulture) + "}", callSG);
567568
}
568569
}
569570
}

0 commit comments

Comments
 (0)