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