Setting Gamma.......

Started by
5 comments, last by Sandeep 19 years, 7 months ago
Hey all! I was trying to have a gamma setting slider to tweak it at runtime. Any ideas how to go about changing gamma values? Using - DX 9.0c Have to use SetGammaRamp....tried using it, no luck. Please let me know if i have to do anything different when in fullscreen or window modes. Thanks! Best, San
If there is one way to do it, and only one way, it WILL fail.
Advertisement
Setting of the gamma values is very much hardware specific, and you need to check the D3DCAPS9 report to see if your card allows it.

iirc, post DX7 a lot of hardware/drivers dropped support for it - my GF256 at the time ceased to allow gamma under DX8 but was perfectly happy with it under DX7!

If you look at a lot of shader code floating around, people do some times include gamma correction as the final step in the px shader. Which may well be why quite a few top-level game engines "still" support gamma correction even if the D3DCAPS9 says the hardware doesn't like it.

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Thanks Jack!
Do you have any idea how to use SetGammaRamp anyway? Have you got the damn thing working at all!!

Nothing happens.....i tried setting the RGB table to both extremes...nothing happened at all :(

And when i switched my app to fullscreen, it would get stuck in some infinite loop!

Still not able to get it working :(
Right now, our game scenes look dull, and i though i could pull it off by using some sort of gamma increase, or brightness enhancement at realtime.

Is there any other way to do it? Perhaps tweaks like brightness and contrast settings etc. at runtime?


Hmmm....dont tell me i would have to end up tweaking up every single texture!! Or maybe...push a dialog box at startup saying "Please pump up your monitor's brightness knob!!" :)

Best,
San
If there is one way to do it, and only one way, it WILL fail.
Quote:Do you have any idea how to use SetGammaRamp anyway? Have you got the damn thing working at all!!
The DXSDK is your best source of technical details. I personally haven't needed to use such things since DX7, so can't provide any examples. I base my knowledge on stuff I've read since then and my own experience going from v7->v8.

Quote:Nothing happens.....i tried setting the RGB table to both extremes...nothing happened at all
If your hardware doesn't support it then no degree of trickery with the function calls will get you what you want. Have a look at the caps viewer or GetDeviceCaps() to do it at runtime.

Quote:Is there any other way to do it? Perhaps tweaks like brightness and contrast settings etc. at runtime?
These all fall into the domain of post-processing effects, so do a bit of reading on the subject. A conventional way of doing this would be to render your scene and then render a TL quad over the entire screen and use blending/shaders to alter the final values (a D3DBLEND_ONE operation on a white/grey quad will brighten your scene considerably).

However, if your scene is so dull that you _require_ this post-processing type operation you may find problems later on with rendering artifacts. Scaling/modifying an 8bit/channel image can lead to horrible colour interpolations. Hence, if possible, do it per-pixel in a shader or simply change the lighting/texturing used by your game.

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This is ridiculous if DX doesnt support gamma settings as this has been something which has been around since a very long time! SetGammaRamp does seem the way to go.

Thanks jolly......forgot to check the caps....will do that now and check again!

Per pixel TL quad maybe an option, but then, it increases my min hard specs - not so good

Thanks again!
San
If there is one way to do it, and only one way, it WILL fail.
Quote:This is ridiculous if DX doesnt support gamma settings
Minor technicality I suppose, but DirectX **does** support gamma ramps. it's the drivers/hardware that doesn't. Point the finger at ATI/Nvidia if anyone [grin]

Quote:Per pixel TL quad maybe an option, but then, it increases my min hard specs
I wouldn't worry about it myself. If you use a shader to manipulate the image then yes, you've got a hefty specification jump. However, using the D3DRS_SRCBLEND and D3DRS_DESTBLEND operations with a full-screen TL quad shouldn't cause you too much damage.

Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Hey Jolly!!

Got it working finally !! :)
Here's the function......in case you are interested :)

Thanks again,
San



// Gamma factor can be starting with 0.0 and up in steps of 0.1 to get your setting....
// do it right before begin scene call...should be fine...

void SetGamma(float GammaFactor )
{
D3DCAPS9 d3dCaps;
D3DGAMMARAMP NewRamp;
DWORD NewValue;
DWORD ui;
DWORD i;


//create linear gamma ramp
for( int i = 0;i < 255;i++ )
{
NewValue = i * GammaFactor * 255; ui = 0;
if(NewValue > 32767) { NewValue = NewValue - 32767; ui = 1;}
if(NewValue > 32767) { NewValue = 32767; }

//manipulate bits to handle unsigned integers
NewRamp.red = NewValue | (0x8000 * ui);
NewRamp.green = NewValue | (0x8000 * ui);
NewRamp.blue = NewValue | (0x8000 * ui);
}

//send gamma ramp to device
m_pd3dDevice->SetGammaRamp(0, D3DSGR_NO_CALIBRATION, &NewRamp);
}
If there is one way to do it, and only one way, it WILL fail.

This topic is closed to new replies.

Advertisement