Skip to content

Commit

Permalink
[VFX/SG] Fix missing ObjectToWorld using Transform (Unity-Technologie…
Browse files Browse the repository at this point in the history
…s#6475)

* Fix TransformNode usage in VFX

Missing World To Object matrix requirement

* *Update changelog

Only in VFX, I don't see other cases where this fix is applicable, maybe DOTS ?

* Better filtering of needed transform

Fix issue Unity-Technologies#6475 (comment)
Fix issue Unity-Technologies#6475 (comment)
  • Loading branch information
PaulDemeulenaere committed Dec 8, 2021
1 parent a574f41 commit 807e271
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.ShaderGraph.Internal;
Expand Down Expand Up @@ -138,10 +139,7 @@ public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapabilit

public NeededTransform[] RequiresTransform(ShaderStageCapability stageCapability)
{
return new[]
{
new NeededTransform(conversion.from.ToNeededCoordinateSpace(), conversion.to.ToNeededCoordinateSpace())
};
return spaceTransform.RequiresTransform.ToArray();
}

NeededCoordinateSpace IMayRequirePosition.RequiresPosition(ShaderStageCapability stageCapability)
Expand Down
18 changes: 18 additions & 0 deletions com.unity.shadergraph/Editor/Data/Util/SpaceTransformUtil.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// using System;
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Internal;

namespace UnityEditor.ShaderGraph
Expand Down Expand Up @@ -49,6 +50,9 @@ internal string NormalizeString()
public NeededCoordinateSpace RequiresPosition =>
((type == ConversionType.Position) && ((from == CoordinateSpace.Tangent) || (to == CoordinateSpace.Tangent)) && (from != to)) ?
NeededCoordinateSpace.World : NeededCoordinateSpace.None;

public IEnumerable<NeededTransform> RequiresTransform =>
SpaceTransformUtil.ComputeTransformRequirement(this);
};

static class SpaceTransformUtil
Expand Down Expand Up @@ -371,6 +375,20 @@ public static void AbsoluteWorldToWorld(SpaceTransform xform, string inputValue,
}
};

internal static IEnumerable<NeededTransform> ComputeTransformRequirement(SpaceTransform xform)
{
var func = k_TransformFunctions[(int)xform.from, (int)xform.to];
if (func == ViaWorld || func == ObjectToAbsoluteWorld)
{
yield return new NeededTransform(xform.from.ToNeededCoordinateSpace(), NeededCoordinateSpace.World);
yield return new NeededTransform(NeededCoordinateSpace.World, xform.to.ToNeededCoordinateSpace());
}
else
{
yield return new NeededTransform(xform.from.ToNeededCoordinateSpace(), xform.to.ToNeededCoordinateSpace());
}
}

public static void GenerateTransformCodeStatement(SpaceTransform xform, string inputValue, string outputVariable, ShaderStringBuilder sb)
{
var func = k_TransformFunctions[(int)xform.from, (int)xform.to];
Expand Down
1 change: 1 addition & 0 deletions com.unity.visualeffectgraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Editing the values in the graph did not impact the system in real-time after saving [Case 1371089](https://issuetracker.unity3d.com/product/unity/issues/guid/1371089/)
- Fixed null reference exception when opening another VFX and a debug mode is enabled [Case 1347420](https://issuetracker.unity3d.com/product/unity/issues/guid/1347420/)
- Creating a new VFX of the same name as an already opened VFX will reuse the existing window [Case 1382841](https://issuetracker.unity3d.com/product/unity/issues/guid/1382841/)
- Incorrect behavior of Tangent Space in ShaderGraph [Case 1363279](https://issuetracker.unity3d.com/product/unity/issues/guid/1363279/)

## [13.1.2] - 2021-11-05

Expand Down

0 comments on commit 807e271

Please sign in to comment.