Skip to content
Draft
Show file tree
Hide file tree
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
26 changes: 17 additions & 9 deletions com.unity.toon-graphics-test/Editor/UTSGraphicsTestSetup.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using Tests;
using System.Linq;
using NUnit.Framework;
using Unity.ToonShader.GraphicsTest;

namespace UnityEditor.Rendering.Toon
{
Expand All @@ -13,7 +12,6 @@ public class UTSGraphicsTestSetup : EditorWindow
// https://docs.unity3d.com/ScriptReference/EditorBuildSettings-scenes.html
Vector2 m_scrollPos;
bool m_initialzed;
List<EditorBuildSettingsScene> m_SceneAssets = new List<EditorBuildSettingsScene>();
List<string> m_SceneNames = new List<string>();

string[] monobehavioursToDisable =
Expand Down Expand Up @@ -91,16 +89,21 @@ private void OnGUI()
EditorGUILayout.BeginHorizontal();
if ( GUILayout.Button("Set up scenes above.") )
{
UTSImageComparisonSO imageComparisonSO = AssetDatabase.LoadAssetAtPath<UTSImageComparisonSO>(IMAGE_COMPARISON_SO_PATH);
Assert.IsNotNull(imageComparisonSO);

for ( int sceneIndex = 0; sceneIndex < EditorBuildSettings.scenes.Length; sceneIndex++)
{
SetupScenes(sceneIndex);
SetupScenes(sceneIndex, imageComparisonSO);
}
}

EditorGUILayout.EndHorizontal();
}
}
void SetupScenes(int scneneIndex)

//----------------------------------------------------------------------------------------------------------------------
void SetupScenes(int scneneIndex, UTSImageComparisonSO imageComparisonSO)
{
var scene = EditorSceneManager.OpenScene(EditorBuildSettings.scenes[scneneIndex].path);
var cameras = GameObject.FindGameObjectsWithTag("MainCamera").Select(x => x.GetComponent<Camera>());
Expand All @@ -116,8 +119,9 @@ void SetupScenes(int scneneIndex)
{
settings = cameraList[0].gameObject.AddComponent<UTS_GraphicsTestSettings>();
}
settings.ImageComparisonSettings.ImageResolution = UnityEngine.TestTools.Graphics.ImageComparisonSettings.Resolution.w960h540;
settings.ImageComparisonSettings.PerPixelCorrectnessThreshold = 0.005f;

settings.SetUTSImageComparisonSO(imageComparisonSO);

settings.CheckMemoryAllocation = false;
settings.WaitFrames = 480;
foreach (GameObject obj in FindObjectsOfType(typeof(GameObject)))
Expand Down Expand Up @@ -158,5 +162,9 @@ void SetupScenes(int scneneIndex)

EditorSceneManager.SaveScene(scene);
}

//----------------------------------------------------------------------------------------------------------------------

private const string IMAGE_COMPARISON_SO_PATH = "Packages/com.unity.toon-graphics-test/Runtime/UTSGraphicsTestImageComparisonSettings.asset";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bce554fd33b2816478da44400f62aac4, type: 3}
m_Name: UTSGraphicsTestImageComparisonSettings
m_EditorClassIdentifier:
m_imageComparisonSettings:
TargetWidth: 960
TargetHeight: 540
TargetMSAASamples: 1
PerPixelCorrectnessThreshold: 0.005
PerPixelGammaThreshold: 0.003921569
PerPixelAlphaThreshold: 0.003921569
RMSEThreshold: 0
AverageCorrectnessThreshold: 0.005
IncorrectPixelsThreshold: 0.0000038146973
UseHDR: 0
UseBackBuffer: 0
ImageResolution: 3
ActiveImageTests: 1
ActivePixelTests: -1

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

24 changes: 24 additions & 0 deletions com.unity.toon-graphics-test/Runtime/UTSImageComparisonSO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using UnityEngine;
using UnityEngine.TestTools.Graphics;

namespace Unity.ToonShader.GraphicsTest {

[Serializable]
[CreateAssetMenu(menuName = "Unity Toon Shader/UTS Image Comparison Settings")]
public class UTSImageComparisonSO : ScriptableObject {
[SerializeField] private ImageComparisonSettings m_imageComparisonSettings = new ImageComparisonSettings() {
TargetWidth = 960,
TargetHeight = 540,
PerPixelCorrectnessThreshold = 0.001f,
AverageCorrectnessThreshold = 0.005f,
UseHDR = false,
UseBackBuffer = false,
ImageResolution = ImageComparisonSettings.Resolution.w1920h1080,
};

public ImageComparisonSettings GetImageComparisonSettings() => m_imageComparisonSettings;
}


}

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

26 changes: 14 additions & 12 deletions com.unity.toon-graphics-test/Runtime/UTS_GraphicsTestSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using UnityEngine.TestTools.Graphics;
using UnityEngine;
using UnityEngine.TestTools.Graphics;

namespace Tests
{
public class UTS_GraphicsTestSettings : GraphicsTestSettings
namespace Unity.ToonShader.GraphicsTest {
public class UTS_GraphicsTestSettings : MonoBehaviour
{
public int WaitFrames = 0;
public bool XRCompatible = true;
Expand All @@ -11,15 +11,17 @@ public class UTS_GraphicsTestSettings : GraphicsTestSettings
#else
public bool CheckMemoryAllocation = true;
#endif //#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX

[SerializeField]
private UTSImageComparisonSO m_imageComparisonSO;

public ImageComparisonSettings FindImageComparisonSettings() {
return m_imageComparisonSO != null ? m_imageComparisonSO.GetImageComparisonSettings() : null;
}

public UTS_GraphicsTestSettings()
{
ImageComparisonSettings.TargetWidth = 960;
ImageComparisonSettings.TargetHeight = 540;
ImageComparisonSettings.AverageCorrectnessThreshold = 0.005f;
ImageComparisonSettings.PerPixelCorrectnessThreshold = 0.001f;
ImageComparisonSettings.UseHDR = false;
ImageComparisonSettings.UseBackBuffer = false;
public void SetUTSImageComparisonSO(UTSImageComparisonSO so) {
m_imageComparisonSO = so;
}
}

}
12 changes: 6 additions & 6 deletions com.unity.toon-graphics-test/Runtime/UTS_GraphicsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using UnityEngine.XR;
using UnityEngine.TestTools.Graphics;
using UnityEditor.TestTools.Graphics;
using UnityEngine.SceneManagement;
using System.Collections.Generic;
using System.IO;
using Unity.ToonShader.GraphicsTest;

namespace Tests
{
Expand Down Expand Up @@ -70,8 +68,10 @@ public IEnumerator Run(GraphicsTestCase testCase)
}

int waitFrames = settings.WaitFrames;
ImageComparisonSettings imageComparisonSettings = settings.FindImageComparisonSettings();
Assert.IsNotNull(imageComparisonSettings);

if (settings.ImageComparisonSettings.UseBackBuffer && settings.WaitFrames < 1)
if (imageComparisonSettings.UseBackBuffer && settings.WaitFrames < 1)
{
waitFrames = 1;
}
Expand All @@ -80,7 +80,7 @@ public IEnumerator Run(GraphicsTestCase testCase)
for (int i = 0; i < waitFrames; i++)
yield return new WaitForEndOfFrame();

ImageAssert.AreEqual(testCase.ReferenceImage, cameras.Where(x => x != null), settings.ImageComparisonSettings);
ImageAssert.AreEqual(testCase.ReferenceImage, cameras.Where(x => x != null), imageComparisonSettings);

// Does it allocate memory when it renders what's on the main camera?
bool allocatesMemory = false;
Expand All @@ -90,7 +90,7 @@ public IEnumerator Run(GraphicsTestCase testCase)
{
try
{
ImageAssert.AllocatesMemory(mainCamera, settings.ImageComparisonSettings);
ImageAssert.AllocatesMemory(mainCamera, imageComparisonSettings);
}
catch (AssertionException)
{
Expand Down