Skip to content

Commit

Permalink
Added the support for lateral and longitudinal chromatic aberration (…
Browse files Browse the repository at this point in the history
…issue #409)
  • Loading branch information
Dade916 committed Jul 27, 2020
1 parent 02f9f4a commit 162c0fd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
9 changes: 5 additions & 4 deletions include/slg/film/imagepipeline/plugins/coloraberration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,14 +49,15 @@ class ColorAberrationPlugin : public ImagePipelinePlugin {
virtual void AddHWChannelsUsed(std::unordered_set<Film::FilmChannelType> &hwChannelsUsed) const;
virtual void ApplyHW(Film &film, const u_int index);

float amount;
float amountX, amountY;

friend class boost::serialization::access;

private:
template<class Archive> 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,
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions release-notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions scenes/luxball/luxball-imagepipelines.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 10 additions & 2 deletions src/slg/film/filmparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(), 0.f, 1.f);
const Property &p = props.Get(Property(prefix + ".amount")(.005f));
float scaleX, scaleY;
if (p.GetSize() == 2) {
scaleX = Clamp(p.Get<float>(0), 0.f, 1.f);
scaleY = Clamp(p.Get<float>(1), 0.f, 1.f);
} else {
scaleX = Clamp(p.Get<float>(), 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") {
Expand Down
16 changes: 9 additions & 7 deletions src/slg/film/imagepipeline/plugins/coloraberration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -55,7 +56,7 @@ ColorAberrationPlugin::~ColorAberrationPlugin() {
}

ImagePipelinePlugin *ColorAberrationPlugin::Copy() const {
return new ColorAberrationPlugin(amount);
return new ColorAberrationPlugin(amountX, amountY);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 162c0fd

Please sign in to comment.