Skip to content
This repository was archived by the owner on Nov 30, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 37 additions & 164 deletions Tests/Runtime/PostProcessingRuntimeTests.cs
Original file line number Diff line number Diff line change
@@ -1,80 +1,47 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.TestTools;
using UnityEngine.SceneManagement;

#if UNITY_EDITOR
using UnityEditor;
#endif

class PostProcessingTests : IPrebuildSetup
class PostProcessingTests
{
const float k_Epsilon = 1e-4f;

static List<string> s_Scenes;
[Test]
public void Profile_AddSettings()
{
var profile = NewProfile();

CommandBuffer m_DummyCmd;
var bloom = profile.AddSettings<Bloom>();
Assert.IsNotNull(bloom);

static PostProcessingTests()
{
s_Scenes = new List<string>
{
"Packages/com.unity.postprocessing/PostProcessing/Tests/Runtime/Scenes/0010_Volumes.unity",
"Packages/com.unity.postprocessing/PostProcessing/Tests/Runtime/Scenes/0011_Weight.unity",
"Packages/com.unity.postprocessing/PostProcessing/Tests/Runtime/Scenes/0012_Intersect.unity",
"Packages/com.unity.postprocessing/PostProcessing/Tests/Runtime/Scenes/0013_Priority.unity",
};
Destroy(profile);
}

public void Setup()
[Test]
public void Profile_HasSettings()
{
#if UNITY_EDITOR
Debug.Log("Adding scenes to build settings...");

var scenes = EditorBuildSettings.scenes.ToList();
var profile = NewProfile(typeof(Bloom));

for (int i = 0; i < s_Scenes.Count; i++)
{
if (!scenes.Exists(x => x.path == s_Scenes[i]))
scenes.Add(new EditorBuildSettingsScene(s_Scenes[i], true));
}
Assert.IsTrue(profile.HasSettings<Bloom>());
Assert.IsFalse(profile.HasSettings<ChromaticAberration>());

EditorBuildSettings.scenes = scenes.ToArray();
#endif
Destroy(profile);
}

[SetUp]
public void Init()
[Test]
public void Profile_GetSettings()
{
m_DummyCmd = new CommandBuffer();
}
var profile = NewProfile(typeof(Bloom));

[TearDown]
public void Cleanup()
{
m_DummyCmd.Release();
m_DummyCmd = null;
}
Assert.IsNotNull(profile.GetSetting<Bloom>());
Assert.IsNull(profile.GetSetting<ChromaticAberration>());

static PostProcessLayer GrabPostProcessLayer()
{
var layer = Object.FindObjectOfType<PostProcessLayer>();
Assert.IsNotNull(layer, "Couldn't find PostProcessLayer");
return layer;
Destroy(profile);
}

[Test]
public void SettingsManagement()
public void Profile_TryGetSettings()
{
var profile = ScriptableObject.CreateInstance<PostProcessProfile>();

var bloom = profile.AddSettings<Bloom>();
Assert.IsNotNull(bloom);
var profile = NewProfile(typeof(Bloom));

Bloom outBloom;
var exists = profile.TryGetSettings(out outBloom);
Expand All @@ -86,126 +53,32 @@ public void SettingsManagement()
Assert.IsFalse(exists);
Assert.IsNull(outChroma);

Assert.IsTrue(profile.HasSettings<Bloom>());
Assert.IsFalse(profile.HasSettings<ChromaticAberration>());

Assert.IsNotNull(profile.GetSetting<Bloom>());
Assert.IsNull(profile.GetSetting<ChromaticAberration>());

profile.RemoveSettings<Bloom>();
Assert.IsFalse(profile.HasSettings<Bloom>());

Object.DestroyImmediate(profile);
}

[UnityTest]
public IEnumerator GlobalVolumeSingleLayer()
{
SceneManager.LoadScene(s_Scenes[0]);

yield return null; // Skip a frame

var ppLayer = GrabPostProcessLayer();
ppLayer.volumeLayer = LayerMask.GetMask("Default");

yield return null; // Skip a frame

ppLayer.UpdateVolumeSystem(ppLayer.GetComponent<Camera>(), m_DummyCmd);

var vignette = ppLayer.GetSettings<Vignette>();
Assert.AreEqual(1f, vignette.intensity.value, k_Epsilon);
Assert.IsTrue(vignette.rounded.value);
}

[UnityTest]
public IEnumerator LocalVolumeMultiLayer()
{
SceneManager.LoadScene(s_Scenes[0]);

yield return null; // Skip a frame

var ppLayer = GrabPostProcessLayer();
ppLayer.volumeLayer = -1;

yield return null; // Skip a frame

ppLayer.UpdateVolumeSystem(ppLayer.GetComponent<Camera>(), m_DummyCmd);

var vignette = ppLayer.GetSettings<Vignette>();
Assert.AreEqual(Color.red, vignette.color.value);
Destroy(profile);
}

[UnityTest]
public IEnumerator LocalVolumeWeight()
{
SceneManager.LoadScene(s_Scenes[1]);

yield return null; // Skip a frame

var ppLayer = GrabPostProcessLayer();
ppLayer.volumeLayer = -1;

yield return null; // Skip a frame

ppLayer.UpdateVolumeSystem(ppLayer.GetComponent<Camera>(), m_DummyCmd);

var vignette = ppLayer.GetSettings<Vignette>();
Assert.AreEqual(0.5f, vignette.color.value.r, k_Epsilon);
}

[UnityTest]
public IEnumerator LocalVolumeIntersect()
[Test]
public void Profile_RemoveSettings()
{
SceneManager.LoadScene(s_Scenes[2]);

yield return null; // Skip a frame

var ppLayer = GrabPostProcessLayer();
ppLayer.volumeLayer = -1;
var profile = NewProfile(typeof(Bloom));

yield return null; // Skip a frame

ppLayer.UpdateVolumeSystem(ppLayer.GetComponent<Camera>(), m_DummyCmd);
profile.RemoveSettings<Bloom>();
Assert.IsFalse(profile.HasSettings<Bloom>());

var vignette = ppLayer.GetSettings<Vignette>();
Assert.AreEqual(0.75f, vignette.color.value.r, k_Epsilon);
Destroy(profile);
}

[UnityTest]
public IEnumerator GetHighestPriority()
static PostProcessProfile NewProfile(params Type[] types)
{
SceneManager.LoadScene(s_Scenes[3]);

yield return null; // Skip a frame

var ppLayer = GrabPostProcessLayer();
ppLayer.volumeLayer = -1;

yield return null; // Skip a frame
var profile = ScriptableObject.CreateInstance<PostProcessProfile>();

ppLayer.UpdateVolumeSystem(ppLayer.GetComponent<Camera>(), m_DummyCmd);
foreach (var t in types)
profile.AddSettings(t);

var volume = PostProcessManager.instance.GetHighestPriorityVolume(ppLayer);
Assert.IsNotNull(volume);
Assert.AreEqual(10000, volume.priority, k_Epsilon);
return profile;
}

[UnityTest]
public IEnumerator GetActiveVolumes()
static void Destroy(PostProcessProfile profile)
{
SceneManager.LoadScene(s_Scenes[3]);

yield return null; // Skip a frame

var ppLayer = GrabPostProcessLayer();
ppLayer.volumeLayer = -1;

yield return null; // Skip a frame

ppLayer.UpdateVolumeSystem(ppLayer.GetComponent<Camera>(), m_DummyCmd);

var results = new List<PostProcessVolume>();
PostProcessManager.instance.GetActiveVolumes(ppLayer, results, true, true);
Assert.AreEqual(3, results.Count, k_Epsilon);
UnityEngine.Object.DestroyImmediate(profile);
}
}