11 #include <OpenImageIO/filesystem.h>
21 size_t pos = in.rfind(
".");
22 if (
pos == string::npos) {
25 suffix = in.substr(
pos + 1);
26 in = in.substr(0,
pos);
35 string name,
string &renderlayer,
string &pass,
string &channel,
bool multiview_channels)
49 if (multiview_channels) {
50 renderlayer +=
"." +
view;
65 for (
const char *chan =
channels.c_str(); *chan; chan++) {
66 map.push_back({
pos++, name +
"." + *chan});
107 size_t input_channel = mapping.channel;
108 size_t layer_channel = i -
channels.begin();
122 size_t output_channel = mapping.channel;
123 size_t layer_channel = i -
channels.begin();
139 const std::vector<string> &neighbor_channelnames)
143 assert(mapping.size() == 0);
148 std::vector<string>::const_iterator frame_channel = find(
149 neighbor_channelnames.begin(), neighbor_channelnames.end(), channel);
151 if (frame_channel == neighbor_channelnames.end()) {
155 mapping[i] = frame_channel - neighbor_channelnames.begin();
164 : denoiser(denoiser), device(device), frame(frame), current_layer(0), buffers(device)
185 error =
"Failed to read neighbor frame pixels";
200 pass->set_type(
type);
201 pass->set_mode(mode);
203 passes.push_back(pass);
219 error =
"No image layers found to denoise in " + center_filepath;
247 for (
Pass *pass : passes) {
287 int image_channel = output_to_image_channel[j];
342 const ParamValue *multiview =
in_spec.find_attribute(
"multiView");
343 const bool multiview_channels = (multiview && multiview->type().basetype == TypeDesc::STRING &&
344 multiview->type().arraylen >= 2);
351 map<string, DenoiseImageLayer> file_layers;
352 for (
int i = 0; i <
channels.size(); i++) {
353 string layer, pass, channel;
355 file_layers[layer].channels.push_back(pass +
"." + channel);
356 file_layers[layer].layer_to_image_channel.push_back(i);
362 for (map<string, DenoiseImageLayer>::iterator i = file_layers.begin(); i != file_layers.end();
364 const string &name = i->first;
378 string sample_string =
in_spec.get_string_attribute(
"cycles." + name +
".samples",
"");
379 if (sample_string !=
"") {
380 if (!sscanf(sample_string.c_str(),
"%d", &layer.
samples)) {
381 error =
"Failed to parse samples metadata: " + sample_string;
389 "No sample number specified in the file for layer %s or on the command line",
409 for (
int j = 0; j < 3; ++j) {
415 for (
int j = 0; j < 3; ++j) {
421 for (
int j = 0; j < 3; ++j) {
427 for (
int j = 0; j < 4; ++j) {
429 int image_channel = input_to_image_channel[
INPUT_MOTION + j];
451 for (
int j = 0; j < 3; ++j) {
453 int image_channel = output_to_image_channel[j];
455 neighbor_pixels[((size_t)i) *
num_channels + image_channel];
464 if (!Filesystem::is_regular(in_filepath)) {
465 error =
"Couldn't find file: " + in_filepath;
469 unique_ptr<ImageInput> in(ImageInput::open(in_filepath));
471 error =
"Couldn't open file: " + in_filepath;
485 error =
"Could not find a render layer containing denoising data and motion vector passes";
495 error =
"Failed to read image: " + in_filepath;
504 if (!Filesystem::is_regular(filepath)) {
505 error =
"Couldn't find neighbor frame: " + filepath;
509 unique_ptr<ImageInput> in_neighbor(ImageInput::open(filepath));
511 error =
"Couldn't open neighbor frame: " + filepath;
515 const ImageSpec &neighbor_spec = in_neighbor->spec();
516 if (neighbor_spec.width !=
width || neighbor_spec.height !=
height) {
517 error =
"Neighbor frame has different dimensions: " + filepath;
522 if (!layer.match_channels(
in_spec.channelnames, neighbor_spec.channelnames)) {
523 error =
"Neighbor frame misses denoising data passes: " + filepath;
539 for (
int i = 0; i <
layers.size(); i++) {
540 string name =
"cycles." +
layers[i].name +
".samples";
541 if (!out_spec.find_attribute(name, TypeDesc::STRING)) {
552 string extension = OIIO::Filesystem::extension(out_filepath);
553 string unique_name =
".denoise-tmp-" + OIIO::Filesystem::unique_path();
554 string tmp_filepath = out_filepath +
unique_name + extension;
558 error =
"Failed to open temporary file " + tmp_filepath +
" for writing";
563 if (!
out->open(tmp_filepath, out_spec)) {
564 error =
"Failed to open file " + tmp_filepath +
" for writing: " +
out->geterror();
570 error =
"Failed to write to file " + tmp_filepath +
": " +
out->geterror();
575 error =
"Failed to save to file " + tmp_filepath +
": " +
out->geterror();
583 if (ok && !OIIO::Filesystem::rename(tmp_filepath, out_filepath, rename_error)) {
584 error =
"Failed to move denoised image to " + out_filepath +
": " + rename_error;
621 int num_frames =
output.size();
623 for (
int frame = 0; frame < num_frames; frame++) {
625 if (
output[frame].empty()) {
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a producing a negative Combine Generate a color from its and blue channels(Deprecated)") DefNode(ShaderNode
int get_pass_offset(PassType type, PassMode mode=PassMode::NOISY) const
void read_pixels(const DenoiseImageLayer &layer, const BufferParams ¶ms, float *input_pixels)
bool parse_channels(const ImageSpec &in_spec, string &error)
vector< DenoiseImageLayer > layers
bool read_previous_pixels(const DenoiseImageLayer &layer, const BufferParams ¶ms, float *input_pixels)
bool load(const string &in_filepath, string &error)
unique_ptr< ImageInput > in_previous
bool load_previous(const string &in_filepath, string &error)
bool save_output(const string &out_filepath, string &error)
DenoiserPipeline * denoiser
DenoiseTask(Device *device, DenoiserPipeline *denoiser, int frame)
bool load_input_pixels(int layer)
std::unique_ptr< Denoiser > denoiser
DenoiserPipeline(DeviceInfo &device_info, const DenoiseParams ¶ms)
static unique_ptr< Denoiser > create(Device *path_trace_device, const DenoiseParams ¶ms)
static Device * create(const DeviceInfo &info, Stats &stats, Profiler &profiler)
virtual bool load_kernels(uint)
device_vector< float > buffer
void reset(const BufferParams ¶ms)
static void init(int num_threads=0)
T * resize(size_t newsize)
#define CCL_NAMESPACE_END
static const int INPUT_NOISY_IMAGE
static const int OUTPUT_NUM_CHANNELS
static void fill_mapping(vector< ChannelMapping > &map, int pos, string name, string channels)
static bool parse_channel_name(string name, string &renderlayer, string &pass, string &channel, bool multiview_channels)
static CCL_NAMESPACE_BEGIN bool split_last_dot(string &in, string &suffix)
static vector< ChannelMapping > input_channels()
static const int INPUT_DENOISING_ALBEDO
static const int INPUT_DENOISING_NORMAL
static const int INPUT_NUM_CHANNELS
static vector< ChannelMapping > output_channels()
static const int INPUT_MOTION
static void add_pass(vector< Pass * > &passes, PassType type, PassMode mode=PassMode::NOISY)
ccl_gpu_kernel_postfix ccl_global float int num_pixels
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
@ KERNEL_FEATURE_DENOISING
@ PASS_DENOISING_PREVIOUS
static void error(const char *str)
bool remove(void *owner, const AttributeIDRef &attribute_id)
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull prop_name, int32_t value)
Allocate a new IDProperty of type IDP_INT, set its name and value.
struct blender::compositor::@179::@181 task
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static void unique_name(bNode *node)
SocketIndexByIdentifierMap * map
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
vector< int > previous_output_to_image_channel
vector< int > input_to_image_channel
bool match_channels(const std::vector< string > &channelnames, const std::vector< string > &neighbor_channelnames)
bool detect_denoising_channels()
vector< int > output_to_image_channel
vector< string > channels
vector< int > layer_to_image_channel