XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Gamma correction/sRGB + CHOOSECOLOR

Last post 03-31-2008 5:18 PM by jogshy. 3 replies.
  • 03-31-2008 2:27 PM

    Gamma correction/sRGB + CHOOSECOLOR

    It happens a very strange thing in my engine editor. I use a sRGB framebuffer and sRGB textures all the time. I'm aware about gamma correction, linear-space shading, etc...

    In the editor, I put an overlay(a 2D rectangle projected on the screen... nothing to do with the "video overlays"... are different things) with a white texture(255,255,255,sRGB_UNORM) multiplied by the light diffuse color to see the color that the light emits. When the user presses over the rectangle then I open a Win32 GDI ChooseColor dialog so the user can select the color he/she wants for the light... the problem is that when I choose an intense yellow, the overlay is painted with a very pale one.

    I'm performing automatic sRGB conversion... using a sRGB framebuffer and sRGB textures... all the shading is done in linear-space... I have also my monitor settings with a sRGB ICC profile... so I cannot understand why the overlay is not painted with the exact color the user selected from the common dialog... This is my shader for the 2D screen overlay rendering:

    return g_ovrTex.Sample(OvrTexSampler,psi.uv) * psi.col;



    where psi.col is a float4 color with elements in range [0.0f,1.0f]... set to the value that the artist chose from the color dialog. For example, if chose a ( 255,255,0) yellow color this will be ( 1.0f,1.0f,0.0f).
    The g_ovrTex is a texture set to (255,255,255,255) and with format DXGI_FORMAT_R8G8B8A8_UNORM_SRGB

    so I really cannot understand why the color that paints D3D10 is not exactly the color the artist chose.... Perhaps I have the TFT bad calibrated...

    A image to see what I mean:




    The user chose a light ambient color of (35,35,35).. which is very low... but when I paint the 2D overlay with that color in the "light ambient color" it's displayed like (100,100,100)... And nope, it's not a bug because if I turn off gamma correction it shows it correctly:



    any idea? thx

  • 03-31-2008 4:25 PM In reply to

    Re: Gamma correction/sRGB + CHOOSECOLOR

    Can you show us the code how you convert the color value from the dialog and set it to the shader/effect?

  • 03-31-2008 4:27 PM In reply to

    Re: Gamma correction/sRGB + CHOOSECOLOR

    Answer
    It sounds like you are getting colors convert to srgb twice.

    The colors in the picker are probably srgb colors. Your pixel shader should be completely linear, so you'd have to convert the srgb color to linear when setting the light color in the constant buffer. Did you do this?

    I'd expect this to affect your greys like in the example, but not the yellow, since that doesn't change between srgb and linear color space.

    Rory
  • 03-31-2008 5:18 PM In reply to

    Re: Gamma correction/sRGB + CHOOSECOLOR

    Rory:

    The colors in the picker are probably srgb colors. Your pixel shader should be completely linear, so you'd have to convert the srgb color to linear when setting the light color in the constant buffer. Did you do this?

    Nope, I was not making that.
    You're right... If the ChooseColor dialog retrieves the color RGB in sRGB space then I should convert the returned RGB value into linear-space before  sending it to the shader's constants.

    I changed it and now works! Thanks, Rory!
Page 1 of 1 (4 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG