I've been trying to figure out a way to map a gamma ramp generation function I have (obtained through RE) to an HLSL/GLSL function/operator, in an effort to emulate the "look and feel" of an older game I fiddle with in my spare time.
however, I'm failing to get anywhere because I'm not sure how the gamma ramp set by D3DDevice9::SetGammaRamp gets used when outputting a pixel. what I'm looking for is: if I have the RGB tuple "x" what operations are performed on x's channels using the ramp that yield the final pixel rendered to the back buffer?
The ramp generation looks like so if it helps in any way:
void GenGammaRamp(long dwGamma, double fContrast, double* pRamp)
{
double fGamma = (double)dwGamma;
double fFractGamma = 0.01 * fGamma;
double fGammaPercent = 100.0 / fGamma;
double fRampEnd = 255.0;
double fMaxGamma = 65535.0;
double fGammaFactor = 1.0 / fRampEnd;
for(double fRamp = 0.0; fRamp < fRampEnd; fRamp += 1.0)
{
double fGammaStep = fGammaFactor * fRamp * fMaxGamma * fFractGamma;
fGammaStep = fGammaStep > fMaxGamma ? fMaxGamma : fGammaStep;
double fFinalGamma = (pow(fGammaFactor * fRamp,fGammaPercent) * fMaxGamma * (100.0 - fContrast) + fGammaStep * fContrast) * 0.01;
pRamp[(int)fRamp] = fFinalGamma;
}
}
(the values get converted to back to 8/16/32 bit integers just before the are sent off to the driver).