Skip to content

Instantly share code, notes, and snippets.

@sgss
Created January 21, 2012 13:44
Show Gist options
  • Save sgss/1652814 to your computer and use it in GitHub Desktop.
Save sgss/1652814 to your computer and use it in GitHub Desktop.
TransparentizeGreenChannel
<languageVersion: 1.0;>
kernel TransparentizeGreenChannel
< namespace : "Sgss";
vendor : "Matsuda Shota";
version : 1;
description : "Recovers transparency of grayscale image with key channel"; >
{
input image4 sourceImage;
output float4 destinationColor;
void evaluatePixel()
{
float4 sourceColor = sample(sourceImage, outCoord());
destinationColor.a = 1.0;
float keyChannel = sourceColor.g;
float baseChannel = sourceColor.r;
float outputAlpha = (1.0 - keyChannel) + baseChannel;
float outputChannel = baseChannel / outputAlpha;
if (keyChannel == baseChannel) {
outputChannel = baseChannel;
outputAlpha = 1.0;
}
destinationColor.rgb = float3(outputChannel, outputChannel, outputChannel);
destinationColor.a = outputAlpha;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment