fixed area sampling

This commit is contained in:
Sam Belliveau 2023-08-21 14:20:44 -04:00
parent 3451cb1ca2
commit d4f8c1b2bd

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);