From d0e837a6864790fe436bc284f56ea5d7492e4516 Mon Sep 17 00:00:00 2001 From: Paul Demeulenaere Date: Wed, 8 Dec 2021 17:21:30 +0100 Subject: [PATCH] [VFX/SG] Fix missing ObjectToWorld using Transform (#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 https://github.com/Unity-Technologies/Graphics/pull/6475#discussion_r764483354 Fix issue https://github.com/Unity-Technologies/Graphics/pull/6475#discussion_r764647186 # Conflicts: # com.unity.visualeffectgraph/CHANGELOG.md --- .../Data/Nodes/Math/Vector/TransformNode.cs | 6 ++---- .../Editor/Data/Util/SpaceTransformUtil.cs | 18 ++++++++++++++++++ com.unity.visualeffectgraph/CHANGELOG.md | 6 ++---- 3 files changed, 22 insertions(+), 8 deletions(-) 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 88c5728cc1c..7f4fb345118 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,5 @@ using System; +using System.Linq; using UnityEditor.Graphing; using UnityEditor.ShaderGraph.Drawing.Controls; using UnityEditor.ShaderGraph.Internal; @@ -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) diff --git a/com.unity.shadergraph/Editor/Data/Util/SpaceTransformUtil.cs b/com.unity.shadergraph/Editor/Data/Util/SpaceTransformUtil.cs index 05f7751b6aa..67a8c23493c 100644 --- a/com.unity.shadergraph/Editor/Data/Util/SpaceTransformUtil.cs +++ b/com.unity.shadergraph/Editor/Data/Util/SpaceTransformUtil.cs @@ -1,4 +1,5 @@ // using System; +using System.Collections.Generic; using UnityEditor.ShaderGraph.Internal; namespace UnityEditor.ShaderGraph @@ -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 RequiresTransform => + SpaceTransformUtil.ComputeTransformRequirement(this); }; static class SpaceTransformUtil @@ -371,6 +375,20 @@ public static void AbsoluteWorldToWorld(SpaceTransform xform, string inputValue, } }; + internal static IEnumerable 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]; diff --git a/com.unity.visualeffectgraph/CHANGELOG.md b/com.unity.visualeffectgraph/CHANGELOG.md index e9d5c2c83d4..1b4669b581b 100644 --- a/com.unity.visualeffectgraph/CHANGELOG.md +++ b/com.unity.visualeffectgraph/CHANGELOG.md @@ -5,12 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [13.1.4] - 2021-12-04 - -Version Updated -The version number for this package has increased due to a version update of a related graphics package. +### Fixed +- Incorrect behavior of Tangent Space in ShaderGraph [Case 1363279](https://issuetracker.unity3d.com/product/unity/issues/guid/1363279/) ## [13.1.3] - 2021-11-17 - ### Fixed - Gradient field doesn't support HDR values [Case 1381867](https://issuetracker.unity3d.com/product/unity/issues/guid/1381867/)