@@ -10,76 +10,50 @@ cbuffer cbScreenSpaceReflectionAttribs
1010Texture2D <float > g_TextureRoughness;
1111Texture2D <float > g_TextureDepth;
1212
13- float SampleRoughness ( uint2 Location, uint2 Offset, uint2 Dimension )
13+ void UpdateClosestDepthAndMaxRoughness ( int2 Location, int2 Dimension, inout float MinDepth, inout float MaxRoughness )
1414{
15- uint2 Position = Location + Offset;
16- if (Position.x >= Dimension.x || Position.y >= Dimension.y)
17- {
18- return g_TextureRoughness.Load (int3 (Location, 0 ));
19- }
20- else
21- {
22- return g_TextureRoughness.Load (int3 (Position, 0 ));
23- }
24- }
15+ Location = ClampScreenCoord (Location, Dimension);
2516
26- float SampleDepth (uint2 Location, uint2 Offset, uint2 Dimension)
27- {
28- uint2 Position = Location + Offset;
29- if (Position.x >= Dimension.x || Position.y >= Dimension.y)
30- {
31- return g_TextureDepth.Load (int3 (Location, 0 ));
32- }
33- else
34- {
35- return g_TextureDepth.Load (int3 (Position, 0 ));
36- }
17+ float Depth = g_TextureDepth.Load (int3 (Location, 0 ));
18+ float Roughness = g_TextureRoughness.Load (int3 (Location, 0 ));
19+
20+ MinDepth = ClosestDepth (MinDepth, Depth);
21+ MaxRoughness = max (MaxRoughness, Roughness);
3722}
3823
3924void ComputeDownsampledStencilMaskPS (in FullScreenTriangleVSOutput VSOut)
4025{
41- uint2 RemappedPosition = uint2 (2.0 * floor (VSOut.f4PixelPos.xy));
26+ int2 RemappedPosition = int2 (2.0 * floor (VSOut.f4PixelPos.xy));
4227
43- uint2 TextureDimension;
28+ int2 TextureDimension;
4429 g_TextureDepth.GetDimensions (TextureDimension.x, TextureDimension.y);
4530
4631 float MinDepth = DepthFarPlane;
4732 float MaxRoughness = 0.0f ;
33+
34+ UpdateClosestDepthAndMaxRoughness (RemappedPosition + int2 (0 , 0 ), TextureDimension, MinDepth, MaxRoughness);
35+ UpdateClosestDepthAndMaxRoughness (RemappedPosition + int2 (1 , 0 ), TextureDimension, MinDepth, MaxRoughness);
36+ UpdateClosestDepthAndMaxRoughness (RemappedPosition + int2 (0 , 1 ), TextureDimension, MinDepth, MaxRoughness);
37+ UpdateClosestDepthAndMaxRoughness (RemappedPosition + int2 (1 , 1 ), TextureDimension, MinDepth, MaxRoughness);
4838
49- for (uint SampleIdx = 0u; SampleIdx < 4u; ++SampleIdx)
50- {
51- uint2 Offset = uint2 (SampleIdx & 0x01u, SampleIdx >> 1u);
52- MinDepth = ClosestDepth (MinDepth, SampleDepth (RemappedPosition, Offset, TextureDimension));
53- MaxRoughness = max (MaxRoughness, SampleRoughness (RemappedPosition, Offset, TextureDimension));
54- }
55-
56- bool IsWidthOdd = (TextureDimension.x & 1u) != 0u;
57- bool IsHeightOdd = (TextureDimension.y & 1u) != 0u;
39+ bool IsWidthOdd = (TextureDimension.x & 1 ) != 0 ;
40+ bool IsHeightOdd = (TextureDimension.y & 1 ) != 0 ;
5841
5942 if (IsWidthOdd)
6043 {
61- for (uint SampleIdx = 0u; SampleIdx < 2u; ++SampleIdx)
62- {
63- uint2 Offset = uint2 (2u, SampleIdx);
64- MinDepth = ClosestDepth (MinDepth, SampleDepth (RemappedPosition, Offset, TextureDimension));
65- MaxRoughness = max (MaxRoughness, SampleRoughness (RemappedPosition, Offset, TextureDimension));
66- }
44+ UpdateClosestDepthAndMaxRoughness (RemappedPosition + int2 (2 , 0 ), TextureDimension, MinDepth, MaxRoughness);
45+ UpdateClosestDepthAndMaxRoughness (RemappedPosition + int2 (2 , 1 ), TextureDimension, MinDepth, MaxRoughness);
6746 }
6847
6948 if (IsHeightOdd)
7049 {
71- for (uint SampleIdx = 0u; SampleIdx < 2u; ++SampleIdx)
72- {
73- uint2 Offset = uint2 (SampleIdx, 2 );
74- MinDepth = ClosestDepth (MinDepth, SampleDepth (RemappedPosition, Offset, TextureDimension));
75- MaxRoughness = max (MaxRoughness, SampleRoughness (RemappedPosition, Offset, TextureDimension));
76- }
50+ UpdateClosestDepthAndMaxRoughness (RemappedPosition + int2 (0 , 2 ), TextureDimension, MinDepth, MaxRoughness);
51+ UpdateClosestDepthAndMaxRoughness (RemappedPosition + int2 (1 , 2 ), TextureDimension, MinDepth, MaxRoughness);
7752 }
7853
7954 if (IsWidthOdd && IsHeightOdd)
8055 {
81- MinDepth = ClosestDepth (MinDepth, SampleDepth (RemappedPosition, uint2 (2 , 2 ), TextureDimension));
82- MaxRoughness = max (MaxRoughness, SampleRoughness (RemappedPosition, uint2 (2 , 2 ), TextureDimension));
56+ UpdateClosestDepthAndMaxRoughness (RemappedPosition + int2 (2 , 2 ), TextureDimension, MinDepth, MaxRoughness);
8357 }
8458
8559 if (!IsReflectionSample (MaxRoughness, MinDepth, g_SSRAttribs.RoughnessThreshold))
0 commit comments