topical media & game development
graphic-flex-image-effects-02-source-luminosity.pbk / pbk
<languageVersion : 1.0;>
kernel Luminosity
< namespace: "com.27Bobs";
vendor: "Todd Yard";
version: 1;
description: "Applies the luminosity of the source image to the background image.";
>
{
parameter float percent
<
minValue: 0.0;
maxValue: 1.0;
defaultValue: 1.0;
description: "The amount of blend to apply.";
>;
input image4 source;
input image4 background;
output pixel4 result;
void
evaluatePixel()
{
float2 coord = outCoord();
pixel4 px = sampleNearest(background, coord);
float backgroundLuminance = px.r * 0.3 +
px.g * 0.59 +
px.b * 0.11;
px = sampleNearest(source, coord);
float sourceLuminance = px.r * 0.3 +
px.g * 0.59 +
px.b * 0.11;
float luminance = backgroundLuminance - sourceLuminance;
pixel4 fullBlend = px;
fullBlend.r += luminance;
fullBlend.g += luminance;
fullBlend.b += luminance;
result = mix(px, fullBlend, percent);
}
}
(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.