topical media & game development
graphic-flex-image-effects-05-source-horizontalLines.pbk / pbk
<languageVersion : 1.0;>
kernel HorizontalLines
<
namespace: "com.27Bobs";
vendor: "Todd Yard";
version: 1;
description: "Draws horizontal lines over darker areas of image.";
>
{
parameter float levelsThreshold
<
minValue: 0.0;
maxValue: 1.0;
defaultValue: 0.4;
description: "The threshold used to determine the light and dark areas.";
>;
parameter float4 foregroundColor
<
minValue: float4(0.0, 0.0, 0.0, 0.0);
maxValue: float4(1.0, 1.0, 1.0, 1.0);
defaultValue: float4(1.0, 1.0, 1.0, 1.0);
description: "the color to use for the lighter areas of the image";
>;
parameter float4 backgroundColor
<
minValue: float4(0.0, 0.0, 0.0, 0.0);
maxValue: float4(1.0, 1.0, 1.0, 1.0);
defaultValue: float4(0.0, 0.0, 0.0, 1.0);
description: "the color to use for the darker areas of the image";
>;
input image4 source;
output pixel4 result;
void
evaluatePixel()
{
float2 coord = outCoord();
pixel4 px = sampleNearest(source, coord);
// only perform threshold check on odd lines
if (mod(coord.y, 2.0) >= 1.0) {
// reduce px to two levels per channel
float numLevels = 2.0;
px = floor(px*numLevels)/numLevels;
float luminance = px.r * 0.3 +
px.g * 0.59 +
px.b * 0.11;
// if luminance of altered pixel is less that or equal
// to threshold, use background color for pixel
if (luminance <= levelsThreshold) {
px = backgroundColor;
// else use foreground color for pixel
} else {
px = foregroundColor;
}
// event lines all get foreground color
} else {
px = foregroundColor;
}
result = px;
}
}
(C) Æliens
18/6/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.