diff --git a/com.unity.toon-graphics-test/Editor/UTSGraphicsTestSetup.cs b/com.unity.toon-graphics-test/Editor/UTSGraphicsTestSetup.cs index 03c7735ad..6d0e5fc24 100644 --- a/com.unity.toon-graphics-test/Editor/UTSGraphicsTestSetup.cs +++ b/com.unity.toon-graphics-test/Editor/UTSGraphicsTestSetup.cs @@ -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 { @@ -13,7 +12,6 @@ public class UTSGraphicsTestSetup : EditorWindow // https://docs.unity3d.com/ScriptReference/EditorBuildSettings-scenes.html Vector2 m_scrollPos; bool m_initialzed; - List m_SceneAssets = new List(); List m_SceneNames = new List(); string[] monobehavioursToDisable = @@ -91,16 +89,21 @@ private void OnGUI() EditorGUILayout.BeginHorizontal(); if ( GUILayout.Button("Set up scenes above.") ) { + UTSImageComparisonSO imageComparisonSO = AssetDatabase.LoadAssetAtPath(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()); @@ -116,8 +119,9 @@ void SetupScenes(int scneneIndex) { settings = cameraList[0].gameObject.AddComponent(); } - 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))) @@ -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"; } } \ No newline at end of file diff --git a/com.unity.toon-graphics-test/Runtime/UTSGraphicsTestImageComparisonSettings.asset b/com.unity.toon-graphics-test/Runtime/UTSGraphicsTestImageComparisonSettings.asset new file mode 100644 index 000000000..2bada96df --- /dev/null +++ b/com.unity.toon-graphics-test/Runtime/UTSGraphicsTestImageComparisonSettings.asset @@ -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 diff --git a/com.unity.toon-graphics-test/Runtime/UTSGraphicsTestImageComparisonSettings.asset.meta b/com.unity.toon-graphics-test/Runtime/UTSGraphicsTestImageComparisonSettings.asset.meta new file mode 100644 index 000000000..ae8a6c22c --- /dev/null +++ b/com.unity.toon-graphics-test/Runtime/UTSGraphicsTestImageComparisonSettings.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 091299cdcbab2584688189a8c745da73 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.toon-graphics-test/Runtime/UTSImageComparisonSO.cs b/com.unity.toon-graphics-test/Runtime/UTSImageComparisonSO.cs new file mode 100644 index 000000000..9b06ef415 --- /dev/null +++ b/com.unity.toon-graphics-test/Runtime/UTSImageComparisonSO.cs @@ -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; +} + + +} \ No newline at end of file diff --git a/com.unity.toon-graphics-test/Runtime/UTSImageComparisonSO.cs.meta b/com.unity.toon-graphics-test/Runtime/UTSImageComparisonSO.cs.meta new file mode 100644 index 000000000..95fe730e2 --- /dev/null +++ b/com.unity.toon-graphics-test/Runtime/UTSImageComparisonSO.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: bce554fd33b2816478da44400f62aac4 \ No newline at end of file diff --git a/com.unity.toon-graphics-test/Runtime/UTS_GraphicsTestSettings.cs b/com.unity.toon-graphics-test/Runtime/UTS_GraphicsTestSettings.cs index cad041fb3..dd43c50d5 100644 --- a/com.unity.toon-graphics-test/Runtime/UTS_GraphicsTestSettings.cs +++ b/com.unity.toon-graphics-test/Runtime/UTS_GraphicsTestSettings.cs @@ -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; @@ -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; } } + } \ No newline at end of file diff --git a/com.unity.toon-graphics-test/Runtime/UTS_GraphicsTests.cs b/com.unity.toon-graphics-test/Runtime/UTS_GraphicsTests.cs index 1e3193160..5036697f9 100644 --- a/com.unity.toon-graphics-test/Runtime/UTS_GraphicsTests.cs +++ b/com.unity.toon-graphics-test/Runtime/UTS_GraphicsTests.cs @@ -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 { @@ -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; } @@ -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; @@ -90,7 +90,7 @@ public IEnumerator Run(GraphicsTestCase testCase) { try { - ImageAssert.AllocatesMemory(mainCamera, settings.ImageComparisonSettings); + ImageAssert.AllocatesMemory(mainCamera, imageComparisonSettings); } catch (AssertionException) {