2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
* Copyright 2019 Blender Foundation. */
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
|
|
|
|
|
#include "COM_DenoiseOperation.h"
|
2019-08-27 08:13:23 -06:00
|
|
|
#include "BLI_system.h"
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
#ifdef WITH_OPENIMAGEDENOISE
|
2019-08-27 11:06:48 +02:00
|
|
|
# include "BLI_threads.h"
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
# include <OpenImageDenoise/oidn.hpp>
|
2019-08-27 11:06:48 +02:00
|
|
|
static pthread_mutex_t oidn_lock = BLI_MUTEX_INITIALIZER;
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
#endif
|
|
|
|
|
|
2021-03-23 17:12:27 +01:00
|
|
|
namespace blender::compositor {
|
|
|
|
|
|
2021-09-19 20:12:53 +02:00
|
|
|
bool COM_is_denoise_supported()
|
|
|
|
|
{
|
|
|
|
|
#ifdef WITH_OPENIMAGEDENOISE
|
|
|
|
|
/* Always supported through Accelerate framework BNNS on macOS. */
|
|
|
|
|
# ifdef __APPLE__
|
|
|
|
|
return true;
|
|
|
|
|
# else
|
|
|
|
|
return BLI_cpu_support_sse41();
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class DenoiseFilter {
|
|
|
|
|
private:
|
|
|
|
|
#ifdef WITH_OPENIMAGEDENOISE
|
2021-10-23 20:52:30 +02:00
|
|
|
oidn::DeviceRef device_;
|
|
|
|
|
oidn::FilterRef filter_;
|
2021-09-19 20:12:53 +02:00
|
|
|
#endif
|
|
|
|
|
bool initialized_ = false;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
~DenoiseFilter()
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(!initialized_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_OPENIMAGEDENOISE
|
|
|
|
|
void init_and_lock_denoiser(MemoryBuffer *output)
|
|
|
|
|
{
|
|
|
|
|
/* Since it's memory intensive, it's better to run only one instance of OIDN at a time.
|
|
|
|
|
* OpenImageDenoise is multithreaded internally and should use all available cores
|
|
|
|
|
* nonetheless. */
|
|
|
|
|
BLI_mutex_lock(&oidn_lock);
|
|
|
|
|
|
2021-10-23 20:52:30 +02:00
|
|
|
device_ = oidn::newDevice();
|
|
|
|
|
device_.set("setAffinity", false);
|
|
|
|
|
device_.commit();
|
|
|
|
|
filter_ = device_.newFilter("RT");
|
2021-09-19 20:12:53 +02:00
|
|
|
initialized_ = true;
|
|
|
|
|
set_image("output", output);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deinit_and_unlock_denoiser()
|
|
|
|
|
{
|
|
|
|
|
BLI_mutex_unlock(&oidn_lock);
|
|
|
|
|
initialized_ = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_image(const StringRef name, MemoryBuffer *buffer)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(initialized_);
|
|
|
|
|
BLI_assert(!buffer->is_a_single_elem());
|
2021-10-23 20:52:30 +02:00
|
|
|
filter_.setImage(name.data(),
|
|
|
|
|
buffer->get_buffer(),
|
|
|
|
|
oidn::Format::Float3,
|
|
|
|
|
buffer->get_width(),
|
|
|
|
|
buffer->get_height(),
|
|
|
|
|
0,
|
|
|
|
|
buffer->get_elem_bytes_len());
|
2021-09-19 20:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T> void set(const StringRef option_name, T value)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(initialized_);
|
2021-10-23 20:52:30 +02:00
|
|
|
filter_.set(option_name.data(), value);
|
2021-09-19 20:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void execute()
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(initialized_);
|
2021-10-23 20:52:30 +02:00
|
|
|
filter_.commit();
|
|
|
|
|
filter_.execute();
|
2021-09-19 20:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
void init_and_lock_denoiser(MemoryBuffer *UNUSED(output))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void deinit_and_unlock_denoiser()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_image(const StringRef UNUSED(name), MemoryBuffer *UNUSED(buffer))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T> void set(const StringRef UNUSED(option_name), T UNUSED(value))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void execute()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DenoiseBaseOperation::DenoiseBaseOperation()
|
|
|
|
|
{
|
2021-10-13 23:01:53 +02:00
|
|
|
flags_.is_fullframe_operation = true;
|
2021-09-19 20:12:53 +02:00
|
|
|
output_rendered_ = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
bool DenoiseBaseOperation::determine_depending_area_of_interest(
|
|
|
|
|
rcti * /*input*/, ReadBufferOperation *read_operation, rcti *output)
|
2021-09-19 20:12:53 +02:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
if (is_cached()) {
|
2021-09-19 20:12:53 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
rcti new_input;
|
|
|
|
|
new_input.xmax = this->get_width();
|
|
|
|
|
new_input.xmin = 0;
|
|
|
|
|
new_input.ymax = this->get_height();
|
|
|
|
|
new_input.ymin = 0;
|
|
|
|
|
return NodeOperation::determine_depending_area_of_interest(&new_input, read_operation, output);
|
2021-09-19 20:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DenoiseBaseOperation::get_area_of_interest(const int UNUSED(input_idx),
|
|
|
|
|
const rcti &UNUSED(output_area),
|
|
|
|
|
rcti &r_input_area)
|
|
|
|
|
{
|
2021-09-28 19:32:49 +02:00
|
|
|
r_input_area = this->get_canvas();
|
2021-09-19 20:12:53 +02:00
|
|
|
}
|
|
|
|
|
|
2020-08-07 15:58:58 +02:00
|
|
|
DenoiseOperation::DenoiseOperation()
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
this->add_input_socket(DataType::Color);
|
|
|
|
|
this->add_input_socket(DataType::Vector);
|
|
|
|
|
this->add_input_socket(DataType::Color);
|
|
|
|
|
this->add_output_socket(DataType::Color);
|
2021-10-13 23:01:04 +02:00
|
|
|
settings_ = nullptr;
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
}
|
2021-10-13 23:01:15 +02:00
|
|
|
void DenoiseOperation::init_execution()
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
SingleThreadedOperation::init_execution();
|
|
|
|
|
input_program_color_ = get_input_socket_reader(0);
|
|
|
|
|
input_program_normal_ = get_input_socket_reader(1);
|
|
|
|
|
input_program_albedo_ = get_input_socket_reader(2);
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void DenoiseOperation::deinit_execution()
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
input_program_color_ = nullptr;
|
|
|
|
|
input_program_normal_ = nullptr;
|
|
|
|
|
input_program_albedo_ = nullptr;
|
|
|
|
|
SingleThreadedOperation::deinit_execution();
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-19 20:12:53 +02:00
|
|
|
static bool are_guiding_passes_noise_free(NodeDenoise *settings)
|
|
|
|
|
{
|
|
|
|
|
switch (settings->prefilter) {
|
|
|
|
|
case CMP_NODE_DENOISE_PREFILTER_NONE:
|
|
|
|
|
case CMP_NODE_DENOISE_PREFILTER_ACCURATE: /* Prefiltered with #DenoisePrefilterOperation. */
|
|
|
|
|
return true;
|
|
|
|
|
case CMP_NODE_DENOISE_PREFILTER_FAST:
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DenoiseOperation::hash_output_params()
|
|
|
|
|
{
|
2021-10-13 23:01:04 +02:00
|
|
|
if (settings_) {
|
|
|
|
|
hash_params((int)settings_->hdr, are_guiding_passes_noise_free(settings_));
|
2021-09-19 20:12:53 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
MemoryBuffer *DenoiseOperation::create_memory_buffer(rcti *rect2)
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
MemoryBuffer *tile_color = (MemoryBuffer *)input_program_color_->initialize_tile_data(rect2);
|
|
|
|
|
MemoryBuffer *tile_normal = (MemoryBuffer *)input_program_normal_->initialize_tile_data(rect2);
|
|
|
|
|
MemoryBuffer *tile_albedo = (MemoryBuffer *)input_program_albedo_->initialize_tile_data(rect2);
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
rcti rect;
|
|
|
|
|
rect.xmin = 0;
|
|
|
|
|
rect.ymin = 0;
|
2021-10-13 23:01:15 +02:00
|
|
|
rect.xmax = get_width();
|
|
|
|
|
rect.ymax = get_height();
|
2021-03-19 14:56:07 +01:00
|
|
|
MemoryBuffer *result = new MemoryBuffer(DataType::Color, rect);
|
2021-10-13 23:01:15 +02:00
|
|
|
this->generate_denoise(result, tile_color, tile_normal, tile_albedo, settings_);
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
void DenoiseOperation::generate_denoise(MemoryBuffer *output,
|
|
|
|
|
MemoryBuffer *input_color,
|
|
|
|
|
MemoryBuffer *input_normal,
|
|
|
|
|
MemoryBuffer *input_albedo,
|
|
|
|
|
NodeDenoise *settings)
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
BLI_assert(input_color->get_buffer());
|
|
|
|
|
if (!input_color->get_buffer()) {
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2021-09-04 15:23:28 +02:00
|
|
|
|
2021-09-19 20:12:53 +02:00
|
|
|
BLI_assert(COM_is_denoise_supported());
|
|
|
|
|
/* OpenImageDenoise needs full buffers. */
|
|
|
|
|
MemoryBuffer *buf_color = input_color->is_a_single_elem() ? input_color->inflate() : input_color;
|
|
|
|
|
MemoryBuffer *buf_normal = input_normal && input_normal->is_a_single_elem() ?
|
|
|
|
|
input_normal->inflate() :
|
|
|
|
|
input_normal;
|
|
|
|
|
MemoryBuffer *buf_albedo = input_albedo && input_albedo->is_a_single_elem() ?
|
|
|
|
|
input_albedo->inflate() :
|
|
|
|
|
input_albedo;
|
2021-09-04 15:23:28 +02:00
|
|
|
|
2021-09-19 20:12:53 +02:00
|
|
|
DenoiseFilter filter;
|
|
|
|
|
filter.init_and_lock_denoiser(output);
|
2021-04-12 14:29:49 +02:00
|
|
|
|
2021-09-19 20:12:53 +02:00
|
|
|
filter.set_image("color", buf_color);
|
|
|
|
|
filter.set_image("normal", buf_normal);
|
|
|
|
|
filter.set_image("albedo", buf_albedo);
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
|
2021-09-19 20:12:53 +02:00
|
|
|
BLI_assert(settings);
|
|
|
|
|
if (settings) {
|
|
|
|
|
filter.set("hdr", settings->hdr);
|
|
|
|
|
filter.set("srgb", false);
|
2021-10-23 20:35:15 +02:00
|
|
|
filter.set("cleanAux", are_guiding_passes_noise_free(settings));
|
2021-09-19 20:12:53 +02:00
|
|
|
}
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
|
2021-09-19 20:12:53 +02:00
|
|
|
filter.execute();
|
|
|
|
|
filter.deinit_and_unlock_denoiser();
|
2021-09-04 15:23:28 +02:00
|
|
|
|
2021-09-19 20:12:53 +02:00
|
|
|
/* Copy the alpha channel, OpenImageDenoise currently only supports RGB. */
|
|
|
|
|
output->copy_from(input_color, input_color->get_rect(), 3, COM_DATA_TYPE_VALUE_CHANNELS, 3);
|
2021-09-04 15:23:28 +02:00
|
|
|
|
2021-09-19 20:12:53 +02:00
|
|
|
/* Delete inflated buffers. */
|
|
|
|
|
if (input_color->is_a_single_elem()) {
|
|
|
|
|
delete buf_color;
|
|
|
|
|
}
|
|
|
|
|
if (input_normal && input_normal->is_a_single_elem()) {
|
|
|
|
|
delete buf_normal;
|
|
|
|
|
}
|
|
|
|
|
if (input_albedo && input_albedo->is_a_single_elem()) {
|
|
|
|
|
delete buf_albedo;
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
}
|
2021-09-04 15:23:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DenoiseOperation::update_memory_buffer(MemoryBuffer *output,
|
|
|
|
|
const rcti &UNUSED(area),
|
|
|
|
|
Span<MemoryBuffer *> inputs)
|
|
|
|
|
{
|
|
|
|
|
if (!output_rendered_) {
|
2021-10-13 23:01:15 +02:00
|
|
|
this->generate_denoise(output, inputs[0], inputs[1], inputs[2], settings_);
|
2021-09-04 15:23:28 +02:00
|
|
|
output_rendered_ = true;
|
|
|
|
|
}
|
Compositor: Added denoising node
This node is built on Intel's OpenImageDenoise library.
Other denoisers could be integrated, for example Lukas' Cycles denoiser.
Compositor: Made OpenImageDenoise optional, added CMake and build_env files to find OIDN
Compositor: Fixed some warnings in the denoising operator
build_environment: Updated OpenImageDenoise to 0.8.1
build_environment: Updated OpenImageDenoise in `make deps` for macOS
Reviewers: sergey, jbakker, brecht
Reviewed By: brecht
Subscribers: YAFU, LazyDodo, Zen_YS, slumber, samgreen, tjvoll, yeus, ponomarovmax, getrad, coder.kalyan, vitos1k, Yegor, DeepBlender, kumaran7, Darkfie9825, aliasguru, aafra, ace_dragon, juang3d, pandrodor, cdog, lordodin, jtheninja, mavek, marcog, 5k1n2, Atair, rawalanche, 0o00o0oo, filibis, poor, lukasstockner97
Tags: #compositing
Differential Revision: https://developer.blender.org/D4304
2019-08-14 15:30:26 +02:00
|
|
|
}
|
2021-03-23 17:12:27 +01:00
|
|
|
|
2021-09-19 20:12:53 +02:00
|
|
|
DenoisePrefilterOperation::DenoisePrefilterOperation(DataType data_type)
|
|
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
this->add_input_socket(data_type);
|
|
|
|
|
this->add_output_socket(data_type);
|
2021-09-19 20:12:53 +02:00
|
|
|
image_name_ = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DenoisePrefilterOperation::hash_output_params()
|
|
|
|
|
{
|
|
|
|
|
hash_param(image_name_);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
MemoryBuffer *DenoisePrefilterOperation::create_memory_buffer(rcti *rect2)
|
2021-09-19 20:12:53 +02:00
|
|
|
{
|
2021-10-13 23:01:15 +02:00
|
|
|
MemoryBuffer *input = (MemoryBuffer *)this->get_input_operation(0)->initialize_tile_data(rect2);
|
2021-09-19 20:12:53 +02:00
|
|
|
rcti rect;
|
2021-10-13 23:01:15 +02:00
|
|
|
BLI_rcti_init(&rect, 0, get_width(), 0, get_height());
|
2021-09-19 20:12:53 +02:00
|
|
|
|
2021-10-13 23:01:15 +02:00
|
|
|
MemoryBuffer *result = new MemoryBuffer(get_output_socket()->get_data_type(), rect);
|
2021-09-19 20:12:53 +02:00
|
|
|
generate_denoise(result, input);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DenoisePrefilterOperation::generate_denoise(MemoryBuffer *output, MemoryBuffer *input)
|
|
|
|
|
{
|
|
|
|
|
BLI_assert(COM_is_denoise_supported());
|
|
|
|
|
|
|
|
|
|
/* Denoising needs full buffers. */
|
|
|
|
|
MemoryBuffer *input_buf = input->is_a_single_elem() ? input->inflate() : input;
|
|
|
|
|
|
|
|
|
|
DenoiseFilter filter;
|
|
|
|
|
filter.init_and_lock_denoiser(output);
|
|
|
|
|
filter.set_image(image_name_, input_buf);
|
|
|
|
|
filter.execute();
|
|
|
|
|
filter.deinit_and_unlock_denoiser();
|
|
|
|
|
|
|
|
|
|
/* Delete inflated buffers. */
|
|
|
|
|
if (input->is_a_single_elem()) {
|
|
|
|
|
delete input_buf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DenoisePrefilterOperation::update_memory_buffer(MemoryBuffer *output,
|
|
|
|
|
const rcti &UNUSED(area),
|
|
|
|
|
Span<MemoryBuffer *> inputs)
|
|
|
|
|
{
|
|
|
|
|
if (!output_rendered_) {
|
|
|
|
|
this->generate_denoise(output, inputs[0]);
|
|
|
|
|
output_rendered_ = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 17:12:27 +01:00
|
|
|
} // namespace blender::compositor
|