# Why shouldn't Bump, Normal and Displacement maps be gamma corrected?

So I'm trying to wrap my head around this from a fairly technical point of view.

When you add a Bump or Normal or Displacement map in your shader they should not be gamma corrected. But diffuse textures should be. But why?

When you save a file in 8bit (or 16bit Integer) with a format like JPEG, PNG or TIFF they get the gamma of 0.4545 (1/2.2) burnt in. So a camera captures the light from the real world (that is linear) and when saving the photo as a JPEG a gamma value of 1/2.2 is added, as a way to compress the information into 8bit, and then when you view the image on a monitor that adds a gamma of 2.2 making the luminance linear again.

So when using a diffuse textures (like a photo) you need to a "remove" that 1/2.2 gamma to make it linear (called linearizing) so now the texture looks darker but these values are correct from a mathematical standpoint so the renderer will make the correct calculations. Side note: the software used a display gamma of 2.2 to make sure the textures looks correct it's just for the internal calculation that they are linearized. But when I create a Bump map in Photoshop and save that as a JPG or PNG then that 1/2.2 gamma is burnt into that image as well, so why doesn't this Bump map need to be linearized as well?

If I load a Bump map in 3ds Max with a input gamma of 2.2 just like a would do with a Diffuse texture, the diffuse looks right but the bump looks wrong, so I have to set the input gamma to 1.0 for the bump in order to make it look right, but as I said: why, both image files have the 1/2.2 gamma burnt in, right?

The fact that a photo is stored in gamma space doesn't have to do with PNG or JPEG, it has to do with the fact that it's a photo.

The camera detects a 50% intensity but is going to save it as a 187 instead of 127, because that is more efficient to keep the color information that matters to the human eye when you have only 256 different possible values. And so does Photoshop if you tell it so.

For normals or displacement maps, you don't have this need so there is no reason to use gamma space for them (using gamma for them would actually be a mistake, since it would affect how precision is distributed). Thus when you decode a normal texture or a displacement texture, you don't need to apply gamma.

If the normal map is encoded in a different space though, as can be the case for a G-Buffer for example, then you have to apply the corresponding correction.

• How do you tell Photoshop to save an image with the gamma baked in as you said above: "And so does Photoshop if you tell it so." – Kristoffer Helander Aug 10 '16 at 21:05
• This doesn't explain the "why" at all. It just reiterates the "what". – user1118321 Aug 15 '16 at 3:05
• @user1118321: I believe it does. I added emphasis in an attempt to make it clearer. – Julien Guertault Aug 15 '16 at 7:42
• Well, true but it still does not really explain why. I admit I have the same problem i just mention the lack of benefit or harm done by such compression. There is no need but the why is that the data of images is peculiar due to human senses whereas our spatial reasoning is more linear in nature (as far as the 3D app is concerned) – joojaa Aug 15 '16 at 7:58

JPG, PNG or any other 8 bit image formats do not intrinsically have 1/2.2 gamma associated with it. They just store values from 0-255. How that data is interpreted depends on the software that reads and writes those files. The interesting fact is that most image editing software uses gamma color space by default. All the brushes, effects, filters and even the color picker all operate in gamma space. Just look at the shades of gray on the color picker in Photoshop. They do not follow a linear distribution.

The consequence is that Photoshop does no conversions between gamma and linear color space when opening or saving an image (by default), only when displaying it. That means that you can just as easily use it to create or edit linear data such as a heightmap as you can edit photos. The bump map does not look correctly when loaded with gamma correction, because it wasn't saved with it.

• Here is a YouTube video also explaining that the stored value in an image is the 1/2.2 (but he simplifies it and just say that it's the square root, there is a disclaimer of that in text.) Computer Color is Broken - MinutePhysics link – Kristoffer Helander Aug 10 '16 at 15:22
• @KristofferHelander Yes, but he says it's only the camera that stores the values as square roots and only the display that squares it back. Image editing software like Photoshop then just open and save the image with no conversions, which results in artifacts shown in the video when you try to blend colors. – Quinchilion Aug 10 '16 at 15:33
• Correct me if I'm wrong on this. When I draw a gradient ramp in Photoshop that looks linear to me on the screen the values in that ramp actually are linear. But Photoshop adds a viewing gamma of 1/2.2 since the monitor adds a gamma of 2.2, thus the images pixel values are linear and they also look linear. But this 1/2.2 gamma is only a viewing gamma that Photoshop use for displaying the image, it is not baked into to image, and therefore no gamma correction to the image need to be done in the 3D software, (use gamma 1.0) since the values already are linear? – Kristoffer Helander Aug 11 '16 at 13:31
• @KristofferHelander goo.gl/yqkeUP The bottom gradient represents physical brightness. If Photoshop applied a gamma of 1/2.2 for either drawing the gradient or displaying the image, you would see the bottom gradient. Instead, you see the top one, which coincidentally appears to be linear, but isn't. It also wouldn't work for viewing photos. The camera applied 1/2.2 when saving the photo, then Photoshop would apply another 1/2.2, but the display only adds gamma of 2.2 once. That wouldn't look right. – Quinchilion Aug 11 '16 at 13:58
• If I fill a document in Photoshop half side red (255,0,0) and the other half with green (0,255,0) and then use a Gaussian blur on that, the resulting gradient becomes brownish rather then yellow in the middle as shown in that video I posted. Why is that? If the pixels in the image are linear then why does the math get screwed up? I don't understand how a displacement map painted in Photoshop is linear and good to go for rendering but at the same time the blurring of pixels gets screwed up with the wrong gamma and colors become to dark and brownish? – Kristoffer Helander Aug 11 '16 at 14:19

### Introduction

It depends on how you create the map! Consider the following and let it sink in for a while before you go forward:

1. The image is displayed with a gamma correction for the benefit of your eyes
2. The data is still just data. The gamma correction is for the display part not the data part.

Now a bump map is pretty hard to draw with a paint application. Because its hard to see even if you were correctly linear. So you end up using such things as looking at values. Now here is the catch:

• If you decide that 128 is halfway in your intensity then that is reality. Since that is what your encoding into the data stream. The data is what you interpret it to be since its not meant for human eyes and the monitor. Who cares what the monitor shows the values as its all on how you interpret the data editing it in.

### Making the bump/displacement map

Ok, so now I have described that the data is up to interpretation. But why would you interpret the data as linear? Because then you can design your side profile better. See what you can do is think of 100% opacity of your brush as the target height you want to carve or layer to. You can then use the curves tool to design the shape of your stamps brush (since you think the data is linear).

Image 1: A suction cup stamp.

Now if you do something like this then your image is linear despite what everybody tells you. You have decided to discard the image rules that says otherwise. And that is why the image is linear, the author chooses for it to be linear so its easier to work with.

Image 2: Same image displaced and interpreted linear (note I scaled the height a bit to fit to my default bb size), working as intended.

### Technically linear is better.

A synthetic map has no benefit of compressing certain values on the expense of others. Linear is inherently better because the spread of your bump is better that way. Which is why you'd be wasting resources encoding it in a gamma corrected manner.

Secondly a image does not need to specify what color space it is in. Its just that image editors will assume it is sRGB encoded. You have no reason to do same interpretation, no info means just: "Nobody bothered to write down what they were thinking". So maybe the point should be made you should tag it linear. But here is the rub... your computer does not come with a easily accessible linear profile.

### What about Photoshop and blur?

This is where it gets tricky. Photoshop tries to do quite much work to ensure that you do not need to know anything about this stuff. And this is where you shoot yourself in the foot. Se Photoshop is not meant for texture making, its meant to edit images not random data. So since blur on a image is different linear and nonlinear it wont work its geared to wrong data.

But you can do one of 2 things to fix this:

1. Disable the gamma correction of blur
2. set your working space to a linear profile

### Conclusion

The reason you have a hard time with this is

1. You do not know what other people think, you simply do not know if they should be gamma corrected or not.
2. that your using a application that treats images as images

Point one is especially confusing. I just know that ALL my bump and displacement maps are in fact linear. But I can not know what your maps are. Odds are they are linear because its nearly universally understood that the data is linear. Even people who do not know about gamma tend to do it linear for bump/displacement for some reason (because its easy and that's what you think images are until somebody tells you otherwise).

• Thank you for your input - wow! :) I'll have a look at this when I get more spare time. I'll get back to you, thanks! – Kristoffer Helander Aug 29 '16 at 14:31
• Even people who do not know about gamma tend to do it linear for bump/displacement for some reason Likely because those maps are generated. – Tara Jul 5 '19 at 8:44

Actually, if your bump or displacement map is saved with that 0.45 gamma correction, it's wrong. These maps contain geometrical information rather than colour, and as such, should be simply encoded linearly.

For a related issue and a fix for Adobe Photoshop, see this slide deck: https://docs.google.com/presentation/d/1vS5nAAnXbZ8Pt6-dXxy-xEXDkjfjXTmNnthNGccorl0/edit#slide=id.g14b3e28660_0_8

• This is especially true for a normal map were you expect vector lengths to be 1. – PaulHK Aug 15 '16 at 9:01