אפקט של תאורה ציבעונית על ידי פנס. יש אופצייה לשנות צבעים ולהגביר את עוצמת האור של הפנס.
ניתן להזיז את הפנס על גבי התמונה בעזרת העכבר.
וזה הקוד שיוצר את האפקט
<languageVersion : 1.0;>
kernel Flashlight
<
namespace : "Light";
vendor : "Ronen Tsamir";
version : 1;
description : "Flashlight effect";
>
{
// Set The input parameters
parameter float radius
<
minValue: 0.0;
maxValue: 600.0;
defaultValue: 30.0;
>;
parameter pixel4 color
<
minValue: float4(0.0,0.0,0.0,0.0);
maxValue: float4(2.0,2.0,2.0,2.0);
defaultValue: float4(0.58,0.94,0.84,0.02);
>;
parameter pixel2 center
<
minValue: pixel2(0,0);
maxValue: pixel2(500,500);
defaultValue: pixel2(200,200);
>;
input image4 src;
output pixel4 result;
// this functuin call for each pixel.
void evaluatePixel()
{
// Get the current pixel location
float2 coord_for_this_pixel = outCoord();
// Get the distance from the center
pixel2 C;
C.x= coord_for_this_pixel.x - center.x;
C.y= coord_for_this_pixel.y - center.y;
float R = sqrt(C.x * C.x + C.y * C.y);
// manipulation the outpot color of the pixel.
result = sampleNearest(src, coord_for_this_pixel) * (1.0 + color - color * sqrt(R / radius));
}
}
kernel Flashlight
<
namespace : "Light";
vendor : "Ronen Tsamir";
version : 1;
description : "Flashlight effect";
>
{
// Set The input parameters
parameter float radius
<
minValue: 0.0;
maxValue: 600.0;
defaultValue: 30.0;
>;
parameter pixel4 color
<
minValue: float4(0.0,0.0,0.0,0.0);
maxValue: float4(2.0,2.0,2.0,2.0);
defaultValue: float4(0.58,0.94,0.84,0.02);
>;
parameter pixel2 center
<
minValue: pixel2(0,0);
maxValue: pixel2(500,500);
defaultValue: pixel2(200,200);
>;
input image4 src;
output pixel4 result;
// this functuin call for each pixel.
void evaluatePixel()
{
// Get the current pixel location
float2 coord_for_this_pixel = outCoord();
// Get the distance from the center
pixel2 C;
C.x= coord_for_this_pixel.x - center.x;
C.y= coord_for_this_pixel.y - center.y;
float R = sqrt(C.x * C.x + C.y * C.y);
// manipulation the outpot color of the pixel.
result = sampleNearest(src, coord_for_this_pixel) * (1.0 + color - color * sqrt(R / radius));
}
}