/* 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: QameraSinCityRed.qtzThis kernel simulates a Sin City 1-color only type camera effect. It takes a "find_color" and a "replace_color". It samples each pixel in the source image and calculates the distance (in the RGB cube) from find_color. If the source pixel is within the threshold distance from the find_color, the kernel replaces the pixel in the output image with the replace_color; otherwise, it desaturates the pixel. In the sample, we've mapped the find_color and replace_color to the same color. But if you watch Robert Rodriquez's 15min film school, you will see they used YELLOW as the find_color and RED as the replace color in many situations. Also the sample QTZ has the sensitivity on a LFO to handle different lighting conditions.
kernel vec4 msBlackSinCityColorReplacement(sampler image, float input_threshold_normal, float threshold_sensitivity, __color find_color, __color replace_color)
{
float input_threshold_sensitivity = 2.*(1.0-clamp(threshold_sensitivity,0.0,1.0));
float input_threshold = clamp(pow(input_threshold_normal, input_threshold_sensitivity),0.0,1.0);
vec3 pel_rgb = unpremultiply(sample(image, samplerCoord(image)));
vec3 find_pel = vec3(find_color.r,find_color.g,find_color.b);
vec4 replace_pel = vec3(replace_color.r, replace_color.g, replace_color.b);
replace_pel.a = 1.0;
float distance_in_rgb_cube = distance(find_pel,pel_rgb);
float distance_abs = sqrt(distance_in_rgb_cube*distance_in_rgb_cube);
vec4 pel_avg = (pel_rgb.r + pel_rgb.g + pel_rgb.b)/3.0;
vec4 result = (distance_abs <input_threshold) ? replace_pel : pel_avg;
return result;
}
Labels: chroma