CameraUtility.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Rendering;
  5. #if URP_OUTLINE && UNITY_2019_1_OR_NEWER
  6. #if UNITY_2019_3_OR_NEWER
  7. using UnityEngine.Rendering.Universal;
  8. #else
  9. using UnityEngine.Rendering.LWRP;
  10. #endif
  11. #endif
  12. #if UNITY_EDITOR
  13. using UnityEditor;
  14. #endif
  15. #if HDRP_OUTLINE
  16. using UnityEngine.Rendering.HighDefinition;
  17. #endif
  18. namespace EPOOutline
  19. {
  20. public static class CameraUtility
  21. {
  22. public static int GetMSAA(Camera camera)
  23. {
  24. if (camera.targetTexture != null)
  25. return camera.targetTexture.antiAliasing;
  26. var antialiasing = GetRenderPipelineMSAA();
  27. var msaa = Mathf.Max(antialiasing, 1);
  28. if (!camera.allowMSAA)
  29. msaa = 1;
  30. if (camera.actualRenderingPath != RenderingPath.Forward &&
  31. camera.actualRenderingPath != RenderingPath.VertexLit)
  32. msaa = 1;
  33. return msaa;
  34. }
  35. private static int GetRenderPipelineMSAA()
  36. {
  37. #if URP_OUTLINE && UNITY_2019_1_OR_NEWER
  38. if (PipelineFetcher.CurrentAsset is
  39. #if UNITY_2019_3_OR_NEWER
  40. UniversalRenderPipelineAsset
  41. #else
  42. LightweightRenderPipelineAsset
  43. #endif
  44. )
  45. return (PipelineFetcher.CurrentAsset as
  46. #if UNITY_2019_3_OR_NEWER
  47. UniversalRenderPipelineAsset
  48. #else
  49. LightweightRenderPipelineAsset
  50. #endif
  51. ).msaaSampleCount;
  52. #endif
  53. #if HDRP_OUTLINE
  54. if (PipelineFetcher.CurrentAsset is HDRenderPipelineAsset)
  55. return 1;
  56. #endif
  57. return QualitySettings.antiAliasing;
  58. }
  59. }
  60. }