AutogenShaderHeaders.ush 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. // Copyright Epic Games, Inc. All Rights Reserved.
  2. #pragma once
  3. #if FEATURE_LEVEL >= FEATURE_LEVEL_SM5
  4. float SampleDeviceZFromSceneTexturesTempCopy(float2 UV)
  5. {
  6. return SceneDepthTexture.SampleLevel(SceneDepthTextureSampler, UV, 0).r;
  7. }
  8. #endif
  9. #ifndef GBUFFER_LAYOUT
  10. #define GBUFFER_LAYOUT 0
  11. #endif
  12. #if GBUFFER_LAYOUT == 0
  13. void EncodeGBufferToMRT(inout FPixelShaderOut Out, FGBufferData GBuffer, float QuantizationBias)
  14. {
  15. float4 MrtFloat1 = 0.0f;
  16. float4 MrtFloat2 = 0.0f;
  17. uint4 MrtUint2 = 0;
  18. float4 MrtFloat3 = 0.0f;
  19. float4 MrtFloat4 = 0.0f;
  20. float4 MrtFloat5 = 0.0f;
  21. float4 MrtFloat6 = 0.0f;
  22. float3 WorldNormal_Compressed = EncodeNormalHelper(GBuffer.WorldNormal, 0.0f);
  23. MrtFloat1.x = WorldNormal_Compressed.x;
  24. MrtFloat1.y = WorldNormal_Compressed.y;
  25. MrtFloat1.z = WorldNormal_Compressed.z;
  26. MrtFloat1.w = GBuffer.PerObjectGBufferData.x;
  27. MrtFloat2.x = GBuffer.Metallic.x;
  28. MrtFloat2.y = GBuffer.Specular.x;
  29. MrtFloat2.z = GBuffer.Roughness.x;
  30. MrtUint2.w |= ((((GBuffer.ShadingModelID.x) >> 0) & 0x0f) << 0);
  31. MrtUint2.w |= ((((GBuffer.SelectiveOutputMask.x) >> 0) & 0x0f) << 4);
  32. MrtFloat3.x = GBuffer.BaseColor.x;
  33. MrtFloat3.y = GBuffer.BaseColor.y;
  34. MrtFloat3.z = GBuffer.BaseColor.z;
  35. MrtFloat3.w = GBuffer.GenericAO.x;
  36. MrtFloat4.x = GBuffer.Velocity.x;
  37. MrtFloat4.y = GBuffer.Velocity.y;
  38. MrtFloat4.z = GBuffer.Velocity.z;
  39. MrtFloat4.w = GBuffer.Velocity.w;
  40. MrtFloat6.x = GBuffer.PrecomputedShadowFactors.x;
  41. MrtFloat6.y = GBuffer.PrecomputedShadowFactors.y;
  42. MrtFloat6.z = GBuffer.PrecomputedShadowFactors.z;
  43. MrtFloat6.w = GBuffer.PrecomputedShadowFactors.w;
  44. MrtFloat5.x = GBuffer.CustomData.x;
  45. MrtFloat5.y = GBuffer.CustomData.y;
  46. MrtFloat5.z = GBuffer.CustomData.z;
  47. MrtFloat5.w = GBuffer.CustomData.w;
  48. Out.MRT[1] = MrtFloat1;
  49. Out.MRT[2] = float4(MrtFloat2.x, MrtFloat2.y, MrtFloat2.z, (float(MrtUint2.w) + .5f) / 255.0f);
  50. Out.MRT[3] = MrtFloat3;
  51. Out.MRT[4] = MrtFloat4;
  52. Out.MRT[5] = MrtFloat5;
  53. Out.MRT[6] = MrtFloat6;
  54. Out.MRT[7] = float4(0.0f, 0.0f, 0.0f, 0.0f);
  55. }
  56. FGBufferData DecodeGBufferDataDirect(float4 InMRT1,
  57. float4 InMRT2,
  58. float4 InMRT3,
  59. float4 InMRT4,
  60. float4 InMRT5,
  61. float4 InMRT6,
  62. float CustomNativeDepth,
  63. float4 AnisotropicData,
  64. uint CustomStencil,
  65. float SceneDepth,
  66. bool bGetNormalizedNormal,
  67. bool bChecker)
  68. {
  69. FGBufferData Ret = (FGBufferData)0;
  70. float3 WorldNormal_Compressed = 0.0f;
  71. WorldNormal_Compressed.x = InMRT1.x;
  72. WorldNormal_Compressed.y = InMRT1.y;
  73. WorldNormal_Compressed.z = InMRT1.z;
  74. Ret.PerObjectGBufferData.x = InMRT1.w;
  75. Ret.Metallic.x = InMRT2.x;
  76. Ret.Specular.x = InMRT2.y;
  77. Ret.Roughness.x = InMRT2.z;
  78. Ret.ShadingModelID.x = (((uint((float(InMRT2.w) * 255.0f) + .5f) >> 0) & 0x0f) << 0);
  79. Ret.SelectiveOutputMask.x = (((uint((float(InMRT2.w) * 255.0f) + .5f) >> 4) & 0x0f) << 0);
  80. Ret.BaseColor.x = InMRT3.x;
  81. Ret.BaseColor.y = InMRT3.y;
  82. Ret.BaseColor.z = InMRT3.z;
  83. Ret.GenericAO.x = InMRT3.w;
  84. Ret.Velocity.x = InMRT4.x;
  85. Ret.Velocity.y = InMRT4.y;
  86. Ret.Velocity.z = InMRT4.z;
  87. Ret.Velocity.w = InMRT4.w;
  88. Ret.PrecomputedShadowFactors.x = InMRT6.x;
  89. Ret.PrecomputedShadowFactors.y = InMRT6.y;
  90. Ret.PrecomputedShadowFactors.z = InMRT6.z;
  91. Ret.PrecomputedShadowFactors.w = InMRT6.w;
  92. Ret.CustomData.x = InMRT5.x;
  93. Ret.CustomData.y = InMRT5.y;
  94. Ret.CustomData.z = InMRT5.z;
  95. Ret.CustomData.w = InMRT5.w;
  96. Ret.WorldNormal = DecodeNormalHelper(WorldNormal_Compressed);
  97. Ret.WorldTangent = AnisotropicData.xyz;
  98. Ret.Anisotropy = AnisotropicData.w;
  99. GBufferPostDecode(Ret,bChecker,bGetNormalizedNormal);
  100. Ret.CustomDepth = ConvertFromDeviceZ(CustomNativeDepth);
  101. Ret.CustomStencil = CustomStencil;
  102. Ret.Depth = SceneDepth;
  103. return Ret;
  104. }
  105. #if FEATURE_LEVEL >= FEATURE_LEVEL_SM5
  106. // @param PixelPos relative to left top of the rendertarget (not viewport)
  107. FGBufferData DecodeGBufferDataUV(float2 UV, bool bGetNormalizedNormal = true)
  108. {
  109. float CustomNativeDepth = Texture2DSampleLevel(SceneTexturesStruct.CustomDepthTexture, SceneTexturesStruct_CustomDepthTextureSampler, UV, 0).r;
  110. int2 IntUV = (int2)trunc(UV * View.BufferSizeAndInvSize.xy * View.BufferToSceneTextureScale.xy);
  111. uint CustomStencil = SceneTexturesStruct.CustomStencilTexture.Load(int3(IntUV, 0)) STENCIL_COMPONENT_SWIZZLE;
  112. float SceneDepth = CalcSceneDepth(UV);
  113. float4 AnisotropicData = Texture2DSampleLevel(SceneTexturesStruct.GBufferFTexture, SceneTexturesStruct_GBufferFTextureSampler, UV, 0).xyzw;
  114. float4 InMRT1 = Texture2DSampleLevel(SceneTexturesStruct.GBufferATexture, SceneTexturesStruct_GBufferATextureSampler, UV, 0).xyzw;
  115. float4 InMRT2 = Texture2DSampleLevel(SceneTexturesStruct.GBufferBTexture, SceneTexturesStruct_GBufferBTextureSampler, UV, 0).xyzw;
  116. float4 InMRT3 = Texture2DSampleLevel(SceneTexturesStruct.GBufferCTexture, SceneTexturesStruct_GBufferCTextureSampler, UV, 0).xyzw;
  117. float4 InMRT4 = Texture2DSampleLevel(SceneTexturesStruct.GBufferVelocityTexture, SceneTexturesStruct_GBufferVelocityTextureSampler, UV, 0).xyzw;
  118. float4 InMRT5 = Texture2DSampleLevel(SceneTexturesStruct.GBufferDTexture, SceneTexturesStruct_GBufferDTextureSampler, UV, 0).xyzw;
  119. float4 InMRT6 = Texture2DSampleLevel(SceneTexturesStruct.GBufferETexture, SceneTexturesStruct_GBufferETextureSampler, UV, 0).xyzw;
  120. FGBufferData Ret = DecodeGBufferDataDirect(InMRT1,
  121. InMRT2,
  122. InMRT3,
  123. InMRT4,
  124. InMRT5,
  125. InMRT6,
  126. CustomNativeDepth,
  127. AnisotropicData,
  128. CustomStencil,
  129. SceneDepth,
  130. bGetNormalizedNormal,
  131. CheckerFromSceneColorUV(UV));
  132. return Ret;
  133. }
  134. // @param PixelPos relative to left top of the rendertarget (not viewport)
  135. FGBufferData DecodeGBufferDataUint(uint2 PixelPos, bool bGetNormalizedNormal = true)
  136. {
  137. float CustomNativeDepth = SceneTexturesStruct.CustomDepthTexture.Load(int3(PixelPos, 0)).r;
  138. uint CustomStencil = SceneTexturesStruct.CustomStencilTexture.Load(int3(PixelPos, 0)) STENCIL_COMPONENT_SWIZZLE;
  139. float SceneDepth = CalcSceneDepth(PixelPos);
  140. float4 AnisotropicData = SceneTexturesStruct.GBufferFTexture.Load(int3(PixelPos, 0)).xyzw;
  141. float4 InMRT1 = SceneTexturesStruct.GBufferATexture.Load(int3(PixelPos, 0)).xyzw;
  142. float4 InMRT2 = SceneTexturesStruct.GBufferBTexture.Load(int3(PixelPos, 0)).xyzw;
  143. float4 InMRT3 = SceneTexturesStruct.GBufferCTexture.Load(int3(PixelPos, 0)).xyzw;
  144. float4 InMRT4 = SceneTexturesStruct.GBufferVelocityTexture.Load(int3(PixelPos, 0)).xyzw;
  145. float4 InMRT5 = SceneTexturesStruct.GBufferDTexture.Load(int3(PixelPos, 0)).xyzw;
  146. float4 InMRT6 = SceneTexturesStruct.GBufferETexture.Load(int3(PixelPos, 0)).xyzw;
  147. FGBufferData Ret = DecodeGBufferDataDirect(InMRT1,
  148. InMRT2,
  149. InMRT3,
  150. InMRT4,
  151. InMRT5,
  152. InMRT6,
  153. CustomNativeDepth,
  154. AnisotropicData,
  155. CustomStencil,
  156. SceneDepth,
  157. bGetNormalizedNormal,
  158. CheckerFromPixelPos(PixelPos));
  159. return Ret;
  160. }
  161. // @param PixelPos relative to left top of the rendertarget (not viewport)
  162. FGBufferData DecodeGBufferDataSceneTextures(float2 UV, bool bGetNormalizedNormal = true)
  163. {
  164. uint CustomStencil = 0;
  165. float CustomNativeDepth = 0;
  166. float DeviceZ = SampleDeviceZFromSceneTexturesTempCopy(UV);
  167. float SceneDepth = ConvertFromDeviceZ(DeviceZ);
  168. float4 AnisotropicData = GBufferFTexture.SampleLevel(GBufferFTextureSampler, UV, 0).xyzw;
  169. float4 InMRT1 = GBufferATexture.SampleLevel(GBufferATextureSampler, UV, 0).xyzw;
  170. float4 InMRT2 = GBufferBTexture.SampleLevel(GBufferBTextureSampler, UV, 0).xyzw;
  171. float4 InMRT3 = GBufferCTexture.SampleLevel(GBufferCTextureSampler, UV, 0).xyzw;
  172. float4 InMRT4 = GBufferVelocityTexture.SampleLevel(GBufferVelocityTextureSampler, UV, 0).xyzw;
  173. float4 InMRT5 = GBufferDTexture.SampleLevel(GBufferDTextureSampler, UV, 0).xyzw;
  174. float4 InMRT6 = GBufferETexture.SampleLevel(GBufferETextureSampler, UV, 0).xyzw;
  175. FGBufferData Ret = DecodeGBufferDataDirect(InMRT1,
  176. InMRT2,
  177. InMRT3,
  178. InMRT4,
  179. InMRT5,
  180. InMRT6,
  181. CustomNativeDepth,
  182. AnisotropicData,
  183. CustomStencil,
  184. SceneDepth,
  185. bGetNormalizedNormal,
  186. CheckerFromSceneColorUV(UV));
  187. return Ret;
  188. }
  189. // @param PixelPos relative to left top of the rendertarget (not viewport)
  190. FGBufferData DecodeGBufferDataSceneTexturesLoad(uint2 PixelCoord, bool bGetNormalizedNormal = true)
  191. {
  192. uint CustomStencil = 0;
  193. float CustomNativeDepth = 0;
  194. float DeviceZ = SceneDepthTexture.Load(int3(PixelCoord, 0)).r;
  195. float SceneDepth = ConvertFromDeviceZ(DeviceZ);
  196. float4 AnisotropicData = GBufferFTexture.Load(int3(PixelCoord, 0)).xyzw;
  197. float4 InMRT1 = GBufferATexture.Load(int3(PixelCoord, 0)).xyzw;
  198. float4 InMRT2 = GBufferBTexture.Load(int3(PixelCoord, 0)).xyzw;
  199. float4 InMRT3 = GBufferCTexture.Load(int3(PixelCoord, 0)).xyzw;
  200. float4 InMRT4 = GBufferVelocityTexture.Load(int3(PixelCoord, 0)).xyzw;
  201. float4 InMRT5 = GBufferDTexture.Load(int3(PixelCoord, 0)).xyzw;
  202. float4 InMRT6 = GBufferETexture.Load(int3(PixelCoord, 0)).xyzw;
  203. FGBufferData Ret = DecodeGBufferDataDirect(InMRT1,
  204. InMRT2,
  205. InMRT3,
  206. InMRT4,
  207. InMRT5,
  208. InMRT6,
  209. CustomNativeDepth,
  210. AnisotropicData,
  211. CustomStencil,
  212. SceneDepth,
  213. bGetNormalizedNormal,
  214. CheckerFromPixelPos(PixelCoord));
  215. return Ret;
  216. }
  217. #endif
  218. #endif
  219. #if GBUFFER_LAYOUT == 1
  220. void EncodeGBufferToMRT(inout FPixelShaderOut Out, FGBufferData GBuffer, float QuantizationBias)
  221. {
  222. float4 MrtFloat1 = 0.0f;
  223. float4 MrtFloat2 = 0.0f;
  224. uint4 MrtUint2 = 0;
  225. float4 MrtFloat3 = 0.0f;
  226. float4 MrtFloat4 = 0.0f;
  227. float4 MrtFloat5 = 0.0f;
  228. float4 MrtFloat6 = 0.0f;
  229. float3 WorldNormal_Compressed = EncodeNormalHelper(GBuffer.WorldNormal, 0.0f);
  230. MrtFloat1.x = WorldNormal_Compressed.x;
  231. MrtFloat1.y = WorldNormal_Compressed.y;
  232. MrtFloat1.z = WorldNormal_Compressed.z;
  233. MrtFloat1.w = GBuffer.PerObjectGBufferData.x;
  234. MrtFloat2.x = GBuffer.Metallic.x;
  235. MrtFloat2.y = GBuffer.Specular.x;
  236. MrtFloat2.z = GBuffer.Roughness.x;
  237. MrtUint2.w |= ((((GBuffer.ShadingModelID.x) >> 0) & 0x0f) << 0);
  238. MrtUint2.w |= ((((GBuffer.SelectiveOutputMask.x) >> 0) & 0x0f) << 4);
  239. MrtFloat3.x = GBuffer.BaseColor.x;
  240. MrtFloat3.y = GBuffer.BaseColor.y;
  241. MrtFloat3.z = GBuffer.BaseColor.z;
  242. MrtFloat3.w = GBuffer.GenericAO.x;
  243. MrtFloat4.x = GBuffer.Velocity.x;
  244. MrtFloat4.y = GBuffer.Velocity.y;
  245. MrtFloat4.z = GBuffer.Velocity.z;
  246. MrtFloat4.w = GBuffer.Velocity.w;
  247. MrtFloat6.x = GBuffer.PrecomputedShadowFactors.x;
  248. MrtFloat6.y = GBuffer.PrecomputedShadowFactors.y;
  249. MrtFloat6.z = GBuffer.PrecomputedShadowFactors.z;
  250. MrtFloat6.w = GBuffer.PrecomputedShadowFactors.w;
  251. MrtFloat5.x = GBuffer.CustomData.x;
  252. MrtFloat5.y = GBuffer.CustomData.y;
  253. MrtFloat5.z = GBuffer.CustomData.z;
  254. MrtFloat5.w = GBuffer.CustomData.w;
  255. Out.MRT[1] = MrtFloat1;
  256. Out.MRT[2] = float4(MrtFloat2.x, MrtFloat2.y, MrtFloat2.z, (float(MrtUint2.w) + .5f) / 255.0f);
  257. Out.MRT[3] = MrtFloat3;
  258. Out.MRT[4] = MrtFloat4;
  259. Out.MRT[5] = MrtFloat5;
  260. Out.MRT[6] = MrtFloat6;
  261. Out.MRT[7] = float4(0.0f, 0.0f, 0.0f, 0.0f);
  262. }
  263. FGBufferData DecodeGBufferDataDirect(float4 InMRT1,
  264. float4 InMRT2,
  265. float4 InMRT3,
  266. float4 InMRT4,
  267. float4 InMRT5,
  268. float4 InMRT6,
  269. float CustomNativeDepth,
  270. float4 AnisotropicData,
  271. uint CustomStencil,
  272. float SceneDepth,
  273. bool bGetNormalizedNormal,
  274. bool bChecker)
  275. {
  276. FGBufferData Ret = (FGBufferData)0;
  277. float3 WorldNormal_Compressed = 0.0f;
  278. WorldNormal_Compressed.x = InMRT1.x;
  279. WorldNormal_Compressed.y = InMRT1.y;
  280. WorldNormal_Compressed.z = InMRT1.z;
  281. Ret.PerObjectGBufferData.x = InMRT1.w;
  282. Ret.Metallic.x = InMRT2.x;
  283. Ret.Specular.x = InMRT2.y;
  284. Ret.Roughness.x = InMRT2.z;
  285. Ret.ShadingModelID.x = (((uint((float(InMRT2.w) * 255.0f) + .5f) >> 0) & 0x0f) << 0);
  286. Ret.SelectiveOutputMask.x = (((uint((float(InMRT2.w) * 255.0f) + .5f) >> 4) & 0x0f) << 0);
  287. Ret.BaseColor.x = InMRT3.x;
  288. Ret.BaseColor.y = InMRT3.y;
  289. Ret.BaseColor.z = InMRT3.z;
  290. Ret.GenericAO.x = InMRT3.w;
  291. Ret.Velocity.x = InMRT4.x;
  292. Ret.Velocity.y = InMRT4.y;
  293. Ret.Velocity.z = InMRT4.z;
  294. Ret.Velocity.w = InMRT4.w;
  295. Ret.PrecomputedShadowFactors.x = InMRT6.x;
  296. Ret.PrecomputedShadowFactors.y = InMRT6.y;
  297. Ret.PrecomputedShadowFactors.z = InMRT6.z;
  298. Ret.PrecomputedShadowFactors.w = InMRT6.w;
  299. Ret.CustomData.x = InMRT5.x;
  300. Ret.CustomData.y = InMRT5.y;
  301. Ret.CustomData.z = InMRT5.z;
  302. Ret.CustomData.w = InMRT5.w;
  303. Ret.WorldNormal = DecodeNormalHelper(WorldNormal_Compressed);
  304. Ret.WorldTangent = AnisotropicData.xyz;
  305. Ret.Anisotropy = AnisotropicData.w;
  306. GBufferPostDecode(Ret,bChecker,bGetNormalizedNormal);
  307. Ret.CustomDepth = ConvertFromDeviceZ(CustomNativeDepth);
  308. Ret.CustomStencil = CustomStencil;
  309. Ret.Depth = SceneDepth;
  310. return Ret;
  311. }
  312. #if FEATURE_LEVEL >= FEATURE_LEVEL_SM5
  313. // @param PixelPos relative to left top of the rendertarget (not viewport)
  314. FGBufferData DecodeGBufferDataUV(float2 UV, bool bGetNormalizedNormal = true)
  315. {
  316. float CustomNativeDepth = Texture2DSampleLevel(SceneTexturesStruct.CustomDepthTexture, SceneTexturesStruct_CustomDepthTextureSampler, UV, 0).r;
  317. int2 IntUV = (int2)trunc(UV * View.BufferSizeAndInvSize.xy * View.BufferToSceneTextureScale.xy);
  318. uint CustomStencil = SceneTexturesStruct.CustomStencilTexture.Load(int3(IntUV, 0)) STENCIL_COMPONENT_SWIZZLE;
  319. float SceneDepth = CalcSceneDepth(UV);
  320. float4 AnisotropicData = Texture2DSampleLevel(SceneTexturesStruct.GBufferFTexture, SceneTexturesStruct_GBufferFTextureSampler, UV, 0).xyzw;
  321. float4 InMRT1 = Texture2DSampleLevel(SceneTexturesStruct.GBufferATexture, SceneTexturesStruct_GBufferATextureSampler, UV, 0).xyzw;
  322. float4 InMRT2 = Texture2DSampleLevel(SceneTexturesStruct.GBufferBTexture, SceneTexturesStruct_GBufferBTextureSampler, UV, 0).xyzw;
  323. float4 InMRT3 = Texture2DSampleLevel(SceneTexturesStruct.GBufferCTexture, SceneTexturesStruct_GBufferCTextureSampler, UV, 0).xyzw;
  324. float4 InMRT4 = Texture2DSampleLevel(SceneTexturesStruct.GBufferVelocityTexture, SceneTexturesStruct_GBufferVelocityTextureSampler, UV, 0).xyzw;
  325. float4 InMRT5 = Texture2DSampleLevel(SceneTexturesStruct.GBufferDTexture, SceneTexturesStruct_GBufferDTextureSampler, UV, 0).xyzw;
  326. float4 InMRT6 = Texture2DSampleLevel(SceneTexturesStruct.GBufferETexture, SceneTexturesStruct_GBufferETextureSampler, UV, 0).xyzw;
  327. FGBufferData Ret = DecodeGBufferDataDirect(InMRT1,
  328. InMRT2,
  329. InMRT3,
  330. InMRT4,
  331. InMRT5,
  332. InMRT6,
  333. CustomNativeDepth,
  334. AnisotropicData,
  335. CustomStencil,
  336. SceneDepth,
  337. bGetNormalizedNormal,
  338. CheckerFromSceneColorUV(UV));
  339. return Ret;
  340. }
  341. // @param PixelPos relative to left top of the rendertarget (not viewport)
  342. FGBufferData DecodeGBufferDataUint(uint2 PixelPos, bool bGetNormalizedNormal = true)
  343. {
  344. float CustomNativeDepth = SceneTexturesStruct.CustomDepthTexture.Load(int3(PixelPos, 0)).r;
  345. uint CustomStencil = SceneTexturesStruct.CustomStencilTexture.Load(int3(PixelPos, 0)) STENCIL_COMPONENT_SWIZZLE;
  346. float SceneDepth = CalcSceneDepth(PixelPos);
  347. float4 AnisotropicData = SceneTexturesStruct.GBufferFTexture.Load(int3(PixelPos, 0)).xyzw;
  348. float4 InMRT1 = SceneTexturesStruct.GBufferATexture.Load(int3(PixelPos, 0)).xyzw;
  349. float4 InMRT2 = SceneTexturesStruct.GBufferBTexture.Load(int3(PixelPos, 0)).xyzw;
  350. float4 InMRT3 = SceneTexturesStruct.GBufferCTexture.Load(int3(PixelPos, 0)).xyzw;
  351. float4 InMRT4 = SceneTexturesStruct.GBufferVelocityTexture.Load(int3(PixelPos, 0)).xyzw;
  352. float4 InMRT5 = SceneTexturesStruct.GBufferDTexture.Load(int3(PixelPos, 0)).xyzw;
  353. float4 InMRT6 = SceneTexturesStruct.GBufferETexture.Load(int3(PixelPos, 0)).xyzw;
  354. FGBufferData Ret = DecodeGBufferDataDirect(InMRT1,
  355. InMRT2,
  356. InMRT3,
  357. InMRT4,
  358. InMRT5,
  359. InMRT6,
  360. CustomNativeDepth,
  361. AnisotropicData,
  362. CustomStencil,
  363. SceneDepth,
  364. bGetNormalizedNormal,
  365. CheckerFromPixelPos(PixelPos));
  366. return Ret;
  367. }
  368. // @param PixelPos relative to left top of the rendertarget (not viewport)
  369. FGBufferData DecodeGBufferDataSceneTextures(float2 UV, bool bGetNormalizedNormal = true)
  370. {
  371. uint CustomStencil = 0;
  372. float CustomNativeDepth = 0;
  373. float DeviceZ = SampleDeviceZFromSceneTexturesTempCopy(UV);
  374. float SceneDepth = ConvertFromDeviceZ(DeviceZ);
  375. float4 AnisotropicData = GBufferFTexture.SampleLevel(GBufferFTextureSampler, UV, 0).xyzw;
  376. float4 InMRT1 = GBufferATexture.SampleLevel(GBufferATextureSampler, UV, 0).xyzw;
  377. float4 InMRT2 = GBufferBTexture.SampleLevel(GBufferBTextureSampler, UV, 0).xyzw;
  378. float4 InMRT3 = GBufferCTexture.SampleLevel(GBufferCTextureSampler, UV, 0).xyzw;
  379. float4 InMRT4 = GBufferVelocityTexture.SampleLevel(GBufferVelocityTextureSampler, UV, 0).xyzw;
  380. float4 InMRT5 = GBufferDTexture.SampleLevel(GBufferDTextureSampler, UV, 0).xyzw;
  381. float4 InMRT6 = GBufferETexture.SampleLevel(GBufferETextureSampler, UV, 0).xyzw;
  382. FGBufferData Ret = DecodeGBufferDataDirect(InMRT1,
  383. InMRT2,
  384. InMRT3,
  385. InMRT4,
  386. InMRT5,
  387. InMRT6,
  388. CustomNativeDepth,
  389. AnisotropicData,
  390. CustomStencil,
  391. SceneDepth,
  392. bGetNormalizedNormal,
  393. CheckerFromSceneColorUV(UV));
  394. return Ret;
  395. }
  396. // @param PixelPos relative to left top of the rendertarget (not viewport)
  397. FGBufferData DecodeGBufferDataSceneTexturesLoad(uint2 PixelCoord, bool bGetNormalizedNormal = true)
  398. {
  399. uint CustomStencil = 0;
  400. float CustomNativeDepth = 0;
  401. float DeviceZ = SceneDepthTexture.Load(int3(PixelCoord, 0)).r;
  402. float SceneDepth = ConvertFromDeviceZ(DeviceZ);
  403. float4 AnisotropicData = GBufferFTexture.Load(int3(PixelCoord, 0)).xyzw;
  404. float4 InMRT1 = GBufferATexture.Load(int3(PixelCoord, 0)).xyzw;
  405. float4 InMRT2 = GBufferBTexture.Load(int3(PixelCoord, 0)).xyzw;
  406. float4 InMRT3 = GBufferCTexture.Load(int3(PixelCoord, 0)).xyzw;
  407. float4 InMRT4 = GBufferVelocityTexture.Load(int3(PixelCoord, 0)).xyzw;
  408. float4 InMRT5 = GBufferDTexture.Load(int3(PixelCoord, 0)).xyzw;
  409. float4 InMRT6 = GBufferETexture.Load(int3(PixelCoord, 0)).xyzw;
  410. FGBufferData Ret = DecodeGBufferDataDirect(InMRT1,
  411. InMRT2,
  412. InMRT3,
  413. InMRT4,
  414. InMRT5,
  415. InMRT6,
  416. CustomNativeDepth,
  417. AnisotropicData,
  418. CustomStencil,
  419. SceneDepth,
  420. bGetNormalizedNormal,
  421. CheckerFromPixelPos(PixelCoord));
  422. return Ret;
  423. }
  424. #endif
  425. #endif