/* 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: Qamera3DDiscoDanceFloor.qtzThis Kernel makes a rectangular mask inset
input_pixels from the edge of the source image, and attenuated by the
input_fade_power.
float radians_from_degrees(const float in_degrees)
{
const float M_PI = 3.1415926535897932384;
return in_degrees * (M_PI/180.0);
}
kernel vec4 msBlackSoftBoxMask(sampler input_image, float input_pixels, float input_angle_degrees, float input_fade_power)
{
vec2 image_size = samplerSize(input_image);
vec2 image_center = image_size*0.5;
vec2 pixel_coord = samplerCoord(input_image);
vec2 pixel_xy = pixel_coord-image_center;
float theta = radians_from_degrees(input_angle_degrees);
float cos_theta = cos(theta);
float sin_theta = sin(theta);
vec2 rotate_x = vec2(cos_theta,-sin_theta);
vec2 rotate_y = vec2(sin_theta,cos_theta);
float xx = dot(rotate_x, pixel_xy);
float yy = dot(rotate_y, pixel_xy);
pixel_coord = image_center + vec2(xx,yy);
float dist_top = abs(pixel_coord.y-0.0);
float dist_left = abs(pixel_coord.x-0.0);
float dist_right = abs(image_size.x-pixel_coord.x);
float dist_bottom = abs(image_size.y-pixel_coord.y);
vec4 pixel = sample(input_image,samplerCoord(input_image));
const float opaque = 1.0;
float alpha = opaque;
const float power = input_fade_power;
float semi_transparent_left = clamp(pow(dist_left/input_pixels,power),0.0,1.0);
alpha = (dist_left<input_pixels) ? min(semi_transparent_left,alpha): alpha;
float semi_transparent_top = clamp(pow(dist_top/input_pixels,power),0.0,1.0);
alpha = (dist_top<input_pixels) ? min(semi_transparent_top,alpha): alpha;
float semi_transparent_right = clamp(pow(dist_right/input_pixels,power),0.0,1.0);
alpha = (dist_right<input_pixels) ? min(semi_transparent_right,alpha) : alpha;
float semi_transparent_bottom = clamp(pow(dist_bottom/input_pixels,power),0.0,1.0);
alpha = (dist_bottom<input_pixels) ? min(semi_transparent_bottom,alpha) : alpha;
pixel.a = alpha;
return pixel;
}
Labels: alpha channel, mask