Merge pull request #12175 from Sam-Belliveau/correct-area-sampling

Corrected Area Sampling Range
This commit is contained in:
Admiral H. Curtiss 2023-11-15 01:49:45 +01:00 committed by GitHub
commit 6309aa0010
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 11 deletions

View File

@ -199,15 +199,16 @@ float4 AreaSampling(float3 uvw, float gamma)
{ {
// Determine the sizes of the source and target images. // Determine the sizes of the source and target images.
float2 source_size = GetResolution(); float2 source_size = GetResolution();
float2 target_size = GetWindowResolution();
float2 inverted_target_size = GetInvWindowResolution(); float2 inverted_target_size = GetInvWindowResolution();
// Determine the range of the source image that the target pixel will cover. // Compute the top-left and bottom-right corners of the target pixel box.
// Workaround: shift the resolution by 1/4 pixel to align the results with other sampling algorithms, float2 t_beg = floor(uvw.xy * target_size);
// otherwise the results would be offsetted, and we'd be sampling from coordinates outside the valid range. float2 t_end = t_beg + float2(1.0, 1.0);
float2 adjusted_source_size = source_size - 0.25;
float2 range = adjusted_source_size * inverted_target_size; // Convert the target pixel box to source pixel box.
float2 beg = (uvw.xy * adjusted_source_size) - (range * 0.5); float2 beg = t_beg * inverted_target_size * source_size;
float2 end = beg + range; float2 end = t_end * inverted_target_size * source_size;
// Compute the top-left and bottom-right corners of the pixel box. // Compute the top-left and bottom-right corners of the pixel box.
float2 f_beg = floor(beg); float2 f_beg = floor(beg);
@ -238,8 +239,8 @@ float4 AreaSampling(float3 uvw, float gamma)
avg_color += area_se * QuickSampleByPixel(float2(f_end.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. // Determine the size of the pixel box.
int x_range = int(f_end.x - f_beg.x + 0.5); int x_range = int(f_end.x - f_beg.x - 0.5);
int y_range = int(f_end.y - f_beg.y + 0.5); int y_range = int(f_end.y - f_beg.y - 0.5);
// Workaround to compile the shader with DX11/12. // Workaround to compile the shader with DX11/12.
// If this isn't done, it will complain that the loop could have too many iterations. // If this isn't done, it will complain that the loop could have too many iterations.