BitReduction Hydra
From Adobe Labs
/*****************************************************************************
*
* Author: Jan Van Coppenolle
* http://compiler.kaustic.com/lab
*
*****************************************************************************/
kernel BitReduction
{
parameter int channelBitDepth
<
minValue: 1;
maxValue: 8;
defaultValue: 8;
>;
void evaluatePixel(in image3 src, out pixel3 dst)
{
pixel3 px = sampleNearest(src, outCoord());
float levels = pow(2.0, float(channelBitDepth));
int3 bp = int3(px * 255.0) * int(levels) / 256;
dst = float3(bp) / (levels - 1.0);
}
}