/* 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: QameraGlassDecoBricks.qtzThis takes two input images in addition to the primary image input. It samples the dx and dy from the displacement maps and then distorts the sample coordinate of the source image by (dx,dy). This kernel can generate an extremely wide variety of distortion effects simply by manipulating the 2D map images. We're getting everything from glass effects to "Chuck Close" style halftone effects.
kernel vec4 msBlackDisplacementMaps(sampler input_image, sampler input_map_x, sampler input_map_y, float input_range_normal)
{
float input_range = clamp(input_range_normal,0.0,1.0);
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
vec4 maxel_x = sample(input_map_x, samplerCoord(input_map_x));
vec4 maxel_y = sample(input_map_y, samplerCoord(input_map_y));
float dx_normal = input_range*dot(vec3(maxel_x),vec3(maxel_x));
float dy_normal = input_range*dot(vec3(maxel_y),vec3(maxel_y));
pixel_coord.x += dx_normal * image_size.x;
pixel_coord.y += dy_normal * image_size.y;
return sample(input_image, pixel_coord);
}