# Artifacts when gamma correcting

Doing post-process gamma correction is showing texture artifacts, here is a small example on a skybox:

The first image is gamma correcting on the skybox shader and seems correct, the lower is doing it in post-process and has terrible artifacts near the edges of the clouds, however both versions do it the same usual way:

Color.rgb = pow(Color.rgb, vec3(1.0/2.2));
Color.a = 1.0;


So that makes me believe there's something wrong with the way I'm creating and using frame buffers, here's sort of how I'm doing it:

// Generate FirstFBO, specify this as the color attachment
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, FramebufferSize.x, FramebufferSize.y, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);

// ...

while (true) {
glBindFramebuffer(GL_FRAMEBUFFER, FirstFBO.ID);
DrawStuff();

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, FirstFBO.ColorTexture);
}


Short answer, set the precision of the image to a higher value.

When looking at a gamma correction curve, you can see that the lower values get changed much more, this means that the difference between lower values will get greater and that causes this effect. You have a limited amount of values for a color channel and this means that when it rounds the number down to the 8 bit value, it makes some neighboring pixels the same color. You don't notice this in a normal image, but after gamma correcting it this effect comes out, because you lose that bit of change in the color that later on can become a much bigger difference in color.

To fix this, you just give the gamma correction more precision to also get that small color change it would've else rounded away.

In the actual shader, it has floating point color information and that means that it has more precision and thus not the weird artifact.

So when making the frame buffer, you can use for example GL_RGBA16F or GL_RGBA32F. This would increase the precision and remove the artifact.

I hope that this can help you fix the problem, good luck and have a great day!

• I was suspicious of precision problems, only I was looking at compression until I got overwhelmed. Thank you so much, this helped me fix it.
– V.M.
Feb 12 '17 at 20:46