@@ -28,49 +28,37 @@ Texture2D<float2> g_TextureMotion;
2828Texture2D <float2 > g_TextureBlueNoise;
2929Texture2D <float > g_TextureDepthHierarchy;
3030
31- SamplerState g_TextureDepthHierarchy_sampler;
32-
33- float3 ScreenSpaceToViewSpace (float3 ScreenCoordUV)
34- {
35- return InvProjectPosition (ScreenCoordUV, g_Camera.mProjInv);
36- }
37-
38- float3 ScreenSpaceToWorldSpace (float3 ScreenCoordUV)
39- {
40- return InvProjectPosition (ScreenCoordUV, g_Camera.mViewProjInv);
41- }
42-
4331float2 GetMipResolution (float2 ScreenDimensions, int MipLevel)
4432{
4533 return ScreenDimensions * rcp (float (1 << MipLevel));
4634}
4735
48- float2 SampleRandomVector2D (int2 PixelCoord)
36+ float2 LoadRandomVector2D (int2 PixelCoord)
4937{
5038 return g_TextureBlueNoise.Load (int3 (PixelCoord & 127 , 0 ));
5139}
5240
53- float SampleRoughness (int2 PixelCoord)
41+ float LoadRoughness (int2 PixelCoord)
5442{
5543 return g_TextureRoughness.Load (int3 (PixelCoord, 0 ));
5644}
5745
58- float3 SampleNormalWS (int2 PixelCoord)
46+ float3 LoadNormalWS (int2 PixelCoord)
5947{
6048 return g_TextureNormal.Load (int3 (PixelCoord, 0 ));
6149}
6250
63- float SampleDepthHierarchy (int2 PixelCoord, int MipLevel)
51+ float LoadDepthHierarchy (int2 PixelCoord, int MipLevel)
6452{
6553 return g_TextureDepthHierarchy.Load (int3 (PixelCoord, MipLevel));
6654}
6755
68- float2 SampleMotion (int2 PixelCoord)
56+ float2 LoadMotion (int2 PixelCoord)
6957{
7058 return g_TextureMotion.Load (int3 (PixelCoord, 0 )) * F3NDC_XYZ_TO_UVD_SCALE.xy;
7159}
7260
73- float3 SampleRadiance (int2 PixelCoord)
61+ float3 LoadRadiance (int2 PixelCoord)
7462{
7563 return g_TextureRadiance.Load (int3 (PixelCoord, 0 ));
7664}
@@ -182,7 +170,7 @@ float3 HierarchicalRaymarch(float3 Origin, float3 Direction, float2 ScreenSize,
182170 while (Idx < MaxTraversalIntersections && CurrentMip >= MostDetailedMip)
183171 {
184172 float2 CurrentMipPosition = CurrentMipResolution * Position.xy;
185- float SurfaceDepth = SampleDepthHierarchy (int2 (CurrentMipPosition), CurrentMip);
173+ float SurfaceDepth = LoadDepthHierarchy (int2 (CurrentMipPosition), CurrentMip);
186174 bool SkippedTile = AdvanceRay (Origin, Direction, InvDirection, CurrentMipPosition, InvCurrentMipResolution, FloorOffset, UVOffset, SurfaceDepth, Position, CurrentT);
187175
188176 // Don't increase mip further than this because we did not generate it
@@ -224,13 +212,13 @@ float ValidateHit(float3 Hit, float2 ScreenCoordUV, float3 RayDirectionWS, float
224212
225213 // Don't lookup radiance from the background.
226214 int2 TexelCoords = int2 (ScreenSize * Hit.xy);
227- float SurfaceDepth = SampleDepthHierarchy (TexelCoords, 0 );
215+ float SurfaceDepth = LoadDepthHierarchy (TexelCoords, 0 );
228216
229217 if (IsBackground (SurfaceDepth))
230218 return 0.0 ;
231219
232220 // We check if we hit the surface from the back, these should be rejected.
233- float3 HitNormalWS = SampleNormalWS (TexelCoords);
221+ float3 HitNormalWS = LoadNormalWS (TexelCoords);
234222 if (dot (HitNormalWS, RayDirectionWS) > 0.0 )
235223 return 0.0 ;
236224
@@ -271,7 +259,7 @@ float4 SampleReflectionVector(float3 View, float3 Normal, float Roughness, int2
271259 float3 B = cross (T, N);
272260 float3x3 TangentToWorld = MatrixFromRows (T, B, N);
273261
274- float2 Xi = SampleRandomVector2D (PixelCoord);
262+ float2 Xi = LoadRandomVector2D (PixelCoord);
275263 Xi.y = lerp (Xi.y, 0.0 , g_SSRAttribs.GGXImportanceSampleBias);
276264
277265 float3 ViewDirTS = mul (TangentToWorld, View);
@@ -300,15 +288,15 @@ PSOutput ComputeIntersectionPS(in FullScreenTriangleVSOutput VSOut)
300288#endif
301289
302290 float2 ScreenCoordUV = Position * g_Camera.f4ViewportSize.zw;
303- float3 NormalWS = SampleNormalWS (int2 (Position));
291+ float3 NormalWS = LoadNormalWS (int2 (Position));
304292 float3 NormalVS = mul (float4 (NormalWS, 0.0 ), g_Camera.mView).xyz;
305- float Roughness = SampleRoughness (int2 (Position));
293+ float Roughness = LoadRoughness (int2 (Position));
306294
307295 bool IsMirror = IsMirrorReflection (Roughness);
308296 int MostDetailedMip = IsMirror ? 0 : int (g_SSRAttribs.MostDetailedMip);
309297 float2 MipResolution = GetMipResolution (g_Camera.f4ViewportSize.xy, MostDetailedMip);
310298
311- float3 RayOriginSS = float3 (ScreenCoordUV, SampleDepthHierarchy (int2 (ScreenCoordUV * MipResolution), MostDetailedMip));
299+ float3 RayOriginSS = float3 (ScreenCoordUV, LoadDepthHierarchy (int2 (ScreenCoordUV * MipResolution), MostDetailedMip));
312300 float3 RayOriginVS = ScreenXYDepthToViewSpace (RayOriginSS, g_Camera.mProj);
313301
314302 float4 RayDirectionVS = SampleReflectionVector (-normalize (RayOriginVS), NormalVS, Roughness, int2 (VSOut.f4PixelPos.xy));
@@ -320,13 +308,13 @@ PSOutput ComputeIntersectionPS(in FullScreenTriangleVSOutput VSOut)
320308 float3 SurfaceHitVS = ScreenXYDepthToViewSpace (SurfaceHitSS, g_Camera.mProj);
321309
322310#if SSR_OPTION_PREVIOUS_FRAME
323- float2 Motion = SampleMotion (int2 (g_Camera.f4ViewportSize.xy * SurfaceHitSS.xy));
311+ float2 Motion = LoadMotion (int2 (g_Camera.f4ViewportSize.xy * SurfaceHitSS.xy));
324312 float2 SurfaceHitSSPrev = SurfaceHitSS.xy - Motion;
325313 float Confidence = ValidHit ? ValidateHit (SurfaceHitSS, SurfaceHitSSPrev, ScreenCoordUV, RayDirectionWS, g_Camera.f4ViewportSize.xy, g_SSRAttribs.DepthBufferThickness) : 0.0 ;
326- float3 ReflectionRadiance = Confidence > 0.0f ? SampleRadiance (int2 (g_Camera.f4ViewportSize.xy * SurfaceHitSSPrev)) : float3 (0.0 , 0.0 , 0.0 );
314+ float3 ReflectionRadiance = Confidence > 0.0f ? LoadRadiance (int2 (g_Camera.f4ViewportSize.xy * SurfaceHitSSPrev)) : float3 (0.0 , 0.0 , 0.0 );
327315#else
328316 float Confidence = ValidHit ? ValidateHit (SurfaceHitSS, ScreenCoordUV, RayDirectionWS, g_Camera.f4ViewportSize.xy, g_SSRAttribs.DepthBufferThickness) : 0.0 ;
329- float3 ReflectionRadiance = Confidence > 0.0f ? SampleRadiance (int2 (g_Camera.f4ViewportSize.xy * SurfaceHitSS.xy)) : float3 (0.0 , 0.0 , 0.0 );
317+ float3 ReflectionRadiance = Confidence > 0.0f ? LoadRadiance (int2 (g_Camera.f4ViewportSize.xy * SurfaceHitSS.xy)) : float3 (0.0 , 0.0 , 0.0 );
330318#endif
331319
332320 //TODO: Try to store inverse RayDirectionWS for more accuracy.
0 commit comments