fixed area sampling

This commit is contained in:
Sam Belliveau 2023-08-21 14:20:44 -04:00
parent 3451cb1ca2
commit d4f8c1b2bd
1 changed files with 9 additions and 8 deletions

View File

@ -199,15 +199,16 @@ float4 AreaSampling(float3 uvw, float gamma)
{
// Determine the sizes of the source and target images.
float2 source_size = GetResolution();
float2 target_size = GetWindowResolution();
float2 inverted_target_size = GetInvWindowResolution();
// Determine the range of the source image that the target pixel will cover.
// Workaround: shift the resolution by 1/4 pixel to align the results with other sampling algorithms,
// otherwise the results would be offsetted, and we'd be sampling from coordinates outside the valid range.
float2 adjusted_source_size = source_size - 0.25;
float2 range = adjusted_source_size * inverted_target_size;
float2 beg = (uvw.xy * adjusted_source_size) - (range * 0.5);
float2 end = beg + range;
// Compute the top-left and bottom-right corners of the target pixel box.
float2 t_beg = floor(uvw.xy * target_size);
float2 t_end = t_beg + float2(1.0, 1.0);
// Convert the target pixel box to source pixel box.
float2 beg = t_beg * inverted_target_size * source_size;
float2 end = t_end * inverted_target_size * source_size;
// Compute the top-left and bottom-right corners of the pixel box.
float2 f_beg = floor(beg);
@ -236,7 +237,7 @@ float4 AreaSampling(float3 uvw, float gamma)
avg_color += area_ne * QuickSampleByPixel(float2(f_end.x, f_beg.y) + offset, uvw.z, gamma);
avg_color += area_sw * QuickSampleByPixel(float2(f_beg.x, f_end.y) + offset, uvw.z, gamma);
avg_color += area_se * QuickSampleByPixel(float2(f_end.x, f_end.y) + offset, uvw.z, gamma);
// Determine the size of the pixel box.
int x_range = int(f_end.x - f_beg.x + 0.5);
int y_range = int(f_end.y - f_beg.y + 0.5);