From 162c0fdf70fe872c85480ffdf8f27c1cbf0ac3bd Mon Sep 17 00:00:00 2001 From: David Bucciarelli Date: Mon, 27 Jul 2020 12:25:52 +0200 Subject: [PATCH] Added the support for lateral and longitudinal chromatic aberration (issue #409) --- .../film/imagepipeline/plugins/coloraberration.h | 9 +++++---- .../plugins/plugin_coloraberration_funcs.cl | 10 +++++----- release-notes.txt | 1 + scenes/luxball/luxball-imagepipelines.cfg | 1 + src/slg/film/filmparse.cpp | 12 ++++++++++-- .../imagepipeline/plugins/coloraberration.cpp | 16 +++++++++------- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/include/slg/film/imagepipeline/plugins/coloraberration.h b/include/slg/film/imagepipeline/plugins/coloraberration.h index bc5a48cb7..457f741b2 100644 --- a/include/slg/film/imagepipeline/plugins/coloraberration.h +++ b/include/slg/film/imagepipeline/plugins/coloraberration.h @@ -38,7 +38,7 @@ class Film; class ColorAberrationPlugin : public ImagePipelinePlugin { public: - ColorAberrationPlugin(const float amount = .005f); + ColorAberrationPlugin(const float amountX = .005f, const float amountY = .005f); virtual ~ColorAberrationPlugin(); virtual ImagePipelinePlugin *Copy() const; @@ -49,14 +49,15 @@ class ColorAberrationPlugin : public ImagePipelinePlugin { virtual void AddHWChannelsUsed(std::unordered_set &hwChannelsUsed) const; virtual void ApplyHW(Film &film, const u_int index); - float amount; + float amountX, amountY; friend class boost::serialization::access; private: template void serialize(Archive &ar, const u_int version) { ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ImagePipelinePlugin); - ar & amount; + ar & amountX; + ar & amountY; } static luxrays::Spectrum BilinearSampleImage(const luxrays::Spectrum *pixels, @@ -76,7 +77,7 @@ class ColorAberrationPlugin : public ImagePipelinePlugin { } -BOOST_CLASS_VERSION(slg::ColorAberrationPlugin, 1) +BOOST_CLASS_VERSION(slg::ColorAberrationPlugin, 2) BOOST_CLASS_EXPORT_KEY(slg::ColorAberrationPlugin) diff --git a/include/slg/film/imagepipeline/plugins/plugin_coloraberration_funcs.cl b/include/slg/film/imagepipeline/plugins/plugin_coloraberration_funcs.cl index 14eb19bb2..e34aca108 100644 --- a/include/slg/film/imagepipeline/plugins/plugin_coloraberration_funcs.cl +++ b/include/slg/film/imagepipeline/plugins/plugin_coloraberration_funcs.cl @@ -46,7 +46,7 @@ __kernel void ColorAberrationPlugin_Apply( const uint filmWidth, const uint filmHeight, __global float *channel_IMAGEPIPELINE, __global float *tmpBuffer, - const float amount) { + const float amountX, const float amountY) { const size_t gid = get_global_id(0); if (gid >= filmWidth * filmHeight) return; @@ -61,10 +61,10 @@ __kernel void ColorAberrationPlugin_Apply( const float yOffset = ny - .5f; const float tOffset = sqrt(xOffset * xOffset + yOffset * yOffset); - const float rbX = (.5f + xOffset * (1.f + tOffset * amount)) * filmWidth; - const float rbY = (.5f + yOffset * (1.f + tOffset * amount)) * filmHeight; - const float gX = (.5f + xOffset * (1.f - tOffset * amount)) * filmWidth; - const float gY = (.5f + yOffset * (1.f - tOffset * amount)) * filmHeight; + const float rbX = (.5f + xOffset * (1.f + tOffset * amountX)) * filmWidth; + const float rbY = (.5f + yOffset * (1.f + tOffset * amountY)) * filmHeight; + const float gX = (.5f + xOffset * (1.f - tOffset * amountX)) * filmWidth; + const float gY = (.5f + yOffset * (1.f - tOffset * amountY)) * filmHeight; const float3 redblue = MAKE_FLOAT3(1.f, 0.f, 1.f); const float3 green = MAKE_FLOAT3(0.f, 1.f, 0.f); diff --git a/release-notes.txt b/release-notes.txt index a4d9e7f66..afb32d43f 100644 --- a/release-notes.txt +++ b/release-notes.txt @@ -8,6 +8,7 @@ * batch.haltspp now supports 2 parameters too in order to have separate halt conditions for eye and light tracing * Added the support for camera not uniform and anamorphic bokeh (issue #409) * Variance clamping is now applied separately to each radiance group (issue #414) +* Added the support for lateral and longitudinal chromatic aberration (issue #409) ### Fixed Bugs diff --git a/scenes/luxball/luxball-imagepipelines.cfg b/scenes/luxball/luxball-imagepipelines.cfg index 3054a9c28..408120d52 100644 --- a/scenes/luxball/luxball-imagepipelines.cfg +++ b/scenes/luxball/luxball-imagepipelines.cfg @@ -69,3 +69,4 @@ film.imagepipelines.5.2.type = GAMMA_CORRECTION film.imagepipelines.5.2.value = 2.2 film.imagepipelines.5.0.type = COLOR_ABERRATION film.imagepipelines.5.0.amount = 0.025 +#film.imagepipelines.5.0.amount = 0.025 0.005 diff --git a/src/slg/film/filmparse.cpp b/src/slg/film/filmparse.cpp index 48a2ebef7..eb7fa5c40 100644 --- a/src/slg/film/filmparse.cpp +++ b/src/slg/film/filmparse.cpp @@ -567,9 +567,17 @@ ImagePipeline *Film::CreateImagePipeline(const Properties &props, const string & imagePipeline->AddPlugin(new VignettingPlugin(scale)); } else if (type == "COLOR_ABERRATION") { - const float scale = Clamp(props.Get(Property(prefix + ".amount")(.005f)).Get(), 0.f, 1.f); + const Property &p = props.Get(Property(prefix + ".amount")(.005f)); + float scaleX, scaleY; + if (p.GetSize() == 2) { + scaleX = Clamp(p.Get(0), 0.f, 1.f); + scaleY = Clamp(p.Get(1), 0.f, 1.f); + } else { + scaleX = Clamp(p.Get(), 0.f, 1.f); + scaleY = scaleX; + } - imagePipeline->AddPlugin(new ColorAberrationPlugin(scale)); + imagePipeline->AddPlugin(new ColorAberrationPlugin(scaleX, scaleY)); } else if (type == "PREMULTIPLY_ALPHA") { imagePipeline->AddPlugin(new PremultiplyAlphaPlugin()); } else if (type == "MIST") { diff --git a/src/slg/film/imagepipeline/plugins/coloraberration.cpp b/src/slg/film/imagepipeline/plugins/coloraberration.cpp index 99d85d41b..ea053a48e 100644 --- a/src/slg/film/imagepipeline/plugins/coloraberration.cpp +++ b/src/slg/film/imagepipeline/plugins/coloraberration.cpp @@ -35,7 +35,8 @@ using namespace slg; BOOST_CLASS_EXPORT_IMPLEMENT(slg::ColorAberrationPlugin) -ColorAberrationPlugin::ColorAberrationPlugin(const float a) : amount(a), +ColorAberrationPlugin::ColorAberrationPlugin(const float ax, const float ay) : + amountX(ax), amountY(ay), tmpBuffer(nullptr), tmpBufferSize(0) { hardwareDevice = nullptr; hwTmpBuffer = nullptr; @@ -55,7 +56,7 @@ ColorAberrationPlugin::~ColorAberrationPlugin() { } ImagePipelinePlugin *ColorAberrationPlugin::Copy() const { - return new ColorAberrationPlugin(amount); + return new ColorAberrationPlugin(amountX, amountY); } //------------------------------------------------------------------------------ @@ -117,10 +118,10 @@ void ColorAberrationPlugin::Apply(Film &film, const u_int index) { const float yOffset = ny - .5f; const float tOffset = sqrtf(xOffset * xOffset + yOffset * yOffset); - const float rbX = (.5f + xOffset * (1.f + tOffset * amount)) * width; - const float rbY = (.5f + yOffset * (1.f + tOffset * amount)) * height; - const float gX = (.5f + xOffset * (1.f - tOffset * amount)) * width; - const float gY = (.5f + yOffset * (1.f - tOffset * amount)) * height; + const float rbX = (.5f + xOffset * (1.f + tOffset * amountX)) * width; + const float rbY = (.5f + yOffset * (1.f + tOffset * amountY)) * height; + const float gX = (.5f + xOffset * (1.f - tOffset * amountX)) * width; + const float gY = (.5f + yOffset * (1.f - tOffset * amountY)) * height; static const Spectrum redblue(1.f, 0.f, 1.f); static const Spectrum green(0.f, 1.f, 0.f); @@ -186,7 +187,8 @@ void ColorAberrationPlugin::ApplyHW(Film &film, const u_int index) { hardwareDevice->SetKernelArg(applyKernel, argIndex++, height); hardwareDevice->SetKernelArg(applyKernel, argIndex++, film.hw_IMAGEPIPELINE); hardwareDevice->SetKernelArg(applyKernel, argIndex++, hwTmpBuffer); - hardwareDevice->SetKernelArg(applyKernel, argIndex++, amount); + hardwareDevice->SetKernelArg(applyKernel, argIndex++, amountX); + hardwareDevice->SetKernelArg(applyKernel, argIndex++, amountY); //---------------------------------------------------------------------- // ColorAberrationPlugin_Copy kernel