Jump to content

  • Log In with Google      Sign In   
  • Create Account

Gamma Correction Issues


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 DementedCarrot   Members   -  Reputation: 632

Like
0Likes
Like

Posted 15 January 2014 - 04:59 PM

I'm trying to get gamma correction to work in my DX11 tile deferred renderer, but something in my pipeline must be doing something that I don't realize.

 

When I manually do gamma correction with pow(color, 2.2) and pow(finalColor, 1.0/2.2) it looks great! When I use the sRGB formats it appears way too bright.

 

My pipeline is as follows.

 

1. Create diffuse G-Buffer by reading from sRGB textures and writing to a sRGB render target. This is a pass-through.

2. Perform lighting in compute shader. Read from the sRGB diffuse G-buffer and compute lighting. Write the result to a DXGI_FORMAT_R16G16B16A16_FLOAT. I can't use an sRGB write format here because I have to write the result into a UAV.

3. Run post-processing. Read from the DXGI_FORMAT_R16G16B16A16_FLOAT and write down to the sRGB render target back buffer to be presented to the screen. I've disabled post-processing steps for the moment so this is just a pass-through.

4. Present.

 

What am I missing? >_>

 

Also, thanks!


Edited by DementedCarrot, 15 January 2014 - 05:02 PM.


Sponsor:

#2 Hodgman   Moderators   -  Reputation: 32898

Like
1Likes
Like

Posted 15 January 2014 - 05:11 PM

How do you read from the G-Buffer in step #2?

I can't use an sRGB write format here because I have to write the result into a UAV.

You also can't use sRGB here because your values are HDR/outside of the 0.0 - 1.0 range. Lighting values should be in linear RGB.

When I manually do gamma correction with pow(color, 2.2) and pow(finalColor, 1.0/2.2) it looks great!

 Does this mean that your pipeline looks like one of these?
1.a Create diffuse G-Buffer by reading from textures and writing to a render target. This is a pass-through.
1.b Create diffuse G-Buffer by reading from sRGB textures and writing to a gamma render target with return rgb1/2.2.
1.c Create diffuse G-Buffer by reading from textures, converting to linear with rgb2.2 and writing to a gamma render target with return rgb1/2.2. These two operations cancel out, so I may as well be using 1.a if optimization was a concern.
2. Perform lighting in compute shader. Read from the gamma diffuse G-buffer, convert to linear with rgb2.2 and compute lighting. Write the result to a DXGI_FORMAT_R16G16B16A16_FLOAT.
3. Run post-processing. Read from the DXGI_FORMAT_R16G16B16A16_FLOAT and write down to the gamma render target back buffer (using return rgb1/2.2) to be presented to the screen. I've disabled post-processing steps for the moment so this is just a gamma correction pass.
4. Present.

Edited by Hodgman, 15 January 2014 - 05:13 PM.


#3 DementedCarrot   Members   -  Reputation: 632

Like
0Likes
Like

Posted 15 January 2014 - 05:17 PM

I read from a sRGB texture and write to the sRGB diffuse G-Buffer render target. I assume DirectX uses the same gamma on the reads/writes. That is 1.b I believe.

 

I guess I'll rephrase!

 

- While creating G-buffers.

1. Read from sRGB texture.

2. Write to the sRGB diffuse G-buffer, which is the back buffer at this point.

 

- In lighting compute shader.

3. Read from sRGB diffuse G-buffer

5. Do lighting.

4. Write unmodified value to the DXGI_FORMAT_R16G16B16A16_FLOAT

 

- In gamma correction pass

5. Read from DXGI_FORMAT_R16G16B16A16_FLOAT

6. Write the value to the sRGB back buffer.

 

7. Present

 

Edit:

I'm reading from the textures in the compute shader with direct brackets, like diffuseTexture[texCoord]. I changed it to use a point texture sampler with SampleLevel() but it didn't change anything.


Edited by DementedCarrot, 15 January 2014 - 08:13 PM.


#4 DementedCarrot   Members   -  Reputation: 632

Like
0Likes
Like

Posted 15 January 2014 - 08:45 PM

I'm starting to think that I've gotten gamma correction working, and that it is really just brighter than I expected it to be without modifying the light values.

 

If a lit render that isn't gamma corrected is compared to the same scene when it is gamma corrected, will it be brighter?


Edited by DementedCarrot, 15 January 2014 - 08:46 PM.


#5 cgrant   Members   -  Reputation: 810

Like
0Likes
Like

Posted 15 January 2014 - 09:18 PM

If in your last pass before presenting you are writing linear values to the sRGB framebuffer, then everything should be correct. When done correctly, gamma correction usually throw people off because even though correct, the scene is usually brighter than a corresponding no gamma corrected scene.



#6 Styves   Members   -  Reputation: 1093

Like
0Likes
Like

Posted 16 January 2014 - 01:08 PM

You haven't been too clear on this, so I'd like to ask: are you converting your sRGB results to linear before lighting?

 

It should be like this:

 

  1. Read textures from sRGB. Output to non-sRGB G-Buffer (or, decode from sRGB, and output to sRGB G-Buffer, but that's wasting cycles).
  2. Read G-Buffer during light stage. Convert G-Buffer values to non-sRGB values. Perform lighting in linear space. Output unmodified to ARGB16.
  3. Read lighting values, write to sRGB back-buffer.

 

 

I'm actually curious what that last stage is supposed to be doing. Is it tone-mapping or something?


Edited by Styves, 16 January 2014 - 01:08 PM.


#7 DementedCarrot   Members   -  Reputation: 632

Like
0Likes
Like

Posted 16 January 2014 - 09:14 PM

Yeah, the last stage is supposed to be for tone-mapping and other post processing stuff.

 

I'm hopeful that tone mapping alone will fix my brightness problem.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS