Skip to content

Commit c6a7cc9

Browse files
Prepare denoiser argument parsing for FFT Bloom
1 parent 78fc958 commit c6a7cc9

File tree

5 files changed

+137
-73
lines changed

5 files changed

+137
-73
lines changed

examples_tests/39.DenoiserTonemapper/CommandLineHandler.cpp

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ CommandLineHandler::CommandLineHandler(core::vector<std::string> argv, IAssetMan
176176
assignToMap(DTEA_DENOISER_EXPOSURE_BIAS);
177177
else if (variable == DENOISER_BLEND_FACTOR)
178178
assignToMap(DTEA_DENOISER_BLEND_FACTOR);
179-
else if (variable == BLOOM_FOV)
180-
assignToMap(DTEA_BLOOM_FOV);
179+
else if (variable == BLOOM_SCALE)
180+
assignToMap(DTEA_BLOOM_SCALE);
181181
else if (variable == REINHARD)
182182
assignToMap(DTEA_TONEMAPPER_REINHARD, 2);
183183
else if (variable == ACES)
@@ -225,7 +225,7 @@ CommandLineHandler::CommandLineHandler(core::vector<std::string> argv, IAssetMan
225225

226226
bool CommandLineHandler::validateMandatoryParameters(const variablesType& rawVariablesPerFile, const size_t idOfInput)
227227
{
228-
static const nbl::core::vector<DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS> mandatoryArgumentsOrdinary = { DTEA_COLOR_FILE, DTEA_CAMERA_TRANSFORM, DTEA_DENOISER_EXPOSURE_BIAS, DTEA_DENOISER_BLEND_FACTOR, DTEA_BLOOM_FOV, DTEA_OUTPUT };
228+
static const nbl::core::vector<DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS> mandatoryArgumentsOrdinary = { DTEA_COLOR_FILE, DTEA_CAMERA_TRANSFORM, DTEA_DENOISER_EXPOSURE_BIAS, DTEA_DENOISER_BLEND_FACTOR, DTEA_BLOOM_SCALE, DTEA_OUTPUT };
229229

230230
auto log = [&](bool status, const std::string message)
231231
{
@@ -235,7 +235,13 @@ bool CommandLineHandler::validateMandatoryParameters(const variablesType& rawVar
235235

236236
auto validateOrdinary = [&](const DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS argument)
237237
{
238-
return rawVariablesPerFile.at(argument).has_value();
238+
if (!rawVariablesPerFile.at(argument).has_value())
239+
return false;
240+
241+
//rawVariablesPerFile.at(argument)
242+
//switch(argument)
243+
244+
return true;
239245
};
240246

241247
auto validateTonemapper = [&]()
@@ -290,29 +296,7 @@ bool CommandLineHandler::validateMandatoryParameters(const variablesType& rawVar
290296

291297
return validateTonemapper();
292298
}
293-
/*
294-
std::pair<DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS,nbl::core::vector<float>> CommandLineHandler::getTonemapper(uint64_t id)
295-
{
296-
nbl::core::vector<float> values;
297-
uint32_t j = DTEA_TONEMAPPER_REINHARD;
298-
DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS num;
299-
for (; j<=DTEA_TONEMAPPER_NONE; j++)
300-
{
301-
num = (DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS)j;
302-
if (rawVariables[id][num].has_value())
303-
break;
304-
}
305-
306-
if (j<=DTEA_TONEMAPPER_NONE)
307-
for (auto i=0; i<TA_COUNT; ++i)
308-
{
309-
float val = std::stof(rawVariables[id][num].value()[i]);
310-
values.push_back(0.f);
311-
}
312-
313-
return { num, values };
314-
}
315-
*/
299+
316300
std::optional<std::string> CommandLineHandler::getNormalFileName(uint64_t id)
317301
{
318302
bool ableToReturn = rawVariables[id][DTEA_NORMAL_FILE].has_value() && !rawVariables[id][DTEA_NORMAL_FILE].value().empty();

examples_tests/39.DenoiserTonemapper/CommandLineHandler.hpp

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Mandatory parameters:
3636
-CAMERA_TRANSFORM=mitsubaFilePath or val1,val2,val3,...,val9
3737
-DENOISER_EXPOSURE_BIAS=value
3838
-DENOISER_BLEND_FACTOR=value
39-
-BLOOM_FOV=theta
39+
-BLOOM_SCALE=theta
4040
-TONEMAPPER=tonemapper=keyValue,extraParameter
4141
-OUTPUT=file.choosenextension
4242
Optional Parameters:
@@ -48,14 +48,14 @@ Optional Parameters:
4848
-BLOOM_PSF_FILE=psfFilePath
4949
5050
Note there mustn't be any space characters!
51-
All file's resolutions must match!
51+
All files' (except the bloom kernel) resolutions must match!
5252
Also you must not put another data like comments or behaviour will be undefined, the app'll crash (TODO: not crash on parse failure)
5353
5454
Description and usage:
5555
56-
COLOR_FILE: File containing color image data, it's required to run within.
57-
ALBEDO_FILE: File containing albedo image data, it is not required to run within.
58-
NORMAL_FILE: File containing normal image data, it is not required to run within, but it can only be specified if ALBEDO_FILE has been specified.
56+
COLOR_FILE: File containing color image data, it's required to run with.
57+
ALBEDO_FILE: File containing albedo image data, it is not required to run.
58+
NORMAL_FILE: File containing normal image data, it is not required to run, but it can only be specified if ALBEDO_FILE has been specified.
5959
6060
COLOR_CHANNEL_NAME: Channel name for multilayered EXR images, a layer with most matching name will be chosen (one that contains the channel name as a substring at the earliest position).
6161
ALBEDO_CHANNEL_NAME: Channel name for multilayered EXR images, a layer with most matching name will be chosen (one that contains the channel name as a substring at the earliest position). It can only be specified if ALBEDO_FILE has been specified.
@@ -73,9 +73,9 @@ you should use the Tonemapping Operator's Key Value.
7373
7474
DENOISER_BLEND_FACTOR: denoiser blend factor, 0.0 is full denoise, 1.0 is no denoise.
7575
76-
BLOOM_FOV: Field of View of the image, its used to scale the size of the Bloom's light-flares (point spread function) to match the Camera's projection.
77-
If you don't want bloom then either provide a PSF image the size of the input image with a single bright pixel, or set the FoV to negative or NaN.
78-
Please note that the Bloom is not implemented yet, so the value is ignored (forced to NaN).
76+
BLOOM_SCALE: Must not be negative or greater than 1. The scale relative to the kernel being placed at the center of the denoised image and isotropically stretched until it touches one of the sides of the denoised image.
77+
You'll usually want to keep this value below 1/32
78+
If you don't want bloom then either provide a PSF image which is a single white pixel, or set bloom scale to a very small non negative value.
7979
8080
TONEMAPPER: tonemapper - choose between "REINHARD", "ACES" and "NONE". After specifying it you have to pass arguments to revelant tonemapper,
8181
the first argument is always the Key Value, a good default is 0.18 like the Reinhard paper's default.
@@ -100,15 +100,16 @@ while "NONE looks like:
100100
-TONEMAPPER=NONE=AutoexposureOff
101101
102102
OUTPUT: output file with specified extension
103-
BLOOM_PSF_FILE: A EXR file with a HDR sprite corresponding to the Point Spread Function you want to convolve the image with,
104-
if this file is not provided then we use a built-in PSF as the kernel for the convolution.
103+
BLOOM_PSF_FILE: A EXR file with a HDR sprite corresponding to the Point Spread Function you want to convolve the image with.
104+
The kernel must be centered and in RGB or RGBA floating point format. Resolution should be less than the denoised image.
105+
If this file is not provided then we use a built-in PSF as the kernel for the convolution.
105106
)";
106107

107108
constexpr std::string_view COLOR_FILE = "COLOR_FILE";
108109
constexpr std::string_view CAMERA_TRANSFORM = "CAMERA_TRANSFORM";
109110
constexpr std::string_view DENOISER_EXPOSURE_BIAS = "DENOISER_EXPOSURE_BIAS";
110111
constexpr std::string_view DENOISER_BLEND_FACTOR = "DENOISER_BLEND_FACTOR";
111-
constexpr std::string_view BLOOM_FOV = "BLOOM_FOV";
112+
constexpr std::string_view BLOOM_SCALE = "BLOOM_SCALE";
112113
constexpr std::string_view TONEMAPPER = "TONEMAPPER";
113114
constexpr std::string_view REINHARD = "REINHARD";
114115
constexpr std::string_view ACES = "ACES";
@@ -128,7 +129,7 @@ constexpr std::array<std::string_view, MANDATORY_CMD_ARGUMENTS_AMOUNT> REQUIRED_
128129
CAMERA_TRANSFORM,
129130
DENOISER_EXPOSURE_BIAS,
130131
DENOISER_BLEND_FACTOR,
131-
BLOOM_FOV,
132+
BLOOM_SCALE,
132133
TONEMAPPER,
133134
OUTPUT
134135
};
@@ -143,7 +144,7 @@ enum DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS
143144
DTEA_CAMERA_TRANSFORM,
144145
DTEA_DENOISER_EXPOSURE_BIAS,
145146
DTEA_DENOISER_BLEND_FACTOR,
146-
DTEA_BLOOM_FOV,
147+
DTEA_BLOOM_SCALE,
147148
DTEA_TONEMAPPER,
148149
DTEA_TONEMAPPER_REINHARD,
149150
DTEA_TONEMAPPER_ACES,
@@ -233,9 +234,9 @@ class CommandLineHandler
233234
return denoiserBlendFactorBundle;
234235
}
235236

236-
auto& getBloomFovBundle() const
237+
auto& getBloomScaleBundle() const
237238
{
238-
return bloomFovBundle;
239+
return bloomScaleBundle;
239240
}
240241

241242
auto& getTonemapperBundle() const
@@ -265,7 +266,7 @@ class CommandLineHandler
265266
rawVariablesPerFile[DTEA_CAMERA_TRANSFORM];
266267
rawVariablesPerFile[DTEA_DENOISER_EXPOSURE_BIAS];
267268
rawVariablesPerFile[DTEA_DENOISER_BLEND_FACTOR];
268-
rawVariablesPerFile[DTEA_BLOOM_FOV];
269+
rawVariablesPerFile[DTEA_BLOOM_SCALE];
269270
rawVariablesPerFile[DTEA_TONEMAPPER_REINHARD];
270271
rawVariablesPerFile[DTEA_TONEMAPPER_ACES];
271272
rawVariablesPerFile[DTEA_TONEMAPPER_NONE];
@@ -289,8 +290,8 @@ class CommandLineHandler
289290
return DTEA_DENOISER_EXPOSURE_BIAS;
290291
else if (variableName == DENOISER_BLEND_FACTOR)
291292
return DTEA_DENOISER_BLEND_FACTOR;
292-
else if (variableName == BLOOM_FOV)
293-
return DTEA_BLOOM_FOV;
293+
else if (variableName == BLOOM_SCALE)
294+
return DTEA_BLOOM_SCALE;
294295
else if (variableName == TONEMAPPER)
295296
return DTEA_TONEMAPPER;
296297
else if (variableName == REINHARD)
@@ -341,9 +342,9 @@ class CommandLineHandler
341342
return std::stof(rawVariables[id][DTEA_DENOISER_BLEND_FACTOR].value()[0]);
342343
}
343344

344-
auto getBloomFov(uint64_t id = 0)
345+
auto getBloomScale(uint64_t id = 0)
345346
{
346-
return std::stof(rawVariables[id][DTEA_BLOOM_FOV].value()[0]);
347+
return std::stof(rawVariables[id][DTEA_BLOOM_SCALE].value()[0]);
347348
}
348349

349350
auto getTonemapper(uint64_t id = 0)
@@ -437,7 +438,7 @@ class CommandLineHandler
437438
cameraTransformBundle.reserve(inputFilesAmount);
438439
denoiserExposureBiasBundle.reserve(inputFilesAmount);
439440
denoiserBlendFactorBundle.reserve(inputFilesAmount);
440-
bloomFovBundle.reserve(inputFilesAmount);
441+
bloomScaleBundle.reserve(inputFilesAmount);
441442
tonemapperBundle.reserve(inputFilesAmount);
442443
outputFileNameBundle.reserve(inputFilesAmount);
443444
bloomPsfFileNameBundle.reserve(inputFilesAmount);
@@ -453,7 +454,7 @@ class CommandLineHandler
453454
cameraTransformBundle.push_back(getCameraTransform(i));
454455
denoiserExposureBiasBundle.push_back(getDenoiserExposureBias(i));
455456
denoiserBlendFactorBundle.push_back(getDenoiserBlendFactor(i));
456-
bloomFovBundle.push_back(getBloomFov(i));
457+
bloomScaleBundle.push_back(getBloomScale(i));
457458
tonemapperBundle.push_back(getTonemapper(i));
458459
outputFileNameBundle.push_back(getOutputFile(i));
459460
bloomPsfFileNameBundle.push_back(getBloomPsfFile(i));
@@ -477,7 +478,7 @@ class CommandLineHandler
477478
nbl::core::vector<std::optional<nbl::core::matrix3x4SIMD>> cameraTransformBundle;
478479
nbl::core::vector<std::optional<float>> denoiserExposureBiasBundle;
479480
nbl::core::vector<std::optional<float>> denoiserBlendFactorBundle;
480-
nbl::core::vector<std::optional<float>> bloomFovBundle;
481+
nbl::core::vector<std::optional<float>> bloomScaleBundle;
481482
nbl::core::vector<std::pair<DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS,nbl::core::vector<float>>> tonemapperBundle;
482483
nbl::core::vector<std::optional<std::string>> outputFileNameBundle;
483484
nbl::core::vector<std::optional<std::string>> bloomPsfFileNameBundle;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
-COLOR_FILE=../../media/noises/spp_benchmark_4k_512.exr -ALBEDO_FILE=../../media/noises/spp_benchmark_4k_512.exr -NORMAL_FILE=../../media/noises/spp_benchmark_4k_512.exr -CAMERA_TRANSFORM=../../media/noises/render.xml -DENOISER_EXPOSURE_BIAS=0.0 -DENOISER_BLEND_FACTOR=1.0 -BLOOM_FOV=0.5 -TONEMAPPER=ACES=0.4,0.8 -OUTPUT=spp_benchmark_4k_512_reference.exr -COLOR_CHANNEL_NAME=color -ALBEDO_CHANNEL_NAME=albedo -NORMAL_CHANNEL_NAME=normal
2-
-COLOR_FILE=../../media/noises/spp_benchmark_4k_512.exr -ALBEDO_FILE=../../media/noises/spp_benchmark_4k_512.exr -NORMAL_FILE=../../media/noises/spp_benchmark_4k_512.exr -CAMERA_TRANSFORM=../../media/noises/render.xml -DENOISER_EXPOSURE_BIAS=0.0 -DENOISER_BLEND_FACTOR=0.0 -BLOOM_FOV=0.5 -TONEMAPPER=ACES=0.4,0.8 -OUTPUT=spp_benchmark_4k_512_denoised.exr -COLOR_CHANNEL_NAME=color -ALBEDO_CHANNEL_NAME=albedo -NORMAL_CHANNEL_NAME=normal
1+
-COLOR_FILE=../../media/noises/spp_benchmark_4k_512.exr -ALBEDO_FILE=../../media/noises/spp_benchmark_4k_512.exr -NORMAL_FILE=../../media/noises/spp_benchmark_4k_512.exr -CAMERA_TRANSFORM=../../media/noises/render.xml -DENOISER_EXPOSURE_BIAS=0.0 -DENOISER_BLEND_FACTOR=1.0 -BLOOM_PSF_FILE=../../media/kernels/physical_flare_512.exr -BLOOM_SCALE=0.0625 -TONEMAPPER=ACES=0.4,0.8 -OUTPUT=spp_benchmark_4k_512_reference.exr -COLOR_CHANNEL_NAME=color -ALBEDO_CHANNEL_NAME=albedo -NORMAL_CHANNEL_NAME=normal
2+
-COLOR_FILE=../../media/noises/spp_benchmark_4k_512.exr -ALBEDO_FILE=../../media/noises/spp_benchmark_4k_512.exr -NORMAL_FILE=../../media/noises/spp_benchmark_4k_512.exr -CAMERA_TRANSFORM=../../media/noises/render.xml -DENOISER_EXPOSURE_BIAS=0.0 -DENOISER_BLEND_FACTOR=0.0 -BLOOM_PSF_FILE=../../media/kernels/physical_flare_512.exr -BLOOM_SCALE=0.0625 -TONEMAPPER=ACES=0.4,0.8 -OUTPUT=spp_benchmark_4k_512_denoised.exr -COLOR_CHANNEL_NAME=color -ALBEDO_CHANNEL_NAME=albedo -NORMAL_CHANNEL_NAME=normal

0 commit comments

Comments
 (0)