Skip to content

Commit

Permalink
VFX staging to master (Unity-Technologies#6175)
Browse files Browse the repository at this point in the history
VFX Staging to master.

Code reformat + fixes

-Fix for nesting of VFXSubgraphContexts.
-Runtime compilation now compiles correctly when constant folding several texture ports that reference the same texture Case 1193602
-Fix compilation error in runtime mode when Speed Range is 0 in Attribute By Speed block Case 1118665
-NullReferenceException while assigning a null pCache Case 1222491
-Add message in inspector for unreachable properties due to VisualEffectAsset stored in AssetBundle Case 1193602
-pCache importer and exporter tool was keeping a lock on texture or pCache files Case 1185677
-Convert inline to exposed property / Quick expose property sets correct default value in parent
-Age particles checkbox was incorrectly hidden Case 1221557
-Fix various bugs in Position (Cone) block [Case 1111053] (https://issuetracker.unity3d.com/product/unity/issues/guid/1111053/)
-Handle correctly direction, position & vector types in AppendVector operator Case 1111867
-Fix space issues with blocks and operators taking a camera as input
-Generated shaderName are now consistent with displayed system names
  • Loading branch information
julienf-unity authored Mar 23, 2020
1 parent 241ce57 commit e408098
Show file tree
Hide file tree
Showing 390 changed files with 21,560 additions and 3,411 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ public void CleanUp()
VFXTestCommon.DeleteAllTemporaryGraph();
}


VFXGraph CreateGraph_And_System()
{
var graph = VFXTestCommon.MakeTemporaryGraph();
Expand All @@ -166,7 +165,7 @@ VFXGraph CreateGraph_And_System()
var spawner = ScriptableObject.CreateInstance<VFXBasicSpawner>();
spawner.LinkTo(contextInitialize);
graph.AddChild(spawner);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph)); ;
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(graph));;

return graph;
}
Expand All @@ -185,7 +184,7 @@ public IEnumerator CreateComponent_And_Graph_Restart_Component_Expected()

//Assert.DoesNotThrow(() => VisualEffectUtility.GetSpawnerState(vfxComponent, 0)); //N.B. : This cannot be tested after EnterPlayMode due to the closure
int maxFrame = 512;
while (VisualEffectUtility.GetSpawnerState(vfxComponent, 0).totalTime < 1.0f && maxFrame-->0)
while (VisualEffectUtility.GetSpawnerState(vfxComponent, 0).totalTime < 1.0f && maxFrame-- > 0)
yield return null;

Assert.GreaterOrEqual(VisualEffectUtility.GetSpawnerState(vfxComponent, 0).totalTime, 1.0f);
Expand All @@ -207,22 +206,24 @@ public IEnumerator CreateComponent_And_Graph_Restart_Component_Expected()
public IEnumerator CreateComponent_And_Graph_Modify_It_To_Generate_Expected_Exception()
{
var graph = CreateGraph_And_System();

yield return null;

while (m_mainObject.GetComponent<VisualEffect>() != null)
UnityEngine.Object.DestroyImmediate(m_mainObject.GetComponent<VisualEffect>());
var vfxComponent = m_mainObject.AddComponent<VisualEffect>();
vfxComponent.visualEffectAsset = graph.visualEffectResource.asset;
Assert.DoesNotThrow(() => VisualEffectUtility.GetSpawnerState(vfxComponent, 0));

yield return null;

//Plug a GPU instruction on bounds, excepting an exception while recompiling
var getPositionDesc = VFXLibrary.GetOperators().FirstOrDefault(o => o.modelType == typeof(VFXAttributeParameter) && o.name.Contains(VFXAttribute.Position.name));
var getPosition = getPositionDesc.CreateInstance();
graph.AddChild(getPosition);
var initializeContext = graph.children.OfType<VFXBasicInitialize>().FirstOrDefault();
Assert.AreEqual(VFXValueType.Float3, initializeContext.inputSlots[0][0].valueType);

getPosition.outputSlots[0].Link(initializeContext.inputSlots[0][0]);

//LogAssert.Expect(LogType.Error, new System.Text.RegularExpressions.Regex("Exception while compiling expression graph:*")); < Incorrect with our katana configuration
Expand Down Expand Up @@ -285,9 +286,9 @@ public IEnumerator CreateComponent_And_VerifyRenderBounds()
vfx.visualEffectAsset = asset;

int maxFrame = 512;
while (( vfx.culled
while ((vfx.culled
|| currentObject.GetComponent<VFXRenderer>().bounds.extents.x == 0.0f)
&& --maxFrame > 0)
&& --maxFrame > 0)
{
yield return null;
}
Expand Down Expand Up @@ -666,9 +667,9 @@ public IEnumerator Create_Component_With_All_Basic_Type_Exposed_Check_Exposed_AP
{
var graph = VFXTestCommon.MakeTemporaryGraph();
var types = Enum.GetValues(typeof(VFXValueType)).Cast<VFXValueType>()
.Where(e => e != VFXValueType.Spline
&& e != VFXValueType.Buffer //TODO : Remove this when Buffer as exposed property is possible
&& e != VFXValueType.None).ToArray();
.Where(e => e != VFXValueType.Spline
&& e != VFXValueType.Buffer //TODO : Remove this when Buffer as exposed property is possible
&& e != VFXValueType.None).ToArray();

foreach (var type in types)
{
Expand Down Expand Up @@ -1074,8 +1075,8 @@ public IEnumerator CreateComponentWithAllBasicTypeExposed([ValueSource("trueOrFa

var types = Enum.GetValues(typeof(VFXValueType)).Cast<VFXValueType>()
.Where(e => e != VFXValueType.Spline
&& e != VFXValueType.Buffer //TODO : Remove this when Buffer as exposed property is possible
&& e != VFXValueType.None).ToArray();
&& e != VFXValueType.Buffer //TODO : Remove this when Buffer as exposed property is possible
&& e != VFXValueType.None).ToArray();
foreach (var parameter in VFXLibrary.GetParameters())
{
var newInstance = parameter.CreateInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ public void UndoRedoChangeSpace()
Undo.PerformUndo(); //Should go back to local
Assert.AreEqual((inlineOperatorController.model as VFXInlineOperator).inputSlots[0].space, VFXCoordinateSpace.Local);
Assert.AreEqual((inlineOperatorController.model as VFXInlineOperator).inputSlots[0].GetSpaceTransformationType(), SpaceableType.Position);

}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public void FailingConvertTest([ValueSource("failingConversions")] Conversion co
LogAssert.Expect(LogType.Error, string.Format("Cannot cast from {0} to {1}", conversion.value.GetType(), conversion.targetType));
Assert.IsNull(VFXConverter.ConvertTo(conversion.value, conversion.targetType));
}

#endif

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public override string ToString()

private static CutBefore[] cutBeforeSource = new CutBefore[]
{
new CutBefore() { taskType = VFXTaskType.Spawner },
new CutBefore() { taskType = VFXTaskType.Initialize },
new CutBefore() { taskType = VFXTaskType.Update },
new CutBefore() { taskType = VFXTaskType.Output },
new CutBefore() { taskType = VFXTaskType.Spawner },
new CutBefore() { taskType = VFXTaskType.Initialize },
new CutBefore() { taskType = VFXTaskType.Update },
new CutBefore() { taskType = VFXTaskType.Output },
};
[UnityTest]
public IEnumerator CopyPast_Context_And_Relink([ValueSource("cutBeforeSource")] CutBefore cutBeforeEncapsultor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void CopyPasteSpacableOperator()
var inlineOperatorDesc = VFXLibrary.GetOperators().Where(t => t.modelType == typeof(VFXInlineOperator)).First();

var newOperator = m_ViewController.AddVFXOperator(new Vector2(100, 100), inlineOperatorDesc);
newOperator.SetSettingValue("m_Type",new SerializableType(typeof(DirectionType)));
newOperator.SetSettingValue("m_Type", new SerializableType(typeof(DirectionType)));

m_ViewController.ApplyChanges();
var operatorController = m_ViewController.allChildren.OfType<VFXOperatorController>().First();
Expand Down Expand Up @@ -432,7 +432,6 @@ public void PasteSystems()
// Assert all names are unique, and the expected number of elements was obtained
Assert.IsTrue(uniqueNames.Count() == spawnerCount + GPUSystemsCount, "Some systems have the same name or are null or empty.");
}

}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using UnityEngine;
using UnityEngine.VFX;

namespace UnityEditor.VFX
{
class VFXCustomSpawnerUpdateCounterTest : VFXSpawnerCallbacks
{
public class InputProperties
{
}

public static uint s_UpdateCount = 0u;
public static float s_LastDeltaTime = 0.0f;
public override void OnPlay(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
{
}

public override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
{
if (state.deltaTime != 0.0f)
{
s_UpdateCount++;
s_LastDeltaTime = state.deltaTime;
}
}

public override void OnStop(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
{
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
using System;
using NUnit.Framework;
using UnityEngine;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public IEnumerator CreateAsset_And_Check_Exception_On_Invalid_Graph()

yield return null;
}

#endif
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
using NUnit.Framework;
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
using NUnit.Framework;
using System;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ public void ProcessVanDerCorputSequence()
}
}


public struct Min_Max_Expression_Folding_TestCase
{
internal string name;
Expand All @@ -347,7 +346,7 @@ public override string ToString()
};

static private string[] k_Min_Max_Expression_Folding_TestCase_Names = Generate_Min_Max_Expression_Folding_TestCase().Select(o => o.name).ToArray();

static private IEnumerable<Min_Max_Expression_Folding_TestCase> Generate_Min_Max_Expression_Folding_TestCase()
{
var x = VFXBuiltInExpression.TotalTime;
Expand All @@ -370,7 +369,7 @@ static private IEnumerable<Min_Max_Expression_Folding_TestCase> Generate_Min_Max
yield return new Min_Max_Expression_Folding_TestCase() { name = "max(min(x, 0), 1)", expression = new VFXExpressionMax(new VFXExpressionMin(x, zero), one), saturateExpected = false };
yield return new Min_Max_Expression_Folding_TestCase() { name = "max(1, min(x, 0))", expression = new VFXExpressionMax(one, new VFXExpressionMin(x, zero)), saturateExpected = false };

//Exotic cases
//Exotic cases
yield return new Min_Max_Expression_Folding_TestCase() { name = "min(min(x, 1), 0)", expression = new VFXExpressionMin(new VFXExpressionMin(x, one), zero), saturateExpected = false };
yield return new Min_Max_Expression_Folding_TestCase() { name = "max(max(x, 1), 0)", expression = new VFXExpressionMax(new VFXExpressionMax(x, one), zero), saturateExpected = false };
yield return new Min_Max_Expression_Folding_TestCase() { name = "max(add(x, 1), 0)", expression = new VFXExpressionMax(new VFXExpressionAdd(x, one), zero), saturateExpected = false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace UnityEditor.VFX.Test
[TestFixture]
class VFXExpressionTests
{


[Test]
public void ProcessStoreValue()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
using NUnit.Framework;
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private VisualEffectAsset CreateTestAsset(string name)
}


return VisualEffectAssetEditorUtility.CreateNewAsset(filePath);
return VisualEffectAssetEditorUtility.CreateNewAsset(filePath);
}

private void EditTestAsset(int assetIndex)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
using System;
using NUnit.Framework;
using UnityEngine;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
using System;

namespace UnityEditor.VFX.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,29 @@ public void AppendOperator()
Assert.AreEqual(VFXValueType.Float4, append.outputSlots[0].GetExpression().valueType);
}

[Test]
public void AppendOperator_With_Direction()
{
var append = ScriptableObject.CreateInstance<Operator.AppendVector>();
append.SetOperandType(0, typeof(DirectionType));
append.SetOperandType(1, typeof(float));

append.inputSlots[0].value = new DirectionType() { direction = new Vector3(1.0f, 1.0f, 0) };
append.inputSlots[1].value = 3.0f;

var context = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation);
var outputValue = context.Compile(append.outputSlots[0].GetExpression());

var expressionValue = outputValue.Get<Vector4>();
//Direction expects a normalize
var expectedValue = new Vector4(1.0f / Mathf.Sqrt(2), 1.0f / Mathf.Sqrt(2), 0.0f, 3.0f);

Assert.AreEqual(expectedValue.x, expressionValue.x, 1e-5f);
Assert.AreEqual(expectedValue.y, expressionValue.y, 1e-5f);
Assert.AreEqual(expectedValue.z, expressionValue.z, 1e-5f);
Assert.AreEqual(expectedValue.w, expressionValue.w, 1e-5f);
}

[Test]
public void BranchOperator_With_Sphere()
{
Expand Down Expand Up @@ -335,7 +358,7 @@ public void BranchOperator_With_Transform()
branch.inputSlots[1].value = transformA;
branch.inputSlots[2].value = transformB;

Func<Transform, Transform, bool> fnCompareTransform = delegate (Transform aS, Transform bS)
Func<Transform, Transform, bool> fnCompareTransform = delegate(Transform aS, Transform bS)
{
//Only compare position => didn't modify something else above
if (aS.position.x != bS.position.x) return false;
Expand All @@ -344,7 +367,7 @@ public void BranchOperator_With_Transform()
return true;
};

Func<VFXSlot, Transform> fnSlotToTransform = delegate (VFXSlot slot)
Func<VFXSlot, Transform> fnSlotToTransform = delegate(VFXSlot slot)
{
var context = new VFXExpression.Context(VFXExpressionContextOption.CPUEvaluation);
var position = context.Compile(slot[0].GetExpression());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
#if !UNITY_EDITOR_OSX || MAC_FORCE_TESTS
using System;
using UnityEngine;

Expand Down
Loading

0 comments on commit e408098

Please sign in to comment.