Files
test/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h
Omar Emara 1bff17cc99 Compositor: Unify plane anti-aliasing between CPU and GPU
This patch unifies the anti-aliasing of plane deforms between the CPU
and GPU compositors. The CPU used a multi-sample approach, where the
mask was computed 8 times with a jitter, then averaged to get smooth
edges. The GPU relied on the anisotropic filtering with zero boundaries
to smooth the edges.

Furthermore, the CPU implementation ignored the anti-aliasing for the
deformed image and also relied anisotropic filtering like the GPU, so
its outputs were different.

To unify both implementation, we use the existing SMAA anti-aliasing
algorithm instead, and use the anti-aliased mask for the image output as
well. This affects both the Corner Pin and Plane Deform nodes.

A consequence of this change for the Plane Deform node is that motion
blur will appear to have less samples, that's because it was sampled
8-times more in the previous implementation. But users can just increase
the samples in the node to account for that.

Pull Request: https://projects.blender.org/blender/blender/pulls/118853
2024-02-29 12:30:16 +01:00

72 lines
1.9 KiB
C++

/* SPDX-FileCopyrightText: 2013 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include <string.h>
#include "COM_MultiThreadedOperation.h"
#include "DNA_movieclip_types.h"
#include "DNA_tracking_types.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
namespace blender::compositor {
#define PLANE_DISTORT_MAX_SAMPLES 64
class PlaneDistortBaseOperation : public MultiThreadedOperation {
protected:
struct MotionSample {
float frame_space_corners[4][2]; /* Corners coordinates in pixel space. */
float perspective_matrix[3][3];
};
MotionSample samples_[PLANE_DISTORT_MAX_SAMPLES];
int motion_blur_samples_;
float motion_blur_shutter_;
public:
PlaneDistortBaseOperation();
void set_motion_blur_samples(int samples)
{
BLI_assert(samples <= PLANE_DISTORT_MAX_SAMPLES);
motion_blur_samples_ = samples;
}
void set_motion_blur_shutter(float shutter)
{
motion_blur_shutter_ = shutter;
}
virtual void calculate_corners(const float corners[4][2], bool normalized, int sample);
private:
friend class PlaneTrackCommon;
};
class PlaneDistortWarpImageOperation : public PlaneDistortBaseOperation {
public:
PlaneDistortWarpImageOperation();
void calculate_corners(const float corners[4][2], bool normalized, int sample) override;
void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override;
void update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> inputs) override;
};
class PlaneDistortMaskOperation : public PlaneDistortBaseOperation {
public:
PlaneDistortMaskOperation();
void update_memory_buffer_partial(MemoryBuffer *output,
const rcti &area,
Span<MemoryBuffer *> inputs) override;
};
} // namespace blender::compositor