Skip to content

Commit

Permalink
Configure inverse gamma.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeschkies committed Mar 3, 2016
1 parent a535285 commit cc8c193
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
28 changes: 14 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ R"(Usage: raytracer <filename> [options]
-m --monte-carlo-samples=<int> Monto Carlo samples per ray [default: 8].
Used only in pathtracer.
-t --threads=<int> Number of threads [default: 1].
--inverse-gamma=<float> Inverse of gamma for gamma correction
[default: 0.454545].
--no-gamma-correction Disables gamma correction.
)";

Expand All @@ -90,14 +92,15 @@ int main(int argc, char const *argv[])
std::map<std::string, docopt::value> args =
docopt::docopt(USAGE, {argv + 1, argv + argc}, true, "raytracer 0.2");

Configuration conf { args["--max-depth"].asLong()
, std::stof(args["--shadow"].asString())
, args["--pixel-samples"].asLong()
, args["--monte-carlo-samples"].asLong()
, args["--threads"].asLong()
, args["--background"].asString()
, args["--no-gamma-correction"].asBool()
};
const Configuration conf { args["--max-depth"].asLong()
, std::stof(args["--shadow"].asString())
, args["--pixel-samples"].asLong()
, args["--monte-carlo-samples"].asLong()
, args["--threads"].asLong()
, args["--background"].asString()
, std::stof(args["--inverse-gamma"].asString())
, args["--no-gamma-correction"].asBool()
};

// import scene
Assimp::Importer importer;
Expand Down Expand Up @@ -167,9 +170,6 @@ int main(int argc, char const *argv[])

std::cerr << "Rendering ";

// TODO: Use conf.
constexpr float inv_gamma = 1.f/2.2f;

ThreadPool pool(conf.num_threads);
std::vector<std::future<void>> tasks;

Expand Down Expand Up @@ -197,9 +197,9 @@ int main(int argc, char const *argv[])

// gamma correction
if (conf.gamma_correction_enabled) {
image(x, y).r = powf(image(x, y).r, inv_gamma);
image(x, y).g = powf(image(x, y).g, inv_gamma);
image(x, y).b = powf(image(x, y).b, inv_gamma);
image(x, y).r = powf(image(x, y).r, conf.inverse_gamma);
image(x, y).g = powf(image(x, y).g, conf.inverse_gamma);
image(x, y).b = powf(image(x, y).b, conf.inverse_gamma);
}
}
}));
Expand Down
6 changes: 5 additions & 1 deletion tests/test_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ SCENARIO("Create config from options", "[config]") {
GIVEN("A background color") {
std::string bg_color = "0 0.3 1.0";

GIVEN("An inverse of gamma") {
float inv_gamma = 1.f/2.2f;

GIVEN("A gamma correction flag") {
bool no_gamma = false;

Expand All @@ -31,6 +34,7 @@ SCENARIO("Create config from options", "[config]") {
, num_monte_carlo_samples
, num_threads
, bg_color
, inv_gamma
, no_gamma
};

Expand All @@ -42,5 +46,5 @@ SCENARIO("Create config from options", "[config]") {
REQUIRE(config.num_threads == 4);
REQUIRE(config.gamma_correction_enabled == true);
REQUIRE(config.bg_color == Color(0.0f, 0.3f, 1.0f, 1.0f));
}}}}}}}}}
}}}}}}}}}}
}
3 changes: 3 additions & 0 deletions trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ class Configuration {
long num_monte_carlo_samples,
long num_threads,
const std::string& bg_color_str,
float inverse_gamma,
const bool no_gamma_correction):
max_depth(max_depth),
shadow_intensity(shadow_intensity),
num_pixel_samples(num_pixel_samples),
num_monte_carlo_samples(num_monte_carlo_samples),
num_threads(num_threads),
inverse_gamma(inverse_gamma),
gamma_correction_enabled(!no_gamma_correction)
{
check();
Expand Down Expand Up @@ -62,6 +64,7 @@ class Configuration {
int num_pixel_samples;
int num_monte_carlo_samples;
int num_threads;
float inverse_gamma;
bool gamma_correction_enabled;
Color bg_color;
};
Expand Down

0 comments on commit cc8c193

Please sign in to comment.