Convert Normal Maps between OpenGL and DirectX

Say you downloaded a shiny new model for use in your Godot engine but something isn’t quite right. After hours of quietly saying things in your head that you wouldn’t say in front of your mother you realize the normal map isn’t in the correct format. Godot (and most things not Microsoft) uses OpenGL format and you’re looking at a DirectX normal map.

How can you tell? If you’re looking at what’s supposed to be a bump and it looks like a hole, it’s DirectX. If the normal map actually looks correct, it’s OpenGL.

Here’s a fancy image that demonstrates the issue:

https://blender.stackexchange.com/questions/100017/directx-vs-opengl-normal-maps

Fortunately, it’s easy to convert from one format to the other. The difference between the two is that the Y value (in the green channel) is inverted. You can use a tool like The Gimp to do this or a command line tool like ImageMagick.

$ magick.exe input.png -channel green -negate +channel output.png

The same command will convert from one to the other. If you start with a DirectX image you will get an OpenGL image and vice-versa.

If you don’t want to use a command line tool and are more comfortable with The Gimp, open the image and do the following:

  1. Open the image and switch to the channels tab/dialog.
    • If it is not visible, it can be opened from the Windows | Dockable Dialogs menu.
  2. Make sure only the green channel is selected (dark highlight).
  3. Select the Colors menu and select Invert.

Once complete the green channel will be inverted resulting in something like this:

Export this image as a png and you are done. Enjoy!

Related Posts