Sub topic 15
OpenGL vs DirectX Normal Map Conventions
This chapter assumes you can bake a tangent-space normal map in Cycles, as covered in the earlier chapters. You should also know that a normal map stores a direction in its red, green and blue channels. Here you will learn why two conventions exist, how to tell which one a map uses, and how to convert between them.
Why two conventions exist
A tangent-space normal map stores a surface direction as a color. The three channels map to three axes of a local frame at each point on the surface:
- Red stores the X axis, which points along the U direction (right across the texture).
- Green stores the Y axis, which points along the V direction (up or down across the texture).
- Blue stores the Z axis, which points away from the surface.
Red and blue agree between engines. Green does not. The two conventions differ in the direction of the green channel:
- OpenGL (also called Y+) treats green as pointing up. A bump lit from above is brighter on its top edge in the green channel.
- DirectX (also called Y-) treats green as pointing down. The green channel is the inverse of the OpenGL one.
Neither is more correct. Each convention follows the way its graphics API places the texture origin. OpenGL puts the origin at the bottom left, and DirectX puts it at the top left. Engines inherited their normal map conventions from these origins.
What Blender uses
Blender uses the OpenGL convention (Y+). The Cycles baker writes OpenGL maps, and the Normal Map node reads OpenGL maps. If you bake in Blender and view the result in Blender, you never have to think about this.
The problem appears when the map leaves Blender. Typical engine conventions are:
| Target | Convention | Green channel |
|---|---|---|
| Blender (Cycles, EEVEE) | OpenGL | Y+ |
| Unity | OpenGL | Y+ |
| Godot | OpenGL | Y+ |
| Unreal Engine | DirectX | Y- |
Check the documentation of your engine version before you rely on this table. Importers and project settings can change the expected convention. Some engines offer an option to flip the green channel when you import a texture.
Recognizing a wrong convention
If the green channel is flipped, the red and blue channels still look right. Only the vertical lighting is wrong. These symptoms point to a convention mismatch:
- Bumps look like dents, and dents look like bumps, but only when the light comes from above or below.
- Lighting from the left or right looks correct.
- Horizontal edges, such as the top and bottom of a panel, look inverted. Vertical edges look fine.
If you see inverted detail in every direction, the cause is different. Check for a flipped normal on the low-poly mesh or a wrong space setting, as described in the troubleshooting chapter.
You can also check the map itself. Look at a bake of a raised, rounded button in an image editor. With an OpenGL map, the top of the button is light green and the bottom is dark green. With a DirectX map it is the reverse.
Seeing the difference in a material
The Normal Map node in Blender has no convention switch, so Blender always interprets the image as OpenGL. If you receive a DirectX map, such as one downloaded from a texture library or exported for Unreal, you have to flip the green channel before the node reads it.
This script builds that fix. It separates the color channels, inverts green, and recombines them before the Normal Map node.
import bpy
mat = bpy.data.objects["Asset_low"].active_material
mat.use_nodes = True
nodes = mat.node_tree.nodes
links = mat.node_tree.links
tex = nodes.new('ShaderNodeTexImage')
tex.image = bpy.data.images["Asset_normal_dx"]
tex.image.colorspace_settings.name = 'Non-Color'
separate = nodes.new('ShaderNodeSeparateColor')
invert = nodes.new('ShaderNodeMath')
invert.operation = 'SUBTRACT'
invert.inputs[0].default_value = 1.0
combine = nodes.new('ShaderNodeCombineColor')
normal_map = nodes.new('ShaderNodeNormalMap')
normal_map.space = 'TANGENT'
bsdf = nodes.get("Principled BSDF")
links.new(tex.outputs['Color'], separate.inputs['Color'])
links.new(separate.outputs['Red'], combine.inputs['Red'])
links.new(separate.outputs['Green'], invert.inputs[1])
links.new(invert.outputs['Value'], combine.inputs['Green'])
links.new(separate.outputs['Blue'], combine.inputs['Blue'])
links.new(combine.outputs['Color'], normal_map.inputs['Color'])
links.new(normal_map.outputs['Normal'], bsdf.inputs['Normal'])The Math node computes 1.0 - green. The result is an OpenGL map, which the Normal Map node reads correctly. This script assumes an image named Asset_normal_dx is already loaded and that the material has a Principled BSDF node.
Exporting a DirectX map from Blender
The reverse case is more common for bakers. You bake in Blender, which gives an OpenGL map, and you need to deliver a DirectX map for Unreal. You have three choices.
- Flip the green channel in an image editor. Open the PNG in an editor such as Krita, GIMP or Photoshop. Invert only the green channel and save the result under a different name, for example
Asset_normal_dx.png. - Flip it in the target engine. Many engines let you tick an option on import, such as flipping the green channel. This keeps a single source file.
- Flip it in Blender with a compositor or node setup. Use the same Separate, Invert, Combine chain as above, then save the result with the Image Editor or a render.
Keep one master file in OpenGL, because that is what Blender produces. Derive the DirectX version from it. If you edit both by hand, the two files will drift apart.
Color space and file format
The flip does not change the color space rule from earlier chapters. Both versions of the map must be set to Non-Color when you load them in Blender, and the engine must treat them as linear data, not as sRGB color. If the engine applies a gamma curve to a normal map, the shading looks wrong in a way that resembles a convention error but affects all directions.
Use a lossless format such as PNG. A lossy format such as JPEG introduces blocky noise into normal data, and the noise appears as faint shading errors on the surface. For 8-bit maps, an inversion is exact: a green value of 200 becomes 55. No precision is lost.
How the convention interacts with the bake
The convention depends on the tangent frame, not only on the image. A tangent frame is built from the UV layout and the mesh normals. That has two consequences.
- If you mirror or flip UV islands, the tangent frame of that island flips as well. A mirrored island in an OpenGL map shows its green channel reversed relative to the rest, and the engine must compute tangents the same way Blender did.
- Blender and the engine must agree on the tangent basis. Blender uses MikkTSpace, a standard tangent-space algorithm. Most engines also use MikkTSpace, and this is why a Blender bake usually matches in Unity, Godot and Unreal apart from the green channel.
If a map still looks wrong after you fix the green channel, check that the engine computes tangents with MikkTSpace on import, not from its own method. Some engines have a setting for this on the model import.
A decision flow
Common mistakes
- Flipping the map twice. You invert green in an image editor, and then the engine also flips it on import. The result looks as wrong as the original.
- Testing with a head-on light only. A light that points straight at the surface hides the problem. Test with a light from above or from the side.
- Using a DirectX map from a library in Blender without a flip. Library files often state the convention in the file name, such as
_nor_glor_nor_dx. Use the name to choose the right file. - Naming files without the convention. A file called
Asset_normal.pnggives no hint. Add a suffix such as_glor_dxso that nobody has to guess later.
Exercise
You baked a normal map in Blender and exported it to Unreal Engine, which expects DirectX. In the engine, vertical edges look correct, but the top and bottom edges of a raised panel look inverted. What is the likely cause, and what is the minimal fix?
Show answer
The map is in the OpenGL convention (Y+) and the engine expects DirectX (Y-). Only the green channel differs, which explains why vertical edges (red channel) look right and horizontal edges (green channel) look inverted. The fix is to invert only the green channel, either in an image editor or with the engine's flip-green import option, and to use only one of these two fixes so the channel is not flipped twice.
Exercise
A teammate inverts all three channels of a normal map to convert it from OpenGL to DirectX. Why does this break the map, and what should they invert instead?
Show answer
Red and blue are the same in both conventions. Inverting them reverses the X direction and the Z direction, so lighting is wrong from every angle and the surface points inward. They should invert only the green channel, for example with a Separate Color node, a Math node set to Subtract from 1.0, and a Combine Color node.