Members - Reputation: 139
Posted 01 April 2013 - 04:57 AM
Moderators - Reputation: 36499
Posted 01 April 2013 - 05:24 AM
I haven't tried this code (just typed it into the forum), but it might be worth a try
This should pack two 0-1 range floats into the hi/low 4 bits of an 8 bit fraction.
//quantize from 0-1 floats, to 0-15 integers, which can be represented in 4 bits a = round(a*15); b = round(b*15); //bit shift a into the upper 4 bits of the fraction, and b into the lower 4 bits float c = dot( float2(a,b), float2(1.0/(255.0/16.0), 1.0/255.0 ) ); return c to an 8-bit render target
float c = tex2d(...) //point sampling and/or tex-coord at exact texel centres. //shift so that a is in the integer part and b in the fractional part float temp = c * 255.0/16.0; //reconstruct the original (but quantized) a&b float a = floor(temp) / 15.0; float b = frac(temp) * 16.0/15.0;