Jump to content
  • Advertisement
Sign in to follow this  
blueshogun96

Gamma Ramp question

This topic is 4819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone explain to me how the Direct3D gamma ramp works? I'm a little confused on how it works. I know how to change and adjust it, but I don't understand it to the point where I can make my scene's fade in and out or flash a certain color. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
The gamma ramp is a remapping/lookup table. The values of the R,G, and B components of a colour are used as array indices to index into the gamma ramp table; the values read from the gamma ramp table are what gets displayed by the video hardware.


Think of it as working like this (except done by the hardware):


struct INPUT_COLOUR
{
BYTE red, green, blue;
};

struct OUTPUT_COLOUR
{
WORD red, green, blue;
};

OUTPUT_COLOUR ApplyGammaRamp( INPUT_COLOUR input, D3DGAMMARAMP gammaRamp )
{
OUTPUT_COLOUR output;

output.red = gammaRamp.red[ input.red ];
output.green = gammaRamp.green[ input.green ];
output.blue = gammaRamp.blue[ input.blue ];

return output;
}



The input to the gamma ramp is an 8-bit value (i.e. in the range 0 to 255), and the output of the gamma ramp is a 16bit value (i.e. in the range of 0 to 65535); the reason for this is one of the reasons for gamma correction in the first place - human vision isn't linear, the output of a monitor/TV isn't linear, and 8 bits isn't enough to represent the range well enough (you need at least 12, which is what many RAMDACs use).

So to tint the output a certain colour, just tint all the entries in the gamma ramp by that colour, scaled by the position in the table; and to fade, just scale all the values in the table.

If you want to know more about gamma in general, Charles Poynton's site is an excellent resource: http://www.poynton.com/GammaFAQ.html

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!