@@ -2622,7 +2622,7 @@ void PostProcessManager::TaaJitterCamera(
2622
2622
current.projection = inoutCameraInfo->projection * inoutCameraInfo->getUserViewMatrix ();
2623
2623
current.frameId = previous.frameId + 1 ;
2624
2624
2625
- auto jitterPosition = [pattern = taaOptions.jitterPattern ](size_t frameIndex){
2625
+ auto jitterPosition = [pattern = taaOptions.jitterPattern ](size_t frameIndex) -> float2 {
2626
2626
using JitterPattern = TemporalAntiAliasingOptions::JitterPattern;
2627
2627
switch (pattern) {
2628
2628
case JitterPattern::RGSS_X4:
@@ -2636,6 +2636,7 @@ void PostProcessManager::TaaJitterCamera(
2636
2636
case JitterPattern::HALTON_23_X32:
2637
2637
return sHaltonSamples (frameIndex);
2638
2638
}
2639
+ return { 0 .0f , 0 .0f };
2639
2640
};
2640
2641
2641
2642
// sample position within a pixel [-0.5, 0.5]
@@ -2759,15 +2760,31 @@ FrameGraphId<FrameGraphTexture> PostProcessManager::taa(FrameGraph& fg,
2759
2760
}};
2760
2761
2761
2762
constexpr float2 sampleOffsets[9 ] = {
2762
- { -1 .0f , -1 .0f }, { 0 .0f , -1 .0f }, { 1 .0f , -1 .0f },
2763
- { - 1 . 0f , 0 . 0f }, { 0 . 0f , 0 . 0f }, { 1 .0f , 0 .0f },
2764
- { -1 .0f , 1 .0f }, { 0 .0f , 1 .0f }, { 1 .0f , 1 .0f },
2763
+ { -1 .0f , -1 .0f }, { 0 .0f , -1 .0f }, { 1 .0f , -1 .0f }, { - 1 . 0f , 0 . 0f },
2764
+ { 0 .0f , 0 .0f },
2765
+ { 1 . 0f , 0 . 0f }, { -1 .0f , 1 .0f }, { 0 .0f , 1 .0f }, { 1 .0f , 1 .0f },
2765
2766
};
2766
2767
2767
2768
constexpr float2 subSampleOffsets[4 ] = {
2768
- { -0 .25f , 0 .25f }, { 0 .25f , 0 .25f }, { 0 .25f , -0 .25f }, { -0 .25f , -0 .25f }
2769
+ { -0 .25f , 0 .25f },
2770
+ { 0 .25f , 0 .25f },
2771
+ { 0 .25f , -0 .25f },
2772
+ { -0 .25f , -0 .25f }
2769
2773
};
2770
2774
2775
+ UTILS_UNUSED
2776
+ auto const lanczos = [](float x, float a) -> float {
2777
+ if (x <= std::numeric_limits<float >::epsilon ()) {
2778
+ return 1 .0f ;
2779
+ }
2780
+ if (std::abs (x) <= a) {
2781
+ return (a * std::sin (f::PI * x) * std::sin (f::PI * x / a))
2782
+ / ((f::PI * f::PI) * (x * x));
2783
+ }
2784
+ return 0 .0f ;
2785
+ };
2786
+
2787
+ float const filterWidth = std::clamp (taaOptions.filterWidth , 1 .0f , 2 .0f );
2771
2788
float4 sum = 0.0 ;
2772
2789
float4 weights[9 ];
2773
2790
@@ -2777,11 +2794,9 @@ FrameGraphId<FrameGraphTexture> PostProcessManager::taa(FrameGraph& fg,
2777
2794
for (size_t i = 0 ; i < 9 ; i++) {
2778
2795
float2 const o = sampleOffsets[i];
2779
2796
for (size_t j = 0 ; j < 4 ; j++) {
2780
- float2 const s = taaOptions.upscaling ? subSampleOffsets[j] : float2{ 0 };
2781
- float2 const d = (o - current.jitter - s) / taaOptions.filterWidth ;
2782
- // This is a gaussian fit of a 3.3-wide Blackman-Harris window
2783
- // see: "High Quality Temporal Supersampling" by Brian Karis
2784
- weights[i][j] = std::exp (-2 .29f * (d.x * d.x + d.y * d.y ));
2797
+ float2 const subPixelOffset = taaOptions.upscaling ? subSampleOffsets[j] : float2{ 0 };
2798
+ float2 const d = (o - (current.jitter - subPixelOffset)) / filterWidth;
2799
+ weights[i][j] = lanczos (length (d), filterWidth);
2785
2800
}
2786
2801
sum += weights[i];
2787
2802
}
0 commit comments