Nessuna descrizione
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XRGraphicsAutomatedTests.cs 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine.Experimental.Rendering;
  4. namespace UnityEngine.Rendering
  5. {
  6. /// <summary>
  7. /// Utility class to connect SRP to automated test framework.
  8. /// </summary>
  9. public static class XRGraphicsAutomatedTests
  10. {
  11. // XR tests can be enabled from the command line. Cache result to avoid GC.
  12. static bool activatedFromCommandLine
  13. {
  14. #if UNITY_EDITOR
  15. get => Array.Exists(Environment.GetCommandLineArgs(), arg => arg == "-xr-reuse-tests");
  16. #elif XR_REUSE_TESTS_STANDALONE
  17. get => true;
  18. #else
  19. get => false;
  20. #endif
  21. }
  22. /// <summary>
  23. /// Used by render pipelines to initialize XR tests.
  24. /// </summary>
  25. public static bool enabled { get; } = activatedFromCommandLine;
  26. /// <summary>
  27. /// Set by automated test framework and read by render pipelines.
  28. /// </summary>
  29. public static bool running = false;
  30. // Helper function to override the XR default layout using settings of new camera
  31. internal static void OverrideLayout(XRLayout layout, Camera camera)
  32. {
  33. #if ENABLE_VR && ENABLE_XR_MODULE
  34. if (enabled && running)
  35. {
  36. var camProjMatrix = camera.projectionMatrix;
  37. var camViewMatrix = camera.worldToCameraMatrix;
  38. if (camera.TryGetCullingParameters(false, out var cullingParams))
  39. {
  40. cullingParams.stereoProjectionMatrix = camProjMatrix;
  41. cullingParams.stereoViewMatrix = camViewMatrix;
  42. cullingParams.stereoSeparationDistance = 0.0f;
  43. List<(Camera, XRPass)> xrPasses = layout.GetActivePasses();
  44. for (int passId = 0; passId < xrPasses.Count; passId++)
  45. {
  46. var xrPass = xrPasses[passId].Item2;
  47. xrPass.AssignCullingParams(xrPass.cullingPassId, cullingParams);
  48. for (int viewId = 0; viewId < xrPass.viewCount; viewId++)
  49. {
  50. var projMatrix = camProjMatrix;
  51. var viewMatrix = camViewMatrix;
  52. bool isFirstViewMultiPass = xrPasses.Count == 2 && passId == 0;
  53. bool isFirstViewSinglePass = xrPasses.Count == 1 && viewId == 0;
  54. if (isFirstViewMultiPass || isFirstViewSinglePass)
  55. {
  56. // Modify the render viewpoint and frustum of the first view in order to
  57. // distinguish it from the final view used for image comparison.
  58. // This is a trick to help detect issues related to view indexing.
  59. var planes = projMatrix.decomposeProjection;
  60. planes.left *= 0.44f;
  61. planes.right *= 0.88f;
  62. planes.top *= 0.11f;
  63. planes.bottom *= 0.33f;
  64. projMatrix = Matrix4x4.Frustum(planes);
  65. viewMatrix *= Matrix4x4.Translate(new Vector3(.34f, 0.25f, -0.08f));
  66. }
  67. XRView xrView = new XRView(projMatrix, viewMatrix, Matrix4x4.identity, false, xrPass.GetViewport(viewId), null, xrPass.GetTextureArraySlice(viewId));
  68. xrPass.AssignView(viewId, xrView);
  69. }
  70. }
  71. }
  72. }
  73. #endif
  74. }
  75. }
  76. }