diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Math/Vector/TransformNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/Math/Vector/TransformNode.cs index f038fc041b2..930b798fb9e 100644 --- a/com.unity.shadergraph/Editor/Data/Nodes/Math/Vector/TransformNode.cs +++ b/com.unity.shadergraph/Editor/Data/Nodes/Math/Vector/TransformNode.cs @@ -1,4 +1,6 @@ using System; +using System.Linq; +using System.Collections.Generic; using UnityEditor.Graphing; using UnityEditor.ShaderGraph.Drawing.Controls; using UnityEditor.ShaderGraph.Internal; @@ -294,12 +296,62 @@ public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapabilit return conversion.from.ToNeededCoordinateSpace(); } - public NeededTransform[] RequiresTransform(ShaderStageCapability stageCapability) + static readonly bool[,] k_ViaWorldFunction = new bool[5, 5] // [from, to] + { + { // from CoordinateSpace.Object + false, // to CoordinateSpace.Object + true, // to CoordinateSpace.View + false, // to CoordinateSpace.World + true, // to CoordinateSpace.Tangent + true, // to CoordinateSpace.AbsoluteWorld + }, + { // from CoordinateSpace.View + true, // to CoordinateSpace.Object + false, // to CoordinateSpace.View + false, // to CoordinateSpace.World + true, // to CoordinateSpace.Tangent + true, // to CoordinateSpace.AbsoluteWorld + }, + { // from CoordinateSpace.World + false, // to CoordinateSpace.Object + false, // to CoordinateSpace.View + false, // to CoordinateSpace.World + false, // to CoordinateSpace.Tangent + false, // to CoordinateSpace.AbsoluteWorld + }, + { // from CoordinateSpace.Tangent + true, // to CoordinateSpace.Object + true, // to CoordinateSpace.View + false, // to CoordinateSpace.World + false, // to CoordinateSpace.Tangent + true, // to CoordinateSpace.AbsoluteWorld + }, + { // from CoordinateSpace.AbsoluteWorld + true, // to CoordinateSpace.Object + true, // to CoordinateSpace.View + false, // to CoordinateSpace.World + true, // to CoordinateSpace.Tangent + false, // to CoordinateSpace.AbsoluteWorld + } + }; + + internal static IEnumerable ComputeTransformRequirement(CoordinateSpaceConversion xform) { - return new[] + var viaWorld = k_ViaWorldFunction[(int)xform.from, (int)xform.to]; + if (viaWorld) + { + yield return new NeededTransform(xform.from.ToNeededCoordinateSpace(), NeededCoordinateSpace.World); + yield return new NeededTransform(NeededCoordinateSpace.World, xform.to.ToNeededCoordinateSpace()); + } + else { - new NeededTransform(conversion.from.ToNeededCoordinateSpace(), conversion.to.ToNeededCoordinateSpace()) - }; + yield return new NeededTransform(xform.from.ToNeededCoordinateSpace(), xform.to.ToNeededCoordinateSpace()); + } + } + + public NeededTransform[] RequiresTransform(ShaderStageCapability stageCapability) + { + return ComputeTransformRequirement(conversion).ToArray(); } } } diff --git a/com.unity.visualeffectgraph/CHANGELOG.md b/com.unity.visualeffectgraph/CHANGELOG.md index b37e157ec05..a8364f6fec2 100644 --- a/com.unity.visualeffectgraph/CHANGELOG.md +++ b/com.unity.visualeffectgraph/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Automatically offset contexts when a new node is inserted to avoid overlapping - 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/) +- Incorrect behavior of Tangent Space in ShaderGraph [Case 1363279](https://issuetracker.unity3d.com/product/unity/issues/guid/1363279/) ## [12.1.2] - 2021-10-22 ### Fixed