Fix #123607: Plane Track Deform produces wrong output

The Plane Track Deform node produces wrong outputs in the GPU compositor
in case the input size was different from the movie size. That's because
the coordinates were normalized based on the input size, while they
should be normalized based on the output size, which is what this
patches does.
This commit is contained in:
Omar Emara
2024-06-25 16:37:18 +03:00
parent 583ad3460a
commit f19a9e9b4d
2 changed files with 12 additions and 12 deletions

View File

@@ -7,19 +7,19 @@
void main()
{
ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
vec2 input_size = vec2(texture_size(input_tx));
vec2 output_size = vec2(imageSize(output_img));
vec2 coordinates = (vec2(texel) + vec2(0.5)) / input_size;
vec2 coordinates = (vec2(texel) + vec2(0.5)) / output_size;
vec3 transformed_coordinates = mat3(homography_matrix) * vec3(coordinates, 1.0);
vec2 projected_coordinates = transformed_coordinates.xy / transformed_coordinates.z;
/* The derivatives of the projected coordinates with respect to x and y are the first and
* second columns respectively, divided by the z projection factor as can be shown by
* differentiating the above matrix multiplication with respect to x and y. Divide by the input
* size since textureGrad assumes derivatives with respect to texel coordinates. */
vec2 x_gradient = (homography_matrix[0].xy / transformed_coordinates.z) / input_size.x;
vec2 y_gradient = (homography_matrix[1].xy / transformed_coordinates.z) / input_size.y;
* differentiating the above matrix multiplication with respect to x and y. Divide by the
* output size since textureGrad assumes derivatives with respect to texel coordinates. */
vec2 x_gradient = (homography_matrix[0].xy / transformed_coordinates.z) / output_size.x;
vec2 y_gradient = (homography_matrix[1].xy / transformed_coordinates.z) / output_size.y;
vec4 sampled_color = textureGrad(input_tx, projected_coordinates, x_gradient, y_gradient);

View File

@@ -7,9 +7,9 @@
void main()
{
ivec2 texel = ivec2(gl_GlobalInvocationID.xy);
vec2 input_size = vec2(texture_size(input_tx));
vec2 output_size = vec2(imageSize(output_img));
vec2 coordinates = (vec2(texel) + vec2(0.5)) / input_size;
vec2 coordinates = (vec2(texel) + vec2(0.5)) / output_size;
vec4 accumulated_color = vec4(0.0);
for (int i = 0; i < number_of_motion_blur_samples; i++) {
@@ -20,10 +20,10 @@ void main()
/* The derivatives of the projected coordinates with respect to x and y are the first and
* second columns respectively, divided by the z projection factor as can be shown by
* differentiating the above matrix multiplication with respect to x and y. Divide by the input
* size since textureGrad assumes derivatives with respect to texel coordinates. */
vec2 x_gradient = (homography_matrix[0].xy / transformed_coordinates.z) / input_size.x;
vec2 y_gradient = (homography_matrix[1].xy / transformed_coordinates.z) / input_size.y;
* differentiating the above matrix multiplication with respect to x and y. Divide by the
* output size since textureGrad assumes derivatives with respect to texel coordinates. */
vec2 x_gradient = (homography_matrix[0].xy / transformed_coordinates.z) / output_size.x;
vec2 y_gradient = (homography_matrix[1].xy / transformed_coordinates.z) / output_size.y;
vec4 sampled_color = textureGrad(input_tx, projected_coordinates, x_gradient, y_gradient);
accumulated_color += sampled_color;