Curtain¶
The Curtain kernel is a componentwise kernel which shifts rows of its input horizontally according to a sine wave, to produce a rippling, curtain-like effect.
The amplitude, phase and period of the wave can be controlled.
// Copyright (c) 2024 The Foundry Visionmongers Ltd. All Rights Reserved.
/// Curtain kernel: Shifts pixels horizontally to produce a rippling effect
kernel CurtainKernel : ImageComputationKernel<eComponentWise>
{
Image<eRead, eAccessRanged1D, eEdgeConstant> src;
Image<eWrite, eAccessPoint> dst;
param:
float amplitudePixels;
float phaseRadians;
float periodPixels;
local:
float angularFrequency;
void define() {
defineParam(amplitudePixels, "Amplitude", 100.0f, eParamProxyScale);
defineParam(phaseRadians, "Phase", PI);
defineParam(periodPixels, "Period", 500.0f, eParamProxyScale);
}
void init() {
src.setRange(-amplitudePixels, amplitudePixels);
src.setAxis(eX);
angularFrequency = 2 * PI / periodPixels;
}
void process(int2 pos) {
int offset = amplitudePixels * sin(pos.y * angularFrequency + phaseRadians);
dst() = src(offset);
}
};