Skip to content

Commit cac8d5e

Browse files
Add bloom intensity commandline parameter!
Also get rid of unused push constants and overrides
1 parent efc648c commit cac8d5e

File tree

4 files changed

+87
-69
lines changed

4 files changed

+87
-69
lines changed

examples_tests/39.DenoiserTonemapper/CommandLineHandler.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,12 @@ 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_SCALE)
180-
assignToMap(DTEA_BLOOM_SCALE);
179+
else if (variable == BLOOM_PSF_FILE)
180+
assignToMap(DTEA_BLOOM_PSF_FILE);
181+
else if (variable == BLOOM_RELATIVE_SCALE)
182+
assignToMap(DTEA_BLOOM_RELATIVE_SCALE);
183+
else if (variable == BLOOM_INTENSITY)
184+
assignToMap(DTEA_BLOOM_INTENSITY);
181185
else if (variable == REINHARD)
182186
assignToMap(DTEA_TONEMAPPER_REINHARD, 2);
183187
else if (variable == ACES)
@@ -196,8 +200,6 @@ CommandLineHandler::CommandLineHandler(core::vector<std::string> argv, IAssetMan
196200
assignToMap(DTEA_ALBEDO_CHANNEL_NAME);
197201
else if (variable == NORMAL_CHANNEL_NAME)
198202
assignToMap(DTEA_NORMAL_CHANNEL_NAME);
199-
else if (variable == BLOOM_PSF_FILE)
200-
assignToMap(DTEA_BLOOM_PSF_FILE);
201203
else
202204
{
203205
os::Printer::log("ERROR (" + std::to_string(__LINE__) + " line): Unexcepted argument! Id of input stride: " + std::to_string(inputBatchStride), ELL_ERROR);
@@ -225,7 +227,7 @@ CommandLineHandler::CommandLineHandler(core::vector<std::string> argv, IAssetMan
225227

226228
bool CommandLineHandler::validateMandatoryParameters(const variablesType& rawVariablesPerFile, const size_t idOfInput)
227229
{
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 };
230+
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_PSF_FILE, DTEA_BLOOM_RELATIVE_SCALE, DTEA_BLOOM_INTENSITY, DTEA_OUTPUT };
229231

230232
auto log = [&](bool status, const std::string message)
231233
{

examples_tests/39.DenoiserTonemapper/CommandLineHandler.hpp

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#include "nbl/core/core.h"
1313
#include "nbl/ext/MitsubaLoader/CMitsubaLoader.h"
1414

15-
#define PROPER_CMD_ARGUMENTS_AMOUNT 14
16-
#define MANDATORY_CMD_ARGUMENTS_AMOUNT 8
17-
#define OPTIONAL_CMD_ARGUMENTS_AMOUNT 6
15+
#define PROPER_CMD_ARGUMENTS_AMOUNT 17
16+
#define MANDATORY_CMD_ARGUMENTS_AMOUNT 12
17+
#define OPTIONAL_CMD_ARGUMENTS_AMOUNT 5
1818
#define PROPER_BATCH_FILE_ARGUMENTS_AMOUNT 3
1919

2020
enum COMMAND_LINE_MODE
@@ -36,7 +36,9 @@ Mandatory parameters:
3636
-CAMERA_TRANSFORM=mitsubaFilePath or val1,val2,val3,...,val9
3737
-DENOISER_EXPOSURE_BIAS=value
3838
-DENOISER_BLEND_FACTOR=value
39-
-BLOOM_SCALE=theta
39+
-BLOOM_PSF_FILE=psfFilePath
40+
-BLOOM_RELATIVE_SCALE=value
41+
-BLOOM_INTENSITY=value
4042
-TONEMAPPER=tonemapper=keyValue,extraParameter
4143
-OUTPUT=file.choosenextension
4244
Optional Parameters:
@@ -45,7 +47,6 @@ Optional Parameters:
4547
-COLOR_CHANNEL_NAME=colorChannelName
4648
-ALBEDO_CHANNEL_NAME=albedoChannelName
4749
-NORMAL_CHANNEL_NAME=normalChannelName
48-
-BLOOM_PSF_FILE=psfFilePath
4950
5051
Note there mustn't be any space characters!
5152
All files' (except the bloom kernel) resolutions must match!
@@ -73,9 +74,14 @@ you should use the Tonemapping Operator's Key Value.
7374
7475
DENOISER_BLEND_FACTOR: denoiser blend factor, 0.0 is full denoise, 1.0 is no denoise.
7576
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.
77+
BLOOM_PSF_FILE: A EXR file with a HDR sprite corresponding to the Point Spread Function you want to convolve the image with.
78+
79+
BLOOM_RELATIVE_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.
80+
You'll usually want to keep this value quite small (below 1/32) to make sure the kernel has a higher pixel density relative to the image, otherwise you'll end up blurring the image (the executable will print a warning).
81+
Do not use it for actually controlling the size of the flare, this is because even though the kernel is scaled, it is normalized to conserve energy, which eventually degenerates into an ugly box blur as scale tends to 0.
82+
83+
BLOOM_INTENSITY: Must be in the [0,1] range, it actually controls the size of the flare much better than the relative scale (assuming a good HDR kernel with very long tails).
84+
If you don't want bloom then set bloom intensity to 0.
7985
8086
TONEMAPPER: tonemapper - choose between "REINHARD", "ACES" and "NONE". After specifying it you have to pass arguments to revelant tonemapper,
8187
the first argument is always the Key Value, a good default is 0.18 like the Reinhard paper's default.
@@ -100,7 +106,6 @@ while "NONE looks like:
100106
-TONEMAPPER=NONE=AutoexposureOff
101107
102108
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.
104109
The kernel must be centered and in RGB or RGBA floating point format. Resolution should be less than the denoised image.
105110
If this file is not provided then we use a built-in PSF as the kernel for the convolution.
106111
)";
@@ -109,7 +114,9 @@ constexpr std::string_view COLOR_FILE = "COLOR_FILE";
109114
constexpr std::string_view CAMERA_TRANSFORM = "CAMERA_TRANSFORM";
110115
constexpr std::string_view DENOISER_EXPOSURE_BIAS = "DENOISER_EXPOSURE_BIAS";
111116
constexpr std::string_view DENOISER_BLEND_FACTOR = "DENOISER_BLEND_FACTOR";
112-
constexpr std::string_view BLOOM_SCALE = "BLOOM_SCALE";
117+
constexpr std::string_view BLOOM_PSF_FILE = "BLOOM_PSF_FILE";
118+
constexpr std::string_view BLOOM_RELATIVE_SCALE = "BLOOM_RELATIVE_SCALE";
119+
constexpr std::string_view BLOOM_INTENSITY = "BLOOM_INTENSITY";
113120
constexpr std::string_view TONEMAPPER = "TONEMAPPER";
114121
constexpr std::string_view REINHARD = "REINHARD";
115122
constexpr std::string_view ACES = "ACES";
@@ -121,15 +128,16 @@ constexpr std::string_view NORMAL_FILE = "NORMAL_FILE";
121128
constexpr std::string_view COLOR_CHANNEL_NAME = "COLOR_CHANNEL_NAME";
122129
constexpr std::string_view ALBEDO_CHANNEL_NAME = "ALBEDO_CHANNEL_NAME";
123130
constexpr std::string_view NORMAL_CHANNEL_NAME = "NORMAL_CHANNEL_NAME";
124-
constexpr std::string_view BLOOM_PSF_FILE = "BLOOM_PSF_FILE";
125131

126132
constexpr std::array<std::string_view, MANDATORY_CMD_ARGUMENTS_AMOUNT> REQUIRED_PARAMETERS =
127133
{
128134
COLOR_FILE,
129135
CAMERA_TRANSFORM,
130136
DENOISER_EXPOSURE_BIAS,
131137
DENOISER_BLEND_FACTOR,
132-
BLOOM_SCALE,
138+
BLOOM_PSF_FILE,
139+
BLOOM_RELATIVE_SCALE,
140+
BLOOM_INTENSITY,
133141
TONEMAPPER,
134142
OUTPUT
135143
};
@@ -144,7 +152,9 @@ enum DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS
144152
DTEA_CAMERA_TRANSFORM,
145153
DTEA_DENOISER_EXPOSURE_BIAS,
146154
DTEA_DENOISER_BLEND_FACTOR,
147-
DTEA_BLOOM_SCALE,
155+
DTEA_BLOOM_PSF_FILE,
156+
DTEA_BLOOM_RELATIVE_SCALE,
157+
DTEA_BLOOM_INTENSITY,
148158
DTEA_TONEMAPPER,
149159
DTEA_TONEMAPPER_REINHARD,
150160
DTEA_TONEMAPPER_ACES,
@@ -160,7 +170,6 @@ enum DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS
160170
DTEA_COLOR_CHANNEL_NAME,
161171
DTEA_ALBEDO_CHANNEL_NAME,
162172
DTEA_NORMAL_CHANNEL_NAME,
163-
DTEA_BLOOM_PSF_FILE,
164173

165174
DTEA_COUNT
166175
};
@@ -234,9 +243,14 @@ class CommandLineHandler
234243
return denoiserBlendFactorBundle;
235244
}
236245

237-
auto& getBloomScaleBundle() const
246+
auto& getBloomRelativeScaleBundle() const
238247
{
239-
return bloomScaleBundle;
248+
return bloomRelativeScaleBundle;
249+
}
250+
251+
auto& getBloomIntensityBundle() const
252+
{
253+
return bloomIntensityBundle;
240254
}
241255

242256
auto& getTonemapperBundle() const
@@ -266,7 +280,9 @@ class CommandLineHandler
266280
rawVariablesPerFile[DTEA_CAMERA_TRANSFORM];
267281
rawVariablesPerFile[DTEA_DENOISER_EXPOSURE_BIAS];
268282
rawVariablesPerFile[DTEA_DENOISER_BLEND_FACTOR];
269-
rawVariablesPerFile[DTEA_BLOOM_SCALE];
283+
rawVariablesPerFile[DTEA_BLOOM_PSF_FILE];
284+
rawVariablesPerFile[DTEA_BLOOM_RELATIVE_SCALE];
285+
rawVariablesPerFile[DTEA_BLOOM_INTENSITY];
270286
rawVariablesPerFile[DTEA_TONEMAPPER_REINHARD];
271287
rawVariablesPerFile[DTEA_TONEMAPPER_ACES];
272288
rawVariablesPerFile[DTEA_TONEMAPPER_NONE];
@@ -277,7 +293,6 @@ class CommandLineHandler
277293
rawVariablesPerFile[DTEA_COLOR_CHANNEL_NAME];
278294
rawVariablesPerFile[DTEA_ALBEDO_CHANNEL_NAME];
279295
rawVariablesPerFile[DTEA_NORMAL_CHANNEL_NAME];
280-
rawVariablesPerFile[DTEA_BLOOM_PSF_FILE];
281296
}
282297

283298
DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS getMatchedVariableMapID(const std::string& variableName)
@@ -290,8 +305,12 @@ class CommandLineHandler
290305
return DTEA_DENOISER_EXPOSURE_BIAS;
291306
else if (variableName == DENOISER_BLEND_FACTOR)
292307
return DTEA_DENOISER_BLEND_FACTOR;
293-
else if (variableName == BLOOM_SCALE)
294-
return DTEA_BLOOM_SCALE;
308+
else if (variableName == BLOOM_PSF_FILE)
309+
return DTEA_BLOOM_PSF_FILE;
310+
else if (variableName == BLOOM_RELATIVE_SCALE)
311+
return DTEA_BLOOM_RELATIVE_SCALE;
312+
else if (variableName == BLOOM_INTENSITY)
313+
return DTEA_BLOOM_INTENSITY;
295314
else if (variableName == TONEMAPPER)
296315
return DTEA_TONEMAPPER;
297316
else if (variableName == REINHARD)
@@ -312,8 +331,6 @@ class CommandLineHandler
312331
return DTEA_ALBEDO_CHANNEL_NAME;
313332
else if (variableName == NORMAL_CHANNEL_NAME)
314333
return DTEA_NORMAL_CHANNEL_NAME;
315-
else if (variableName == BLOOM_PSF_FILE)
316-
return DTEA_BLOOM_PSF_FILE;
317334
else
318335
return DTEA_COUNT;
319336
}
@@ -342,9 +359,14 @@ class CommandLineHandler
342359
return std::stof(rawVariables[id][DTEA_DENOISER_BLEND_FACTOR].value()[0]);
343360
}
344361

345-
auto getBloomScale(uint64_t id = 0)
362+
auto getBloomRelativeScale(uint64_t id = 0)
363+
{
364+
return std::stof(rawVariables[id][DTEA_BLOOM_RELATIVE_SCALE].value()[0]);
365+
}
366+
367+
auto getBloomIntensity(uint64_t id = 0)
346368
{
347-
return std::stof(rawVariables[id][DTEA_BLOOM_SCALE].value()[0]);
369+
return std::stof(rawVariables[id][DTEA_BLOOM_INTENSITY].value()[0]);
348370
}
349371

350372
auto getTonemapper(uint64_t id = 0)
@@ -438,10 +460,11 @@ class CommandLineHandler
438460
cameraTransformBundle.reserve(inputFilesAmount);
439461
denoiserExposureBiasBundle.reserve(inputFilesAmount);
440462
denoiserBlendFactorBundle.reserve(inputFilesAmount);
441-
bloomScaleBundle.reserve(inputFilesAmount);
463+
bloomPsfFileNameBundle.reserve(inputFilesAmount);
464+
bloomRelativeScaleBundle.reserve(inputFilesAmount);
465+
bloomIntensityBundle.reserve(inputFilesAmount);
442466
tonemapperBundle.reserve(inputFilesAmount);
443467
outputFileNameBundle.reserve(inputFilesAmount);
444-
bloomPsfFileNameBundle.reserve(inputFilesAmount);
445468

446469
for (auto i = 0ul; i < inputFilesAmount; ++i)
447470
{
@@ -454,10 +477,11 @@ class CommandLineHandler
454477
cameraTransformBundle.push_back(getCameraTransform(i));
455478
denoiserExposureBiasBundle.push_back(getDenoiserExposureBias(i));
456479
denoiserBlendFactorBundle.push_back(getDenoiserBlendFactor(i));
457-
bloomScaleBundle.push_back(getBloomScale(i));
480+
bloomPsfFileNameBundle.push_back(getBloomPsfFile(i));
481+
bloomRelativeScaleBundle.push_back(getBloomRelativeScale(i));
482+
bloomIntensityBundle.push_back(getBloomIntensity(i));
458483
tonemapperBundle.push_back(getTonemapper(i));
459484
outputFileNameBundle.push_back(getOutputFile(i));
460-
bloomPsfFileNameBundle.push_back(getBloomPsfFile(i));
461485
}
462486
}
463487

@@ -478,10 +502,11 @@ class CommandLineHandler
478502
nbl::core::vector<std::optional<nbl::core::matrix3x4SIMD>> cameraTransformBundle;
479503
nbl::core::vector<std::optional<float>> denoiserExposureBiasBundle;
480504
nbl::core::vector<std::optional<float>> denoiserBlendFactorBundle;
481-
nbl::core::vector<std::optional<float>> bloomScaleBundle;
505+
nbl::core::vector<std::optional<std::string>> bloomPsfFileNameBundle;
506+
nbl::core::vector<std::optional<float>> bloomRelativeScaleBundle;
507+
nbl::core::vector<std::optional<float>> bloomIntensityBundle;
482508
nbl::core::vector<std::pair<DENOISER_TONEMAPPER_EXAMPLE_ARGUMENTS,nbl::core::vector<float>>> tonemapperBundle;
483509
nbl::core::vector<std::optional<std::string>> outputFileNameBundle;
484-
nbl::core::vector<std::optional<std::string>> bloomPsfFileNameBundle;
485510

486511
std::chrono::nanoseconds elapsedTimeXmls = {};
487512
std::chrono::nanoseconds elapsedTimeEntireLoading = {};
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
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
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=0.0 -BLOOM_PSF_FILE=../../media/kernels/physical_flare_512.exr -BLOOM_RELATIVE_SCALE=0.235 -BLOOM_INTENSITY=0.99 -TONEMAPPER=ACES=0.4,0.8 -OUTPUT=bloom_intens_0_99.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_RELATIVE_SCALE=0.235 -BLOOM_INTENSITY=0.75 -TONEMAPPER=ACES=0.4,0.8 -OUTPUT=bloom_intens_0_75.exr -COLOR_CHANNEL_NAME=color -ALBEDO_CHANNEL_NAME=albedo -NORMAL_CHANNEL_NAME=normal
3+
-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_RELATIVE_SCALE=0.235 -BLOOM_INTENSITY=0.5 -TONEMAPPER=ACES=0.4,0.8 -OUTPUT=bloom_intens_0_5.exr -COLOR_CHANNEL_NAME=color -ALBEDO_CHANNEL_NAME=albedo -NORMAL_CHANNEL_NAME=normal
4+
-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_RELATIVE_SCALE=0.235 -BLOOM_INTENSITY=0.25 -TONEMAPPER=ACES=0.4,0.8 -OUTPUT=bloom_intens_0_25.exr -COLOR_CHANNEL_NAME=color -ALBEDO_CHANNEL_NAME=albedo -NORMAL_CHANNEL_NAME=normal
5+
6+
-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_RELATIVE_SCALE=0.01 -BLOOM_INTENSITY=0.0 -TONEMAPPER=ACES=0.4,0.8 -OUTPUT=reference.exr -COLOR_CHANNEL_NAME=color -ALBEDO_CHANNEL_NAME=albedo -NORMAL_CHANNEL_NAME=normal

0 commit comments

Comments
 (0)