/* 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: QameraVHSPlayBack.qtzThis kernel evaluates the sawtooth waveform at each vertical pixel location, x, and computes the alpha based on the value of the function at that point.
const float M_PI = 3.1415926535897932384;
const float period_degrees = 180.0;
float inverse_saw(float in_angle_degrees)
{
float angle_degrees = clamp(in_angle_degrees,0.0, period_degrees);
float value_normal = angle_degrees/period_degrees;
float value_if_nz = (value_normal*2.0 - 1.0);
float value = (angle_degrees==0.0) ? 0.0 : -1.0*value_if_nz;
return value;
}
kernel vec4 msBlackHorizontalSawMask(sampler input_image, float input_frequency, float input_amplitude, float input_offset, float input_phase)
{
vec2 image_size = samplerSize(input_image);
vec2 pixel_coord = samplerCoord(input_image);
vec4 pixel = sample(input_image, pixel_coord);
float pixel_y_normal = pixel_coord.y/image_size.y;
float degrees = (pixel_y_normal* period_degrees);
float phase = clamp(input_phase* period_degrees,0.0, period_degrees);
float alpha = input_offset + (input_amplitude * mod(phase+input_frequency* inverse_saw(degrees),1.0));
pixel.a = alpha*pixel.a;
return vec4(clamp(pixel, 0.0, 1.0));
}
Labels: alpha channel, mask