Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

UniversalResourceData.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. using System;
  2. using UnityEngine.Rendering.RenderGraphModule;
  3. namespace UnityEngine.Rendering.Universal
  4. {
  5. /// <summary>
  6. /// Class that holds settings related to texture resources.
  7. /// </summary>
  8. public class UniversalResourceData : UniversalResourceDataBase
  9. {
  10. /// <summary>
  11. /// The active color target ID.
  12. /// </summary>
  13. internal ActiveID activeColorID { get; set; }
  14. /// <summary>
  15. /// Returns the current active color target texture. To be referenced at RenderGraph pass recording time, not in passes render functions.
  16. /// </summary>
  17. /// <value>Returns the active color texture between the front and back buffer.</value>
  18. public TextureHandle activeColorTexture
  19. {
  20. get
  21. {
  22. if (!CheckAndWarnAboutAccessibility())
  23. return TextureHandle.nullHandle;
  24. switch (activeColorID)
  25. {
  26. case ActiveID.Camera:
  27. return cameraColor;
  28. case ActiveID.BackBuffer:
  29. return backBufferColor;
  30. default:
  31. throw new ArgumentOutOfRangeException();
  32. }
  33. }
  34. }
  35. /// <summary>
  36. /// The active depth target ID.
  37. /// </summary>
  38. internal ActiveID activeDepthID { get; set; }
  39. /// <summary>
  40. /// Returns the current active color target texture. To be referenced at RenderGraph pass recording time, not in passes render functions.
  41. /// </summary>
  42. /// <value>TextureHandle</value>
  43. public TextureHandle activeDepthTexture
  44. {
  45. get
  46. {
  47. if (!CheckAndWarnAboutAccessibility())
  48. return TextureHandle.nullHandle;
  49. switch (activeDepthID)
  50. {
  51. case ActiveID.Camera:
  52. return cameraDepth;
  53. case ActiveID.BackBuffer:
  54. return backBufferDepth;
  55. default:
  56. throw new ArgumentOutOfRangeException();
  57. }
  58. }
  59. }
  60. /// <summary>
  61. /// True if the current active target is the backbuffer. To be referenced at RenderGraph pass recording time, not in passes render functions.
  62. /// </summary>
  63. /// <value>Returns true if the backbuffer is currently in use and false otherwise.</value>
  64. public bool isActiveTargetBackBuffer
  65. {
  66. get
  67. {
  68. if (!isAccessible)
  69. {
  70. Debug.LogError("Trying to access frameData outside of the current frame setup.");
  71. return false;
  72. }
  73. return activeColorID == UniversalResourceData.ActiveID.BackBuffer;
  74. }
  75. }
  76. /// <summary>
  77. /// The backbuffer color used to render directly to screen. All passes can write to it depending on frame setup.
  78. /// </summary>
  79. public TextureHandle backBufferColor
  80. {
  81. get => CheckAndGetTextureHandle(ref _backBufferColor);
  82. internal set => CheckAndSetTextureHandle(ref _backBufferColor, value);
  83. }
  84. private TextureHandle _backBufferColor;
  85. /// <summary>
  86. /// The backbuffer depth used to render directly to screen. All passes can write to it depending on frame setup.
  87. /// </summary>
  88. public TextureHandle backBufferDepth
  89. {
  90. get => CheckAndGetTextureHandle(ref _backBufferDepth);
  91. internal set => CheckAndSetTextureHandle(ref _backBufferDepth, value);
  92. }
  93. private TextureHandle _backBufferDepth;
  94. // intermediate camera targets
  95. /// <summary>
  96. /// Main offscreen camera color target. All passes can write to it depending on frame setup.
  97. /// Can hold multiple samples if MSAA is enabled.
  98. /// </summary>
  99. public TextureHandle cameraColor
  100. {
  101. get => CheckAndGetTextureHandle(ref _cameraColor);
  102. set => CheckAndSetTextureHandle(ref _cameraColor, value);
  103. }
  104. private TextureHandle _cameraColor;
  105. /// <summary>
  106. /// Main offscreen camera depth target. All passes can write to it depending on frame setup.
  107. /// Can hold multiple samples if MSAA is enabled.
  108. /// </summary>
  109. public TextureHandle cameraDepth
  110. {
  111. get => CheckAndGetTextureHandle(ref _cameraDepth);
  112. set => CheckAndSetTextureHandle(ref _cameraDepth, value);
  113. }
  114. private TextureHandle _cameraDepth;
  115. // shadows
  116. /// <summary>
  117. /// Main shadow map.
  118. /// </summary>
  119. public TextureHandle mainShadowsTexture
  120. {
  121. get => CheckAndGetTextureHandle(ref _mainShadowsTexture);
  122. set => CheckAndSetTextureHandle(ref _mainShadowsTexture, value);
  123. }
  124. private TextureHandle _mainShadowsTexture;
  125. /// <summary>
  126. /// Additional shadow map.
  127. /// </summary>
  128. public TextureHandle additionalShadowsTexture
  129. {
  130. get => CheckAndGetTextureHandle(ref _additionalShadowsTexture);
  131. set => CheckAndSetTextureHandle(ref _additionalShadowsTexture, value);
  132. }
  133. private TextureHandle _additionalShadowsTexture;
  134. // GBuffer targets
  135. /// <summary>
  136. /// GBuffer. Written to by the GBuffer pass.
  137. /// </summary>
  138. public TextureHandle[] gBuffer
  139. {
  140. get => CheckAndGetTextureHandle(ref _gBuffer);
  141. set => CheckAndSetTextureHandle(ref _gBuffer, value);
  142. }
  143. private TextureHandle[] _gBuffer = new TextureHandle[RenderGraphUtils.GBufferSize];
  144. // camera opaque/depth/normal
  145. /// <summary>
  146. /// Camera opaque texture. Contains a copy of CameraColor if the CopyColor pass is executed.
  147. /// </summary>
  148. public TextureHandle cameraOpaqueTexture
  149. {
  150. get => CheckAndGetTextureHandle(ref _cameraOpaqueTexture);
  151. internal set => CheckAndSetTextureHandle(ref _cameraOpaqueTexture, value);
  152. }
  153. private TextureHandle _cameraOpaqueTexture;
  154. /// <summary>
  155. /// Camera depth texture. Contains the scene depth if the CopyDepth or Depth Prepass passes are executed.
  156. /// </summary>
  157. public TextureHandle cameraDepthTexture
  158. {
  159. get => CheckAndGetTextureHandle(ref _cameraDepthTexture);
  160. internal set => CheckAndSetTextureHandle(ref _cameraDepthTexture, value);
  161. }
  162. private TextureHandle _cameraDepthTexture;
  163. /// <summary>
  164. /// Camera normals texture. Contains the scene depth if the DepthNormals Prepass pass is executed.
  165. /// </summary>
  166. public TextureHandle cameraNormalsTexture
  167. {
  168. get => CheckAndGetTextureHandle(ref _cameraNormalsTexture);
  169. internal set => CheckAndSetTextureHandle(ref _cameraNormalsTexture, value);
  170. }
  171. private TextureHandle _cameraNormalsTexture;
  172. // motion vector
  173. /// <summary>
  174. /// Motion Vector Color. Written to by the Motion Vector passes.
  175. /// </summary>
  176. public TextureHandle motionVectorColor
  177. {
  178. get => CheckAndGetTextureHandle(ref _motionVectorColor);
  179. set => CheckAndSetTextureHandle(ref _motionVectorColor, value);
  180. }
  181. private TextureHandle _motionVectorColor;
  182. /// <summary>
  183. /// Motion Vector Depth. Written to by the Motion Vector passes.
  184. /// </summary>
  185. public TextureHandle motionVectorDepth
  186. {
  187. get => CheckAndGetTextureHandle(ref _motionVectorDepth);
  188. set => CheckAndSetTextureHandle(ref _motionVectorDepth, value);
  189. }
  190. private TextureHandle _motionVectorDepth;
  191. // postFx
  192. /// <summary>
  193. /// Internal Color LUT. Written to by the InternalLUT pass.
  194. /// </summary>
  195. public TextureHandle internalColorLut
  196. {
  197. get => CheckAndGetTextureHandle(ref _internalColorLut);
  198. set => CheckAndSetTextureHandle(ref _internalColorLut, value);
  199. }
  200. private TextureHandle _internalColorLut;
  201. /// <summary>
  202. /// Color output of post-process passes (uberPost and finalPost) when HDR debug views are enabled. It replaces
  203. /// the backbuffer color as standard output because the later cannot be sampled back (or may not be in HDR format).
  204. /// If used, DebugHandler will perform the blit from DebugScreenTexture to BackBufferColor.
  205. /// </summary>
  206. internal TextureHandle debugScreenColor
  207. {
  208. get => CheckAndGetTextureHandle(ref _debugScreenColor);
  209. set => CheckAndSetTextureHandle(ref _debugScreenColor, value);
  210. }
  211. internal TextureHandle _debugScreenColor;
  212. /// <summary>
  213. /// Depth output of post-process passes (uberPost and finalPost) when HDR debug views are enabled. It replaces
  214. /// the backbuffer depth as standard output because the later cannot be sampled back.
  215. /// </summary>
  216. internal TextureHandle debugScreenDepth
  217. {
  218. get => CheckAndGetTextureHandle(ref _debugScreenDepth);
  219. set => CheckAndSetTextureHandle(ref _debugScreenDepth, value);
  220. }
  221. internal TextureHandle _debugScreenDepth;
  222. /// <summary>
  223. /// After Post Process Color. Stores the contents of the main color target after the post processing passes.
  224. /// </summary>
  225. public TextureHandle afterPostProcessColor
  226. {
  227. get => CheckAndGetTextureHandle(ref _afterPostProcessColor);
  228. internal set => CheckAndSetTextureHandle(ref _afterPostProcessColor, value);
  229. }
  230. private TextureHandle _afterPostProcessColor;
  231. /// <summary>
  232. /// Overlay UI Texture. The DrawScreenSpaceUI pass writes to this texture when rendering off-screen.
  233. /// </summary>
  234. public TextureHandle overlayUITexture
  235. {
  236. get => CheckAndGetTextureHandle(ref _overlayUITexture);
  237. internal set => CheckAndSetTextureHandle(ref _overlayUITexture, value);
  238. }
  239. private TextureHandle _overlayUITexture;
  240. // rendering layers
  241. /// <summary>
  242. /// Rendering Layers Texture. Can be written to by the DrawOpaques pass or DepthNormals prepass based on settings.
  243. /// </summary>
  244. public TextureHandle renderingLayersTexture
  245. {
  246. get => CheckAndGetTextureHandle(ref _renderingLayersTexture);
  247. internal set => CheckAndSetTextureHandle(ref _renderingLayersTexture, value);
  248. }
  249. private TextureHandle _renderingLayersTexture;
  250. // decals
  251. /// <summary>
  252. /// DBuffer. Written to by the Decals pass.
  253. /// </summary>
  254. public TextureHandle[] dBuffer
  255. {
  256. get => CheckAndGetTextureHandle(ref _dBuffer);
  257. set => CheckAndSetTextureHandle(ref _dBuffer, value);
  258. }
  259. private TextureHandle[] _dBuffer = new TextureHandle[RenderGraphUtils.DBufferSize];
  260. /// <summary>
  261. /// DBufferDepth. Written to by the Decals pass.
  262. /// </summary>
  263. public TextureHandle dBufferDepth
  264. {
  265. get => CheckAndGetTextureHandle(ref _dBufferDepth);
  266. set => CheckAndSetTextureHandle(ref _dBufferDepth, value);
  267. }
  268. private TextureHandle _dBufferDepth;
  269. /// <summary>
  270. /// Screen Space Ambient Occlusion texture. Written to by the SSAO pass.
  271. /// </summary>
  272. public TextureHandle ssaoTexture
  273. {
  274. get => CheckAndGetTextureHandle(ref _ssaoTexture);
  275. internal set => CheckAndSetTextureHandle(ref _ssaoTexture, value);
  276. }
  277. private TextureHandle _ssaoTexture;
  278. /// <summary>
  279. /// STP debug visualization written to by the STP upscaler.
  280. /// </summary>
  281. internal TextureHandle stpDebugView
  282. {
  283. get => CheckAndGetTextureHandle(ref _stpDebugView);
  284. set => CheckAndSetTextureHandle(ref _stpDebugView, value);
  285. }
  286. private TextureHandle _stpDebugView;
  287. /// <inheritdoc />
  288. public override void Reset()
  289. {
  290. _backBufferColor = TextureHandle.nullHandle;
  291. _backBufferDepth = TextureHandle.nullHandle;
  292. _cameraColor = TextureHandle.nullHandle;
  293. _cameraDepth = TextureHandle.nullHandle;
  294. _mainShadowsTexture = TextureHandle.nullHandle;
  295. _additionalShadowsTexture = TextureHandle.nullHandle;
  296. _cameraOpaqueTexture = TextureHandle.nullHandle;
  297. _cameraDepthTexture = TextureHandle.nullHandle;
  298. _cameraNormalsTexture = TextureHandle.nullHandle;
  299. _motionVectorColor = TextureHandle.nullHandle;
  300. _motionVectorDepth = TextureHandle.nullHandle;
  301. _internalColorLut = TextureHandle.nullHandle;
  302. _debugScreenColor = TextureHandle.nullHandle;
  303. _debugScreenDepth = TextureHandle.nullHandle;
  304. _afterPostProcessColor = TextureHandle.nullHandle;
  305. _overlayUITexture = TextureHandle.nullHandle;
  306. _renderingLayersTexture = TextureHandle.nullHandle;
  307. _dBufferDepth = TextureHandle.nullHandle;
  308. _ssaoTexture = TextureHandle.nullHandle;
  309. _stpDebugView = TextureHandle.nullHandle;
  310. for (int i = 0; i < _gBuffer.Length; i++)
  311. _gBuffer[i] = TextureHandle.nullHandle;
  312. for (int i = 0; i < _dBuffer.Length; i++)
  313. _dBuffer[i] = TextureHandle.nullHandle;
  314. }
  315. }
  316. }