1// ======================================================================== //
2// Copyright 2009-2019 Intel Corporation //
3// //
4// Licensed under the Apache License, Version 2.0 (the "License"); //
5// you may not use this file except in compliance with the License. //
6// You may obtain a copy of the License at //
7// //
8// http://www.apache.org/licenses/LICENSE-2.0 //
9// //
10// Unless required by applicable law or agreed to in writing, software //
11// distributed under the License is distributed on an "AS IS" BASIS, //
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
13// See the License for the specific language governing permissions and //
14// limitations under the License. //
15// ======================================================================== //
16
17#pragma once
18
19#include "filter.h"
20#include "network.h"
21#include "transfer_function.h"
22
23namespace oidn {
24
25 // --------------------------------------------------------------------------
26 // AutoencoderFilter - Direct-predicting autoencoder
27 // --------------------------------------------------------------------------
28
29 class AutoencoderFilter : public Filter
30 {
31 protected:
32 static constexpr int alignment = 32; // required spatial alignment in pixels (padding may be necessary)
33 static constexpr int receptiveField = 222; // receptive field in pixels
34 static constexpr int overlap = roundUp(receptiveField / 2, alignment); // required spatial overlap between tiles in pixels
35
36 static constexpr int estimatedBytesBase = 16*1024*1024; // estimated base memory usage
37 static constexpr int estimatedBytesPerPixel8 = 889; // estimated memory usage per pixel for K=8
38 static constexpr int estimatedBytesPerPixel16 = 2185; // estimated memory usage per pixel for K=16
39
40 Image color;
41 Image albedo;
42 Image normal;
43 Image output;
44 bool hdr = false;
45 float hdrScale = std::numeric_limits<float>::quiet_NaN();
46 bool srgb = false;
47 int maxMemoryMB = 6000; // approximate maximum memory usage in MBs
48
49 int H = 0; // image height
50 int W = 0; // image width
51 int tileH = 0; // tile height
52 int tileW = 0; // tile width
53 int tileCountH = 1; // number of tiles in H dimension
54 int tileCountW = 1; // number of tiles in W dimension
55
56 std::shared_ptr<Executable> net;
57 std::shared_ptr<Node> inputReorder;
58 std::shared_ptr<Node> outputReorder;
59
60 struct
61 {
62 void* ldr = nullptr;
63 void* ldr_alb = nullptr;
64 void* ldr_alb_nrm = nullptr;
65 void* hdr = nullptr;
66 void* hdr_alb = nullptr;
67 void* hdr_alb_nrm = nullptr;
68 } weightData;
69
70 explicit AutoencoderFilter(const Ref<Device>& device);
71 virtual std::shared_ptr<TransferFunction> makeTransferFunc();
72
73 public:
74 void setImage(const std::string& name, const Image& data) override;
75 void set1i(const std::string& name, int value) override;
76 int get1i(const std::string& name) override;
77 void set1f(const std::string& name, float value) override;
78 float get1f(const std::string& name) override;
79
80 void commit() override;
81 void execute() override;
82
83 private:
84 void computeTileSize();
85
86 template<int K>
87 std::shared_ptr<Executable> buildNet();
88
89 bool isCommitted() const { return bool(net); }
90 };
91
92 // --------------------------------------------------------------------------
93 // RTFilter - Generic ray tracing denoiser
94 // --------------------------------------------------------------------------
95
96// -- GODOT start --
97// Godot doesn't need Raytracing filters. Removing them saves space in the weights files.
98#if 0
99// -- GODOT end --
100 class RTFilter : public AutoencoderFilter
101 {
102 public:
103 explicit RTFilter(const Ref<Device>& device);
104 };
105// -- GODOT start --
106#endif
107// -- GODOT end --
108
109 // --------------------------------------------------------------------------
110 // RTLightmapFilter - Ray traced lightmap denoiser
111 // --------------------------------------------------------------------------
112
113 class RTLightmapFilter : public AutoencoderFilter
114 {
115 public:
116 explicit RTLightmapFilter(const Ref<Device>& device);
117 std::shared_ptr<TransferFunction> makeTransferFunc() override;
118 };
119
120} // namespace oidn
121