diff --git a/RayTracer/sampling/Image.cpp b/RayTracer/sampling/Image.cpp index 86555124e54021675f62f27e21a14f33b68ec248..b82813cbb4e66b4034fdbaff4b25de8e097c6ad2 100644 --- a/RayTracer/sampling/Image.cpp +++ b/RayTracer/sampling/Image.cpp @@ -35,7 +35,18 @@ void Image::setPixels(size_t threadcount, std::shared_ptr<Sampler> sampler) { } void Image::setPixelsTask(int x, int y, std::shared_ptr<Sampler> sampler) { - setPixel(x, y, sampler->color(x, y)); + Vec3 v = sampler->color(x, y); + setPixel(x, y, v); +} + +void Image::gammaCorrect(float gamma) { + // correct the whole data-array with the given gamma + std::transform(vec.begin(), vec.end(), vec.begin(), + [gamma](util::Vec3 v) -> util::Vec3 { + return util::Vec3(std::powf(v.x(), 1 / gamma), + std::powf(v.y(), 1 / gamma), + std::powf(v.z(), 1 / gamma)); + }); } Vec3 Image::operator[](const std::array<int, 2>& i) const { return vec[width * i[1] + i[0]]; @@ -51,6 +62,7 @@ Image raytrace(size_t threadcount, const cam::CamObs& cam, StratifiedSampler(sampler, n)) // sampler ); + result.gammaCorrect(2.2); return result; } } // namespace util \ No newline at end of file diff --git a/RayTracer/sampling/Image.h b/RayTracer/sampling/Image.h index c23b1f12fa27a08aa42a7bc587c87b9007cb53f5..10f95f8160d1f7c2b770e529ee9a0e75460d43b1 100644 --- a/RayTracer/sampling/Image.h +++ b/RayTracer/sampling/Image.h @@ -18,6 +18,7 @@ class Image { const int width; const int height; + void gammaCorrect(float gamma); protected: void setPixelsTask(int x, int y, std::shared_ptr<Sampler> sampler);