No Description
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.

UniversalRenderPipelineCameraUI.Output.Drawers.cs 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Rendering.Universal;
  4. namespace UnityEditor.Rendering.Universal
  5. {
  6. using CED = CoreEditorDrawer<UniversalRenderPipelineSerializedCamera>;
  7. static partial class UniversalRenderPipelineCameraUI
  8. {
  9. public partial class Output
  10. {
  11. public static readonly CED.IDrawer Drawer;
  12. static Output()
  13. {
  14. Drawer = CED.Conditional(
  15. (serialized, owner) => (CameraRenderType)serialized.cameraType.intValue == CameraRenderType.Base,
  16. CED.FoldoutGroup(
  17. CameraUI.Output.Styles.header,
  18. Expandable.Output,
  19. k_ExpandedState,
  20. FoldoutOption.Indent,
  21. CED.Group(
  22. DrawerOutputTargetTexture
  23. ),
  24. CED.Conditional(
  25. (serialized, owner) => serialized.serializedObject.targetObject is Camera camera && camera.targetTexture == null,
  26. CED.Group(
  27. DrawerOutputMultiDisplay
  28. )
  29. ),
  30. #if ENABLE_VR && ENABLE_XR_MODULE
  31. CED.Group(DrawerOutputXRRendering),
  32. #endif
  33. CED.Group(
  34. DrawerOutputNormalizedViewPort
  35. ),
  36. CED.Conditional(
  37. (serialized, owner) => serialized.serializedObject.targetObject is Camera camera && camera.targetTexture == null,
  38. CED.Group(
  39. CED.Group(DrawerOutputHDR),
  40. CED.Conditional(
  41. (serialized, owner) => PlayerSettings.allowHDRDisplaySupport,
  42. CED.Group(DrawerOutputHDROutput)
  43. ),
  44. CED.Group(DrawerOutputMSAA),
  45. CED.Group(DrawerOutputAllowDynamicResolution)
  46. )
  47. )
  48. )
  49. );
  50. }
  51. static void DrawerOutputMultiDisplay(UniversalRenderPipelineSerializedCamera p, Editor owner)
  52. {
  53. using (var checkScope = new EditorGUI.ChangeCheckScope())
  54. {
  55. p.baseCameraSettings.DrawMultiDisplay();
  56. if (checkScope.changed)
  57. {
  58. UpdateStackCamerasOutput(p, camera =>
  59. {
  60. bool isChanged = false;
  61. // Force same target display
  62. int targetDisplay = p.baseCameraSettings.targetDisplay.intValue;
  63. if (camera.targetDisplay != targetDisplay)
  64. {
  65. camera.targetDisplay = targetDisplay;
  66. isChanged = true;
  67. }
  68. // Force same target display
  69. StereoTargetEyeMask stereoTargetEye = (StereoTargetEyeMask)p.baseCameraSettings.targetEye.intValue;
  70. if (camera.stereoTargetEye != stereoTargetEye)
  71. {
  72. camera.stereoTargetEye = stereoTargetEye;
  73. isChanged = true;
  74. }
  75. return isChanged;
  76. });
  77. }
  78. }
  79. }
  80. static void DrawerOutputAllowDynamicResolution(UniversalRenderPipelineSerializedCamera p, Editor owner)
  81. {
  82. using (var checkScope = new EditorGUI.ChangeCheckScope())
  83. {
  84. CameraUI.Output.Drawer_Output_AllowDynamicResolution(p, owner, Styles.allowDynamicResolution);
  85. if (checkScope.changed)
  86. {
  87. UpdateStackCamerasOutput(p, camera =>
  88. {
  89. bool allowDynamicResolution = p.allowDynamicResolution.boolValue;
  90. if (camera.allowDynamicResolution == p.allowDynamicResolution.boolValue)
  91. return false;
  92. EditorUtility.SetDirty(camera);
  93. camera.allowDynamicResolution = allowDynamicResolution;
  94. return true;
  95. });
  96. }
  97. }
  98. }
  99. static void DrawerOutputNormalizedViewPort(UniversalRenderPipelineSerializedCamera p, Editor owner)
  100. {
  101. using (var checkScope = new EditorGUI.ChangeCheckScope())
  102. {
  103. CameraUI.Output.Drawer_Output_NormalizedViewPort(p, owner);
  104. if (checkScope.changed)
  105. {
  106. UpdateStackCamerasOutput(p, camera =>
  107. {
  108. Rect rect = p.baseCameraSettings.normalizedViewPortRect.rectValue;
  109. if (camera.rect != rect)
  110. {
  111. camera.rect = p.baseCameraSettings.normalizedViewPortRect.rectValue;
  112. return true;
  113. }
  114. return false;
  115. });
  116. }
  117. }
  118. }
  119. static void UpdateStackCamerasOutput(UniversalRenderPipelineSerializedCamera p, Func<Camera, bool> updateOutputProperty)
  120. {
  121. int cameraCount = p.cameras.arraySize;
  122. for (int i = 0; i < cameraCount; ++i)
  123. {
  124. SerializedProperty cameraProperty = p.cameras.GetArrayElementAtIndex(i);
  125. Camera overlayCamera = cameraProperty.objectReferenceValue as Camera;
  126. if (overlayCamera != null)
  127. {
  128. Undo.RecordObject(overlayCamera, Styles.inspectorOverlayCameraText);
  129. if (updateOutputProperty(overlayCamera))
  130. EditorUtility.SetDirty(overlayCamera);
  131. }
  132. }
  133. }
  134. static void DrawerOutputTargetTexture(UniversalRenderPipelineSerializedCamera p, Editor owner)
  135. {
  136. var rpAsset = UniversalRenderPipeline.asset;
  137. using (var checkScope = new EditorGUI.ChangeCheckScope())
  138. {
  139. EditorGUILayout.PropertyField(p.baseCameraSettings.targetTexture, Styles.targetTextureLabel);
  140. var texture = p.baseCameraSettings.targetTexture.objectReferenceValue as RenderTexture;
  141. if (!p.baseCameraSettings.targetTexture.hasMultipleDifferentValues && rpAsset != null)
  142. {
  143. int pipelineSamplesCount = rpAsset.msaaSampleCount;
  144. if (texture && texture.antiAliasing > pipelineSamplesCount)
  145. {
  146. string pipelineMSAACaps = (pipelineSamplesCount > 1) ? string.Format(Styles.pipelineMSAACapsSupportSamples, pipelineSamplesCount) : Styles.pipelineMSAACapsDisabled;
  147. EditorGUILayout.HelpBox(string.Format(Styles.cameraTargetTextureMSAA, texture.antiAliasing, pipelineMSAACaps), MessageType.Warning, true);
  148. }
  149. }
  150. if (checkScope.changed)
  151. {
  152. UpdateStackCamerasOutput(p, camera =>
  153. {
  154. if (camera.targetTexture == texture)
  155. return false;
  156. camera.targetTexture = texture;
  157. return true;
  158. });
  159. }
  160. }
  161. }
  162. #if ENABLE_VR && ENABLE_XR_MODULE
  163. static void DrawerOutputXRRendering(UniversalRenderPipelineSerializedCamera p, Editor owner)
  164. {
  165. Rect controlRect = EditorGUILayout.GetControlRect(true);
  166. EditorGUI.BeginProperty(controlRect, Styles.xrTargetEye, p.allowXRRendering);
  167. {
  168. using (var checkScope = new EditorGUI.ChangeCheckScope())
  169. {
  170. int selectedValue = !p.allowXRRendering.boolValue ? 0 : 1;
  171. bool allowXRRendering = EditorGUI.IntPopup(controlRect, Styles.xrTargetEye, selectedValue, Styles.xrTargetEyeOptions, Styles.xrTargetEyeValues) == 1;
  172. if (checkScope.changed)
  173. p.allowXRRendering.boolValue = allowXRRendering;
  174. }
  175. }
  176. EditorGUI.EndProperty();
  177. }
  178. #endif
  179. static void DrawerOutputHDR(UniversalRenderPipelineSerializedCamera p, Editor owner)
  180. {
  181. Rect controlRect = EditorGUILayout.GetControlRect(true);
  182. EditorGUI.BeginProperty(controlRect, Styles.allowHDR, p.baseCameraSettings.HDR);
  183. {
  184. using (var checkScope = new EditorGUI.ChangeCheckScope())
  185. {
  186. int selectedValue = !p.baseCameraSettings.HDR.boolValue ? 0 : 1;
  187. var allowHDR = EditorGUI.IntPopup(controlRect, Styles.allowHDR, selectedValue, Styles.displayedCameraOptions, Styles.cameraOptions) == 1;
  188. if (checkScope.changed)
  189. {
  190. p.baseCameraSettings.HDR.boolValue = allowHDR;
  191. UpdateStackCamerasOutput(p, camera =>
  192. {
  193. if (camera.allowHDR == allowHDR)
  194. return false;
  195. camera.allowHDR = allowHDR;
  196. return true;
  197. });
  198. }
  199. }
  200. }
  201. EditorGUI.EndProperty();
  202. }
  203. static void DrawerOutputHDROutput(UniversalRenderPipelineSerializedCamera p, Editor owner)
  204. {
  205. Rect controlRect = EditorGUILayout.GetControlRect(true);
  206. EditorGUI.BeginProperty(controlRect, Styles.allowHDROutput, p.allowHDROutput);
  207. {
  208. using (var checkScope = new EditorGUI.ChangeCheckScope())
  209. {
  210. int selectedValue = !p.allowHDROutput.boolValue ? 0 : 1;
  211. var allowHDROutput = EditorGUI.IntPopup(controlRect, Styles.allowHDROutput, selectedValue, Styles.hdrOuputOptions, Styles.hdrOuputValues) == 1;
  212. var rpAsset = UniversalRenderPipeline.asset;
  213. bool perCameraHDRDisabled = !p.baseCameraSettings.HDR.boolValue && (rpAsset == null || rpAsset.supportsHDR);
  214. if (allowHDROutput && PlayerSettings.allowHDRDisplaySupport && perCameraHDRDisabled)
  215. {
  216. EditorGUILayout.HelpBox(Styles.disabledHDRRenderingWithHDROutput, MessageType.Warning);
  217. }
  218. if (checkScope.changed)
  219. p.allowHDROutput.boolValue = allowHDROutput;
  220. }
  221. }
  222. EditorGUI.EndProperty();
  223. }
  224. static void DrawerOutputMSAA(UniversalRenderPipelineSerializedCamera p, Editor owner)
  225. {
  226. Rect controlRect = EditorGUILayout.GetControlRect(true);
  227. EditorGUI.BeginProperty(controlRect, Styles.allowMSAA, p.baseCameraSettings.allowMSAA);
  228. {
  229. using (var checkScope = new EditorGUI.ChangeCheckScope())
  230. {
  231. int selectedValue = !p.baseCameraSettings.allowMSAA.boolValue ? 0 : 1;
  232. var allowMSAA = EditorGUI.IntPopup(controlRect, Styles.allowMSAA,
  233. selectedValue, Styles.displayedCameraOptions, Styles.cameraOptions) == 1;
  234. if (checkScope.changed)
  235. {
  236. p.baseCameraSettings.allowMSAA.boolValue = allowMSAA;
  237. UpdateStackCamerasOutput(p, camera =>
  238. {
  239. if (camera.allowMSAA == allowMSAA)
  240. return false;
  241. camera.allowMSAA = allowMSAA;
  242. return true;
  243. });
  244. }
  245. }
  246. }
  247. EditorGUI.EndProperty();
  248. }
  249. }
  250. }
  251. }