tornavis/source/blender/compositor/nodes/COM_AntiAliasingNode.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

48 lines
1.7 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2017 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "COM_AntiAliasingNode.h"
#include "COM_SMAAOperation.h"
2021-03-23 17:12:27 +01:00
namespace blender::compositor {
Compositor: Port GLSL SMAA to CPU compositor This patch ports the GLSL SMAA library to the CPU compositor in order to unify the anti-aliasing behavior between the CPU and GPU compositor. Additionally, the SMAA texture generator was removed since it is now unused. Previously, we used an external C++ library for SMAA anti-aliasing, which is itself a port of the GLSL SMAA library. However, the code structure and results of the library were different, which made it quite difficult to match results between CPU and GPU, hence the decision to port the library ourselves. The port was performed through a complete copy of the library to C++, retaining the same function and variable names, even if they are different from Blender's naming conversions. The necessary code changes were done to make it work in C++, including manually doing swizzling which changes the code structure a bit. Even after porting the library, there were still major differences between CPU and GPU, due to different arithmetic precision. To fix this some of the bilinear samplers used in branches and selections were carefully changed to use point samplers to avoid discontinuities around branches, also resulting in a nice performance improvement. Some slight differences still exist due to different bilinear interpolation, but they shall be looked into later once we have a baseline implementation. The new implementation is slower than the existing implementation, most likely due to the liberal use of bilinear interpolation, since it is quite cheap on GPUs and the code even does more work to use bilinear interpolation to avoid multiple texture fetches, except this causes a slow down on CPUs. Some of those were alleviated as mentioned in the previous section, but we can probably look into optimizing it further. Pull Request: https://projects.blender.org/blender/blender/pulls/119414
2024-03-25 14:21:00 +01:00
/* Blender encodes the threshold in the [0, 1] range, while the SMAA algorithm expects it in
* the [0, 0.5] range. */
static float get_threshold(const NodeAntiAliasingData *data)
{
return data->threshold / 2.0f;
}
/* Blender encodes the local contrast adaptation factor in the [0, 1] range, while the SMAA
* algorithm expects it in the [0, 10] range. */
static float get_local_contrast_adaptation_factor(const NodeAntiAliasingData *data)
{
return data->contrast_limit * 10.0f;
}
/* Blender encodes the corner rounding factor in the float [0, 1] range, while the SMAA algorithm
* expects it in the integer [0, 100] range. */
static int get_corner_rounding(const NodeAntiAliasingData *data)
{
return int(data->corner_rounding * 100.0f);
}
void AntiAliasingNode::convert_to_operations(NodeConverter &converter,
const CompositorContext & /*context*/) const
{
const bNode *node = this->get_bnode();
const NodeAntiAliasingData *data = (const NodeAntiAliasingData *)node->storage;
Compositor: Port GLSL SMAA to CPU compositor This patch ports the GLSL SMAA library to the CPU compositor in order to unify the anti-aliasing behavior between the CPU and GPU compositor. Additionally, the SMAA texture generator was removed since it is now unused. Previously, we used an external C++ library for SMAA anti-aliasing, which is itself a port of the GLSL SMAA library. However, the code structure and results of the library were different, which made it quite difficult to match results between CPU and GPU, hence the decision to port the library ourselves. The port was performed through a complete copy of the library to C++, retaining the same function and variable names, even if they are different from Blender's naming conversions. The necessary code changes were done to make it work in C++, including manually doing swizzling which changes the code structure a bit. Even after porting the library, there were still major differences between CPU and GPU, due to different arithmetic precision. To fix this some of the bilinear samplers used in branches and selections were carefully changed to use point samplers to avoid discontinuities around branches, also resulting in a nice performance improvement. Some slight differences still exist due to different bilinear interpolation, but they shall be looked into later once we have a baseline implementation. The new implementation is slower than the existing implementation, most likely due to the liberal use of bilinear interpolation, since it is quite cheap on GPUs and the code even does more work to use bilinear interpolation to avoid multiple texture fetches, except this causes a slow down on CPUs. Some of those were alleviated as mentioned in the previous section, but we can probably look into optimizing it further. Pull Request: https://projects.blender.org/blender/blender/pulls/119414
2024-03-25 14:21:00 +01:00
SMAAOperation *operation = new SMAAOperation();
operation->set_threshold(get_threshold(data));
operation->set_local_contrast_adaptation_factor(get_local_contrast_adaptation_factor(data));
operation->set_corner_rounding(get_corner_rounding(data));
converter.add_operation(operation);
Compositor: Port GLSL SMAA to CPU compositor This patch ports the GLSL SMAA library to the CPU compositor in order to unify the anti-aliasing behavior between the CPU and GPU compositor. Additionally, the SMAA texture generator was removed since it is now unused. Previously, we used an external C++ library for SMAA anti-aliasing, which is itself a port of the GLSL SMAA library. However, the code structure and results of the library were different, which made it quite difficult to match results between CPU and GPU, hence the decision to port the library ourselves. The port was performed through a complete copy of the library to C++, retaining the same function and variable names, even if they are different from Blender's naming conversions. The necessary code changes were done to make it work in C++, including manually doing swizzling which changes the code structure a bit. Even after porting the library, there were still major differences between CPU and GPU, due to different arithmetic precision. To fix this some of the bilinear samplers used in branches and selections were carefully changed to use point samplers to avoid discontinuities around branches, also resulting in a nice performance improvement. Some slight differences still exist due to different bilinear interpolation, but they shall be looked into later once we have a baseline implementation. The new implementation is slower than the existing implementation, most likely due to the liberal use of bilinear interpolation, since it is quite cheap on GPUs and the code even does more work to use bilinear interpolation to avoid multiple texture fetches, except this causes a slow down on CPUs. Some of those were alleviated as mentioned in the previous section, but we can probably look into optimizing it further. Pull Request: https://projects.blender.org/blender/blender/pulls/119414
2024-03-25 14:21:00 +01:00
converter.map_input_socket(get_input_socket(0), operation->get_input_socket(0));
converter.map_output_socket(get_output_socket(0), operation->get_output_socket());
}
2021-03-23 17:12:27 +01:00
} // namespace blender::compositor