Skip to content

Commit 44f497b

Browse files
ludovic-theobaldjulienf-unity
authored andcommitted
Fix 1290493 - Spaceship specific warnings (#176)
* Avoid implicit trucation in template + safe normalize setting * Update CHANGELOG.md * Added variants * Delete conditioning on GPU evaluation + conservative safe normalize Co-authored-by: Julien Fryer <[email protected]>
1 parent 8f3b4f9 commit 44f497b

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

com.unity.render-pipelines.high-definition/Editor/VFXGraph/Shaders/VFXLitVaryings.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ o.VFX_VARYING_METALLIC = metallic;
6767
#elif HDRP_MATERIAL_TYPE_SPECULAR
6868
#ifdef VFX_VARYING_SPECULAR
6969
${VFXLoadParameter:{specularColor}}
70-
o.VFX_VARYING_SPECULAR = specularColor;
70+
o.VFX_VARYING_SPECULAR = specularColor.rgb;
7171
#endif
7272
#elif HDRP_MATERIAL_TYPE_TRANSLUCENT
7373
#ifdef VFX_VARYING_THICKNESS
@@ -92,7 +92,7 @@ o.VFX_VARYING_EMISSIVESCALE = emissiveScale;
9292
o.VFX_VARYING_EMISSIVE = attributes.color;
9393
#elif HDRP_USE_ADDITIONAL_EMISSIVE_COLOR
9494
${VFXLoadParameter:{emissiveColor}}
95-
o.VFX_VARYING_EMISSIVE = emissiveColor;
95+
o.VFX_VARYING_EMISSIVE = emissiveColor.rgb;
9696
#endif
9797
#endif
9898
#if HDRP_USE_ADDITIONAL_BASE_COLOR

com.unity.visualeffectgraph/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1919
- Exclude Operator, Context, Block and Subgraph from Preset [Case 1232309](https://issuetracker.unity3d.com/product/unity/issues/guid/1232309/)
2020
- Fix [Case 1212002](https://fogbugz.unity3d.com/f/cases/1212002/)
2121
- Fix [Case 1223747](https://fogbugz.unity3d.com/f/cases/1223747/)
22+
- Fix [Case 1290493](https://fogbugz.unity3d.com/f/cases/1290493/#BugEvent.1072735759)
2223

2324
## [10.2.0] - 2020-10-19
2425
### Added

com.unity.visualeffectgraph/Editor/Models/Operators/Implementations/Normalize.cs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,44 @@
11
using System;
2+
using System.Collections.Generic;
23
using UnityEngine;
34

45
namespace UnityEditor.VFX.Operator
56
{
6-
[VFXInfo(category = "Math/Vector")]
7+
class SafeNormalizationVariantProvider : VariantProvider
8+
{
9+
protected override sealed Dictionary<string, object[]> variants
10+
{
11+
get
12+
{
13+
return new Dictionary<string, object[]>
14+
{
15+
{ "safeNormalize", new object[]{true, false} }
16+
};
17+
}
18+
}
19+
}
20+
21+
22+
[VFXInfo(category = "Math/Vector", variantProvider = typeof(SafeNormalizationVariantProvider))]
723
class Normalize : VFXOperatorNumericUniform
824
{
925
public class InputProperties
1026
{
1127
public Vector3 x = Vector3.one;
1228
}
1329

14-
protected override sealed string operatorName { get { return "Normalize"; } }
30+
[VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), SerializeField, Tooltip("Specifies if the operator should check if the vector to be normalized is a vero vector.")]
31+
bool safeNormalize = false;
32+
33+
34+
protected override sealed string operatorName { get {return safeNormalize ? "Safe Normalize" : "Normalize"; } }
1535

1636
protected override sealed VFXExpression[] BuildExpression(VFXExpression[] inputExpression)
1737
{
18-
return new[] { VFXOperatorUtility.Normalize(inputExpression[0]) };
38+
if(safeNormalize)
39+
return new[] { VFXOperatorUtility.SafeNormalize(inputExpression[0]) };
40+
else
41+
return new[] { VFXOperatorUtility.Normalize(inputExpression[0]) };
1942
}
2043

2144
protected override sealed ValidTypeRule typeFilter

com.unity.visualeffectgraph/Editor/Models/Operators/VFXOperatorUtility.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public static Dictionary<VFXValueType, VFXExpression> GenerateExpressionConstant
3333
public static readonly Dictionary<VFXValueType, VFXExpression> TauExpression = GenerateExpressionConstant(2.0f * Mathf.PI);
3434
public static readonly Dictionary<VFXValueType, VFXExpression> E_NapierConstantExpression = GenerateExpressionConstant(Mathf.Exp(1));
3535
public static readonly Dictionary<VFXValueType, VFXExpression> EpsilonExpression = GenerateExpressionConstant(1e-5f);
36+
public static readonly Dictionary<VFXValueType, VFXExpression> EpsilonSqrExpression = GenerateExpressionConstant(1e-10f);
37+
3638

3739
public enum Base
3840
{
@@ -269,7 +271,7 @@ static public VFXExpression Normalize(VFXExpression v)
269271
static public VFXExpression SafeNormalize(VFXExpression v)
270272
{
271273
var sqrDist = Dot(v, v);
272-
var condition = new VFXExpressionCondition(VFXValueType.Float, VFXCondition.Equal, VFXOperatorUtility.ZeroExpression[VFXValueType.Float], sqrDist);
274+
var condition = new VFXExpressionCondition(VFXValueType.Float, VFXCondition.Less, VFXOperatorUtility.EpsilonSqrExpression[VFXValueType.Float], sqrDist);
273275
return new VFXExpressionBranch(condition, VFXOperatorUtility.ZeroExpression[v.valueType], Normalize(v));
274276
}
275277

0 commit comments

Comments
 (0)