/* Published by b-l-a-c-k-o-p.com
Copyright (c) 2007-2012
http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
*/
SAMPLE: QameraConcave.qtz This filter can flex the image in both inward and outward directions. My goal was to have it take normalized parameters and have the two inward and outward flexes to be symmetrical. Didn't quite get it, but close enough.
kernel vec4 msBlackLensFlex(sampler image, vec2 center, float input_factor_normal, float input_sign, float input_scale_normal)
{
vec2 vector = destCoord() - center;
float distance_from_center = length(vector);
vec2 distance_normal = normalize(vector);
float input_factor = clamp(input_factor_normal,0.0,1.0);
float input_scale = -input_sign*((1.0-input_sign)-clamp(input_scale_normal,0.0,1.0));
float distance_sq = distance_from_center*distance_from_center;
vec2 image_size = samplerSize(image);
float max_factor = max(image_size.x,image_size.y);
float lens_factor = abs(input_factor)*max_factor;
float lens_factor_sq = input_sign*lens_factor*lens_factor;
float dxdy = input_scale * distance_from_center / (1.0 - (distance_sq/lens_factor_sq) );
vec2 pixel_offset = center + dxdy * distance_normal;
vec4 pixel = sample(image, samplerTransform(image, pixel_offset));
return pixel;
}