testss
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"createSeparatePackage": false
|
||||
}
|
@@ -0,0 +1,178 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using UnityEditor.Rendering.Universal.Internal;
|
||||
using UnityEngine.Experimental.Rendering.Universal;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
class EditorTests
|
||||
{
|
||||
// When creating a new render pipeline asset it should not log any errors or throw exceptions.
|
||||
[Test]
|
||||
public void CreatePipelineAssetWithoutErrors()
|
||||
{
|
||||
// Test without any render pipeline assigned to GraphicsSettings.
|
||||
var renderPipelineAsset = GraphicsSettings.renderPipelineAsset;
|
||||
GraphicsSettings.renderPipelineAsset = null;
|
||||
|
||||
try
|
||||
{
|
||||
ForwardRendererData data = ScriptableObject.CreateInstance<ForwardRendererData>();
|
||||
UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
ScriptableObject.DestroyImmediate(asset);
|
||||
ScriptableObject.DestroyImmediate(data);
|
||||
}
|
||||
// Makes sure the render pipeline is restored in case of a NullReference exception.
|
||||
finally
|
||||
{
|
||||
GraphicsSettings.renderPipelineAsset = renderPipelineAsset;
|
||||
}
|
||||
}
|
||||
|
||||
// When creating a new forward renderer asset it should not log any errors or throw exceptions.
|
||||
[Test]
|
||||
public void CreateForwardRendererAssetWithoutErrors()
|
||||
{
|
||||
// Test without any render pipeline assigned to GraphicsSettings.
|
||||
var renderPipelineAsset = GraphicsSettings.renderPipelineAsset;
|
||||
GraphicsSettings.renderPipelineAsset = null;
|
||||
|
||||
try
|
||||
{
|
||||
var asset = ScriptableObject.CreateInstance<ForwardRendererData>();
|
||||
ResourceReloader.ReloadAllNullIn(asset, UniversalRenderPipelineAsset.packagePath);
|
||||
var renderer = asset.InternalCreateRenderer();
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
renderer.Dispose();
|
||||
ScriptableObject.DestroyImmediate(asset);
|
||||
}
|
||||
// Makes sure the render pipeline is restored in case of a NullReference exception.
|
||||
finally
|
||||
{
|
||||
GraphicsSettings.renderPipelineAsset = renderPipelineAsset;
|
||||
}
|
||||
}
|
||||
|
||||
// When creating a new renderer 2d asset it should not log any errors or throw exceptions.
|
||||
[Test]
|
||||
public void CreateRenderer2DAssetWithoutErrors()
|
||||
{
|
||||
// Test without any render pipeline assigned to GraphicsSettings.
|
||||
var renderPipelineAsset = GraphicsSettings.renderPipelineAsset;
|
||||
GraphicsSettings.renderPipelineAsset = null;
|
||||
|
||||
try
|
||||
{
|
||||
var asset = ScriptableObject.CreateInstance<Renderer2DData>();
|
||||
ResourceReloader.ReloadAllNullIn(asset, UniversalRenderPipelineAsset.packagePath);
|
||||
var renderer = asset.InternalCreateRenderer();
|
||||
LogAssert.NoUnexpectedReceived();
|
||||
renderer.Dispose();
|
||||
ScriptableObject.DestroyImmediate(asset);
|
||||
}
|
||||
// Makes sure the render pipeline is restored in case of a NullReference exception.
|
||||
finally
|
||||
{
|
||||
GraphicsSettings.renderPipelineAsset = renderPipelineAsset;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate that resource Guids are valid
|
||||
[Test]
|
||||
public void ValidateBuiltinResourceFiles()
|
||||
{
|
||||
string templatePath = AssetDatabase.GUIDToAssetPath(ResourceGuid.rendererTemplate);
|
||||
Assert.IsFalse(string.IsNullOrEmpty(templatePath));
|
||||
|
||||
string editorResourcesPath = AssetDatabase.GUIDToAssetPath(UniversalRenderPipelineAsset.editorResourcesGUID);
|
||||
Assert.IsFalse(string.IsNullOrEmpty(editorResourcesPath));
|
||||
}
|
||||
|
||||
// Validate that ShaderUtils.GetShaderGUID results are valid and that ShaderUtils.GetShaderPath match shader names.
|
||||
[TestCase(ShaderPathID.Lit)]
|
||||
[TestCase(ShaderPathID.SimpleLit)]
|
||||
[TestCase(ShaderPathID.Unlit)]
|
||||
[TestCase(ShaderPathID.TerrainLit)]
|
||||
[TestCase(ShaderPathID.ParticlesLit)]
|
||||
[TestCase(ShaderPathID.ParticlesSimpleLit)]
|
||||
[TestCase(ShaderPathID.ParticlesUnlit)]
|
||||
[TestCase(ShaderPathID.BakedLit)]
|
||||
[TestCase(ShaderPathID.SpeedTree7)]
|
||||
[TestCase(ShaderPathID.SpeedTree7Billboard)]
|
||||
[TestCase(ShaderPathID.SpeedTree8)]
|
||||
public void ValidateShaderResources(ShaderPathID shaderPathID)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(shaderPathID));
|
||||
Assert.IsFalse(string.IsNullOrEmpty(path));
|
||||
|
||||
var shader = AssetDatabase.LoadAssetAtPath<Shader>(path);
|
||||
Assert.AreEqual(shader.name, ShaderUtils.GetShaderPath(shaderPathID));
|
||||
}
|
||||
|
||||
// When creating URP all required resources should be initialized.
|
||||
[Test]
|
||||
public void ValidateNewAssetResources()
|
||||
{
|
||||
ForwardRendererData data = ScriptableObject.CreateInstance<ForwardRendererData>();
|
||||
UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);
|
||||
Assert.AreNotEqual(null, asset.defaultMaterial);
|
||||
Assert.AreNotEqual(null, asset.defaultParticleMaterial);
|
||||
Assert.AreNotEqual(null, asset.defaultLineMaterial);
|
||||
Assert.AreNotEqual(null, asset.defaultTerrainMaterial);
|
||||
Assert.AreNotEqual(null, asset.defaultShader);
|
||||
|
||||
// URP doesn't override the following materials
|
||||
Assert.AreEqual(null, asset.defaultUIMaterial);
|
||||
Assert.AreEqual(null, asset.defaultUIOverdrawMaterial);
|
||||
Assert.AreEqual(null, asset.defaultUIETC1SupportedMaterial);
|
||||
Assert.AreEqual(null, asset.default2DMaterial);
|
||||
|
||||
Assert.AreNotEqual(null, asset.m_EditorResourcesAsset, "Editor Resources should be initialized when creating a new pipeline.");
|
||||
Assert.AreNotEqual(null, asset.m_RendererDataList, "A default renderer data should be created when creating a new pipeline.");
|
||||
ScriptableObject.DestroyImmediate(asset);
|
||||
ScriptableObject.DestroyImmediate(data);
|
||||
}
|
||||
|
||||
// When changing URP settings, all settings should be valid.
|
||||
[Test]
|
||||
public void ValidateAssetSettings()
|
||||
{
|
||||
// Create a new asset and validate invalid settings
|
||||
ForwardRendererData data = ScriptableObject.CreateInstance<ForwardRendererData>();
|
||||
UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);
|
||||
if (asset != null)
|
||||
{
|
||||
asset.shadowDistance = -1.0f;
|
||||
Assert.GreaterOrEqual(asset.shadowDistance, 0.0f);
|
||||
|
||||
asset.renderScale = -1.0f;
|
||||
Assert.GreaterOrEqual(asset.renderScale, UniversalRenderPipeline.minRenderScale);
|
||||
|
||||
asset.renderScale = 32.0f;
|
||||
Assert.LessOrEqual(asset.renderScale, UniversalRenderPipeline.maxRenderScale);
|
||||
|
||||
asset.shadowNormalBias = -1.0f;
|
||||
Assert.GreaterOrEqual(asset.shadowNormalBias, 0.0f);
|
||||
|
||||
asset.shadowNormalBias = 32.0f;
|
||||
Assert.LessOrEqual(asset.shadowNormalBias, UniversalRenderPipeline.maxShadowBias);
|
||||
|
||||
asset.shadowDepthBias = -1.0f;
|
||||
Assert.GreaterOrEqual(asset.shadowDepthBias, 0.0f);
|
||||
|
||||
asset.shadowDepthBias = 32.0f;
|
||||
Assert.LessOrEqual(asset.shadowDepthBias, UniversalRenderPipeline.maxShadowBias);
|
||||
|
||||
asset.maxAdditionalLightsCount = -1;
|
||||
Assert.GreaterOrEqual(asset.maxAdditionalLightsCount, 0);
|
||||
|
||||
asset.maxAdditionalLightsCount = 32;
|
||||
Assert.LessOrEqual(asset.maxAdditionalLightsCount, UniversalRenderPipeline.maxPerObjectLights);
|
||||
}
|
||||
ScriptableObject.DestroyImmediate(asset);
|
||||
ScriptableObject.DestroyImmediate(data);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "Unity.RenderPipelines.Universal.Editor.Tests",
|
||||
"references": [
|
||||
"GUID:15fc0a57446b3144c949da3e2b9737a9",
|
||||
"GUID:c579267770062bf448e75eb160330b7f",
|
||||
"GUID:df380645f10b7bc4b97d4f5eb6303d95",
|
||||
"GUID:27619889b8ba8c24980f49ee34dbb44a",
|
||||
"GUID:0acc523941302664db1f4e527237feb3"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": []
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.Experimental.Rendering.Universal;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
class MultipleObjectLight2DTests
|
||||
{
|
||||
GameObject m_TestObject1;
|
||||
GameObject m_TestObject2;
|
||||
GameObject m_TestObject3;
|
||||
GameObject m_TestObject4;
|
||||
GameObject m_TestObjectCached;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
m_TestObject1 = new GameObject("Test Object 1");
|
||||
m_TestObject2 = new GameObject("Test Object 2");
|
||||
m_TestObject3 = new GameObject("Test Object 3");
|
||||
m_TestObject4 = new GameObject("Test Object 4");
|
||||
m_TestObjectCached = new GameObject("Test Object Cached");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void Cleanup()
|
||||
{
|
||||
Object.DestroyImmediate(m_TestObjectCached);
|
||||
Object.DestroyImmediate(m_TestObject4);
|
||||
Object.DestroyImmediate(m_TestObject3);
|
||||
Object.DestroyImmediate(m_TestObject2);
|
||||
Object.DestroyImmediate(m_TestObject1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LightsAreSortedByLightOrder()
|
||||
{
|
||||
var light1 = m_TestObject1.AddComponent<Light2D>();
|
||||
var light2 = m_TestObject2.AddComponent<Light2D>();
|
||||
var light3 = m_TestObject3.AddComponent<Light2D>();
|
||||
|
||||
light1.lightOrder = 1;
|
||||
light2.lightOrder = 2;
|
||||
light3.lightOrder = 0;
|
||||
|
||||
var camera = m_TestObject4.AddComponent<Camera>();
|
||||
var cameraPos = camera.transform.position;
|
||||
light1.transform.position = cameraPos;
|
||||
light2.transform.position = cameraPos;
|
||||
light3.transform.position = cameraPos;
|
||||
|
||||
light1.UpdateMesh(true);
|
||||
light1.UpdateBoundingSphere();
|
||||
light2.UpdateMesh(true);
|
||||
light2.UpdateBoundingSphere();
|
||||
light3.UpdateMesh(true);
|
||||
light3.UpdateBoundingSphere();
|
||||
|
||||
var cullResult = new Light2DCullResult();
|
||||
var cullingParams = new ScriptableCullingParameters();
|
||||
camera.TryGetCullingParameters(out cullingParams);
|
||||
cullResult.SetupCulling(ref cullingParams, camera);
|
||||
|
||||
Assert.AreSame(light3, cullResult.visibleLights[0]);
|
||||
Assert.AreSame(light1, cullResult.visibleLights[1]);
|
||||
Assert.AreSame(light2, cullResult.visibleLights[2]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LightIsInVisibleListIfInCameraView()
|
||||
{
|
||||
var camera = m_TestObject1.AddComponent<Camera>();
|
||||
var light = m_TestObject2.AddComponent<Light2D>();
|
||||
light.transform.position = camera.transform.position;
|
||||
light.UpdateMesh(true);
|
||||
light.UpdateBoundingSphere();
|
||||
|
||||
var cullResult = new Light2DCullResult();
|
||||
var cullingParams = new ScriptableCullingParameters();
|
||||
camera.TryGetCullingParameters(out cullingParams);
|
||||
cullResult.SetupCulling(ref cullingParams, camera);
|
||||
|
||||
Assert.Contains(light, cullResult.visibleLights);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LightIsNotInVisibleListIfNotInCameraView()
|
||||
{
|
||||
var camera = m_TestObject1.AddComponent<Camera>();
|
||||
var light = m_TestObject2.AddComponent<Light2D>();
|
||||
light.transform.position = camera.transform.position + new Vector3(9999.0f, 0.0f, 0.0f);
|
||||
light.UpdateMesh(true);
|
||||
light.UpdateBoundingSphere();
|
||||
|
||||
var cullResult = new Light2DCullResult();
|
||||
var cullingParams = new ScriptableCullingParameters();
|
||||
camera.TryGetCullingParameters(out cullingParams);
|
||||
cullResult.SetupCulling(ref cullingParams, camera);
|
||||
|
||||
Assert.IsFalse(cullResult.visibleLights.Contains(light));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CachedMeshDataIsUpdatedOnChange()
|
||||
{
|
||||
var shapePath = new Vector3[4] { new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 1, 0), new Vector3(0, 1, 0) };
|
||||
var light = m_TestObjectCached.AddComponent<Light2D>();
|
||||
light.lightType = Light2D.LightType.Freeform;
|
||||
|
||||
light.SetShapePath(shapePath);
|
||||
light.UpdateMesh(true);
|
||||
|
||||
Assert.AreEqual(true, light.hasCachedMesh);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CachedMeshDataIsOverriddenByRuntimeChanges()
|
||||
{
|
||||
var shapePath = new Vector3[4] { new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 1, 0), new Vector3(0, 1, 0) };
|
||||
var light = m_TestObjectCached.AddComponent<Light2D>();
|
||||
light.lightType = Light2D.LightType.Freeform;
|
||||
light.SetShapePath(shapePath);
|
||||
light.UpdateMesh(true);
|
||||
|
||||
int vertexCount = 0, triangleCount = 0;
|
||||
|
||||
// Check if Cached Data and the actual data are the same.
|
||||
Assert.AreEqual(true, light.hasCachedMesh);
|
||||
vertexCount = light.lightMesh.triangles.Length;
|
||||
triangleCount = light.lightMesh.vertices.Length;
|
||||
|
||||
// Simulate Runtime Behavior.
|
||||
var shapePathChanged = new Vector3[5] { new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 1, 0), new Vector3(0.5f, 1.5f, 0), new Vector3(0, 1, 0) };
|
||||
light.SetShapePath(shapePathChanged);
|
||||
light.UpdateMesh(true);
|
||||
|
||||
// Check if Cached Data and the actual data are no longer the same. (We don't save cache on Runtime)
|
||||
Assert.AreNotEqual(vertexCount, light.lightMesh.triangles.Length);
|
||||
Assert.AreNotEqual(triangleCount, light.lightMesh.vertices.Length);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnsureShapeMeshGenerationDoesNotOverflowAllocation()
|
||||
{
|
||||
var shapePath = new Vector3[4] { new Vector3(-76.04548f, 7.522535f, 0f), new Vector3(-66.52518f, 18.88778f, 0f), new Vector3(-66.35441f, 24.34475f, 0), new Vector3(-75.15407f, 33.0358f, 0) };
|
||||
var light = m_TestObjectCached.AddComponent<Light2D>();
|
||||
light.lightType = Light2D.LightType.Freeform;
|
||||
LightUtility.GenerateShapeMesh(light, shapePath, 180.0f);
|
||||
|
||||
Assert.AreEqual(true, light.hasCachedMesh);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,326 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.Experimental.Rendering.Universal;
|
||||
|
||||
namespace UnityEngine.Rendering.Universal.Tests
|
||||
{
|
||||
internal class PixelPerfectCameraTests
|
||||
{
|
||||
internal class PixelPerfectCameraTestComponent : IPixelPerfectCamera
|
||||
{
|
||||
public int assetsPPU { get; set; }
|
||||
public int refResolutionX { get; set; }
|
||||
public int refResolutionY { get; set; }
|
||||
public bool upscaleRT { get; set; }
|
||||
public bool pixelSnapping { get; set; }
|
||||
public bool cropFrameX { get; set; }
|
||||
public bool cropFrameY { get; set; }
|
||||
public bool stretchFill { get; set; }
|
||||
}
|
||||
|
||||
internal class CalculateCameraPropertiesResult
|
||||
{
|
||||
public int zoom;
|
||||
public bool useOffscreenRT;
|
||||
public int offscreenRTWidth;
|
||||
public int offscreenRTHeight;
|
||||
public Rect pixelRect;
|
||||
public float orthoSize;
|
||||
public float unitsPerPixel;
|
||||
}
|
||||
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
private static object[] GetCalculateCameraPropertiesTestCases()
|
||||
{
|
||||
object[] testCaseArray = new object[9];
|
||||
|
||||
for (int i = 0; i < testCaseArray.Length; ++i)
|
||||
{
|
||||
PixelPerfectCameraTestComponent testComponent = new PixelPerfectCameraTestComponent();
|
||||
int screenWidth = 0;
|
||||
int screenHeight = 0;
|
||||
CalculateCameraPropertiesResult expected = new CalculateCameraPropertiesResult();
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
testComponent.assetsPPU = 100;
|
||||
testComponent.refResolutionX = 400;
|
||||
testComponent.refResolutionY = 300;
|
||||
testComponent.upscaleRT = false;
|
||||
testComponent.pixelSnapping = true;
|
||||
testComponent.cropFrameX = true;
|
||||
testComponent.cropFrameY = true;
|
||||
testComponent.stretchFill = true;
|
||||
screenWidth = 800;
|
||||
screenHeight = 500;
|
||||
|
||||
expected.zoom = 1;
|
||||
expected.useOffscreenRT = true;
|
||||
expected.offscreenRTWidth = 400;
|
||||
expected.offscreenRTHeight = 300;
|
||||
expected.pixelRect = new Rect(0.0f, 0.0f, 400, 300);
|
||||
expected.orthoSize = 1.5f;
|
||||
expected.unitsPerPixel = 0.01f;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
testComponent.assetsPPU = 100;
|
||||
testComponent.refResolutionX = 400;
|
||||
testComponent.refResolutionY = 300;
|
||||
testComponent.upscaleRT = true;
|
||||
testComponent.pixelSnapping = true;
|
||||
testComponent.cropFrameX = true;
|
||||
testComponent.cropFrameY = true;
|
||||
testComponent.stretchFill = true;
|
||||
screenWidth = 1100;
|
||||
screenHeight = 900;
|
||||
|
||||
expected.zoom = 2;
|
||||
expected.useOffscreenRT = true;
|
||||
expected.offscreenRTWidth = 400;
|
||||
expected.offscreenRTHeight = 300;
|
||||
expected.pixelRect = new Rect(0.0f, 0.0f, 400, 300);
|
||||
expected.orthoSize = 1.5f;
|
||||
expected.unitsPerPixel = 0.01f;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
testComponent.assetsPPU = 100;
|
||||
testComponent.refResolutionX = 400;
|
||||
testComponent.refResolutionY = 300;
|
||||
testComponent.upscaleRT = true;
|
||||
testComponent.pixelSnapping = true;
|
||||
testComponent.cropFrameX = false;
|
||||
testComponent.cropFrameY = true;
|
||||
testComponent.stretchFill = false;
|
||||
screenWidth = 400;
|
||||
screenHeight = 250;
|
||||
|
||||
expected.zoom = 1;
|
||||
expected.useOffscreenRT = true;
|
||||
expected.offscreenRTWidth = 400;
|
||||
expected.offscreenRTHeight = 300;
|
||||
expected.pixelRect = new Rect(0.0f, 0.0f, 400, 300);
|
||||
expected.orthoSize = 1.5f;
|
||||
expected.unitsPerPixel = 0.01f;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
testComponent.assetsPPU = 100;
|
||||
testComponent.refResolutionX = 400;
|
||||
testComponent.refResolutionY = 300;
|
||||
testComponent.upscaleRT = true;
|
||||
testComponent.pixelSnapping = true;
|
||||
testComponent.cropFrameX = true;
|
||||
testComponent.cropFrameY = false;
|
||||
testComponent.stretchFill = false;
|
||||
screenWidth = 1600;
|
||||
screenHeight = 1200;
|
||||
|
||||
expected.zoom = 4;
|
||||
expected.useOffscreenRT = true;
|
||||
expected.offscreenRTWidth = 400;
|
||||
expected.offscreenRTHeight = 300;
|
||||
expected.pixelRect = new Rect(0.0f, 0.0f, 400, 300);
|
||||
expected.orthoSize = 1.5f;
|
||||
expected.unitsPerPixel = 0.01f;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
testComponent.assetsPPU = 100;
|
||||
testComponent.refResolutionX = 400;
|
||||
testComponent.refResolutionY = 300;
|
||||
testComponent.upscaleRT = true;
|
||||
testComponent.pixelSnapping = true;
|
||||
testComponent.cropFrameX = false;
|
||||
testComponent.cropFrameY = false;
|
||||
testComponent.stretchFill = false;
|
||||
screenWidth = 1600;
|
||||
screenHeight = 1100;
|
||||
|
||||
expected.zoom = 3;
|
||||
expected.useOffscreenRT = true;
|
||||
expected.offscreenRTWidth = 532;
|
||||
expected.offscreenRTHeight = 366;
|
||||
expected.pixelRect = new Rect(0.0f, 0.0f, 532, 366);
|
||||
expected.orthoSize = 1.83f;
|
||||
expected.unitsPerPixel = 0.01f;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
testComponent.assetsPPU = 100;
|
||||
testComponent.refResolutionX = 400;
|
||||
testComponent.refResolutionY = 300;
|
||||
testComponent.upscaleRT = false;
|
||||
testComponent.pixelSnapping = false;
|
||||
testComponent.cropFrameX = false;
|
||||
testComponent.cropFrameY = false;
|
||||
testComponent.stretchFill = true;
|
||||
screenWidth = 800;
|
||||
screenHeight = 600;
|
||||
|
||||
expected.zoom = 2;
|
||||
expected.useOffscreenRT = false;
|
||||
expected.offscreenRTWidth = 0;
|
||||
expected.offscreenRTHeight = 0;
|
||||
expected.pixelRect = Rect.zero;
|
||||
expected.orthoSize = 1.5f;
|
||||
expected.unitsPerPixel = 0.005f;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
testComponent.assetsPPU = 100;
|
||||
testComponent.refResolutionX = 400;
|
||||
testComponent.refResolutionY = 300;
|
||||
testComponent.upscaleRT = false;
|
||||
testComponent.pixelSnapping = false;
|
||||
testComponent.cropFrameX = true;
|
||||
testComponent.cropFrameY = true;
|
||||
testComponent.stretchFill = false;
|
||||
screenWidth = 800;
|
||||
screenHeight = 700;
|
||||
|
||||
expected.zoom = 2;
|
||||
expected.useOffscreenRT = true;
|
||||
expected.offscreenRTWidth = 800;
|
||||
expected.offscreenRTHeight = 600;
|
||||
expected.pixelRect = new Rect(0.0f, 0.0f, 800, 600);
|
||||
expected.orthoSize = 1.5f;
|
||||
expected.unitsPerPixel = 0.005f;
|
||||
break;
|
||||
|
||||
case 7:
|
||||
testComponent.assetsPPU = 100;
|
||||
testComponent.refResolutionX = 400;
|
||||
testComponent.refResolutionY = 300;
|
||||
testComponent.upscaleRT = false;
|
||||
testComponent.pixelSnapping = true;
|
||||
testComponent.cropFrameX = false;
|
||||
testComponent.cropFrameY = true;
|
||||
testComponent.stretchFill = false;
|
||||
screenWidth = 900;
|
||||
screenHeight = 600;
|
||||
|
||||
expected.zoom = 2;
|
||||
expected.useOffscreenRT = true;
|
||||
expected.offscreenRTWidth = 900;
|
||||
expected.offscreenRTHeight = 600;
|
||||
expected.pixelRect = new Rect(0.0f, 0.0f, 900, 600);
|
||||
expected.orthoSize = 1.5f;
|
||||
expected.unitsPerPixel = 0.01f;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
testComponent.assetsPPU = 100;
|
||||
testComponent.refResolutionX = 400;
|
||||
testComponent.refResolutionY = 300;
|
||||
testComponent.upscaleRT = false;
|
||||
testComponent.pixelSnapping = true;
|
||||
testComponent.cropFrameX = true;
|
||||
testComponent.cropFrameY = false;
|
||||
testComponent.stretchFill = false;
|
||||
screenWidth = 900;
|
||||
screenHeight = 600;
|
||||
|
||||
expected.zoom = 2;
|
||||
expected.useOffscreenRT = true;
|
||||
expected.offscreenRTWidth = 800;
|
||||
expected.offscreenRTHeight = 600;
|
||||
expected.pixelRect = new Rect(0.0f, 0.0f, 800, 600);
|
||||
expected.orthoSize = 1.5f;
|
||||
expected.unitsPerPixel = 0.01f;
|
||||
break;
|
||||
}
|
||||
|
||||
testCaseArray[i] = new object[] { testComponent, screenWidth, screenHeight, expected };
|
||||
}
|
||||
|
||||
return testCaseArray;
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("GetCalculateCameraPropertiesTestCases")]
|
||||
public void CalculateCameraPropertiesProvidesCorrectResultsWithVariousInputs(PixelPerfectCameraTestComponent testComponent, int screenWidth, int screenHeight, CalculateCameraPropertiesResult expected)
|
||||
{
|
||||
PixelPerfectCameraInternal internals = new PixelPerfectCameraInternal(testComponent);
|
||||
internals.CalculateCameraProperties(screenWidth, screenHeight);
|
||||
|
||||
Assert.AreEqual(expected.zoom, internals.zoom);
|
||||
Assert.AreEqual(expected.useOffscreenRT, internals.useOffscreenRT);
|
||||
Assert.AreEqual(expected.offscreenRTWidth, internals.offscreenRTWidth);
|
||||
Assert.AreEqual(expected.offscreenRTHeight, internals.offscreenRTHeight);
|
||||
Assert.AreEqual(expected.pixelRect, internals.pixelRect);
|
||||
Assert.AreEqual(expected.orthoSize, internals.orthoSize);
|
||||
Assert.AreEqual(expected.unitsPerPixel, internals.unitsPerPixel);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateFinalBlitPixelRectStretchToFitHeightWorks()
|
||||
{
|
||||
PixelPerfectCameraTestComponent testComponent = new PixelPerfectCameraTestComponent();
|
||||
testComponent.refResolutionX = 200;
|
||||
testComponent.refResolutionY = 100;
|
||||
PixelPerfectCameraInternal internals = new PixelPerfectCameraInternal(testComponent);
|
||||
|
||||
internals.useStretchFill = true;
|
||||
Rect pixelRect = internals.CalculateFinalBlitPixelRect(400, 100);
|
||||
|
||||
Rect expected = new Rect(100.0f, 0.0f, 200.0f, 100.0f);
|
||||
Assert.AreEqual(expected, pixelRect);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateFinalBlitPixelRectStretchToFitWidthWorks()
|
||||
{
|
||||
PixelPerfectCameraTestComponent testComponent = new PixelPerfectCameraTestComponent();
|
||||
testComponent.refResolutionX = 200;
|
||||
testComponent.refResolutionY = 100;
|
||||
PixelPerfectCameraInternal internals = new PixelPerfectCameraInternal(testComponent);
|
||||
|
||||
internals.useStretchFill = true;
|
||||
Rect pixelRect = internals.CalculateFinalBlitPixelRect(200, 200);
|
||||
|
||||
Rect expected = new Rect(0.0f, 50.0f, 200.0f, 100.0f);
|
||||
Assert.AreEqual(expected, pixelRect);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateFinalBlitPixelRectCenteredWorksWithUpscaleRT()
|
||||
{
|
||||
PixelPerfectCameraTestComponent testComponent = new PixelPerfectCameraTestComponent();
|
||||
testComponent.upscaleRT = true;
|
||||
testComponent.refResolutionX = 400;
|
||||
testComponent.refResolutionY = 300;
|
||||
PixelPerfectCameraInternal internals = new PixelPerfectCameraInternal(testComponent);
|
||||
|
||||
internals.useStretchFill = false;
|
||||
internals.zoom = 2;
|
||||
internals.offscreenRTWidth = 400;
|
||||
internals.offscreenRTHeight = 300;
|
||||
|
||||
Rect pixelRect = internals.CalculateFinalBlitPixelRect(1600, 1200);
|
||||
|
||||
Rect expected = new Rect(400.0f, 300.0f, 800.0f, 600.0f);
|
||||
Assert.AreEqual(expected, pixelRect);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateFinalBlitPixelRectCenteredWorksWithoutUpscaleRT()
|
||||
{
|
||||
PixelPerfectCameraTestComponent testComponent = new PixelPerfectCameraTestComponent();
|
||||
testComponent.upscaleRT = false;
|
||||
testComponent.refResolutionX = 400;
|
||||
testComponent.refResolutionY = 300;
|
||||
PixelPerfectCameraInternal internals = new PixelPerfectCameraInternal(testComponent);
|
||||
|
||||
internals.useStretchFill = false;
|
||||
internals.zoom = 2;
|
||||
internals.offscreenRTWidth = 400;
|
||||
internals.offscreenRTHeight = 300;
|
||||
|
||||
Rect pixelRect = internals.CalculateFinalBlitPixelRect(1600, 1200);
|
||||
|
||||
Rect expected = new Rect(600.0f, 450.0f, 400.0f, 300.0f);
|
||||
Assert.AreEqual(expected, pixelRect);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
[TestFixture]
|
||||
class RuntimeTests
|
||||
{
|
||||
GameObject go;
|
||||
Camera camera;
|
||||
RenderPipelineAsset currentAsset;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
go = new GameObject();
|
||||
camera = go.AddComponent<Camera>();
|
||||
currentAsset = GraphicsSettings.renderPipelineAsset;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void Cleanup()
|
||||
{
|
||||
GraphicsSettings.renderPipelineAsset = currentAsset;
|
||||
Object.DestroyImmediate(go);
|
||||
}
|
||||
|
||||
// When LWRP pipeline is active, lightsUseLinearIntensity must match active color space.
|
||||
[UnityTest]
|
||||
public IEnumerator PipelineHasCorrectColorSpace()
|
||||
{
|
||||
AssetCheck();
|
||||
|
||||
camera.Render();
|
||||
yield return null;
|
||||
|
||||
Assert.AreEqual(QualitySettings.activeColorSpace == ColorSpace.Linear, GraphicsSettings.lightsUseLinearIntensity,
|
||||
"GraphicsSettings.lightsUseLinearIntensity must match active color space.");
|
||||
}
|
||||
|
||||
// When switching to LWRP it sets "UniversalPipeline" as global shader tag.
|
||||
// When switching to Built-in it sets "" as global shader tag.
|
||||
#if UNITY_EDITOR // TODO This API call does not reset in player
|
||||
[UnityTest]
|
||||
public IEnumerator PipelineSetsAndRestoreGlobalShaderTagCorrectly()
|
||||
{
|
||||
AssetCheck();
|
||||
|
||||
camera.Render();
|
||||
yield return null;
|
||||
|
||||
Assert.AreEqual("UniversalPipeline,LightweightPipeline", Shader.globalRenderPipeline, "Wrong render pipeline shader tag.");
|
||||
|
||||
GraphicsSettings.renderPipelineAsset = null;
|
||||
camera.Render();
|
||||
yield return null;
|
||||
|
||||
Assert.AreEqual("", Shader.globalRenderPipeline, "Render Pipeline shader tag is not restored.");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void AssetCheck()
|
||||
{
|
||||
//Assert.IsNotNull(currentAsset, "Render Pipeline Asset is Null");
|
||||
// Temp fix, test passes if project isnt setup for Universal RP
|
||||
if (currentAsset == null)
|
||||
Assert.Pass("Render Pipeline Asset is Null, test pass by default");
|
||||
|
||||
Assert.AreEqual(currentAsset.GetType(), typeof(UniversalRenderPipelineAsset),
|
||||
"Pipeline Asset is not Universal RP");
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "Unity.RenderPipelines.Universal.Runtime.Tests",
|
||||
"references": [
|
||||
"GUID:15fc0a57446b3144c949da3e2b9737a9",
|
||||
"GUID:27619889b8ba8c24980f49ee34dbb44a",
|
||||
"GUID:0acc523941302664db1f4e527237feb3"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": []
|
||||
}
|
Reference in New Issue
Block a user