KatsBits Community

Normal map Rotation issues

kat · 1 · 7058

0 Members and 1 Guest are viewing this topic.

Offline kat

  • Administrator
  • Hero Member
  • *
    • Posts: 2692
    • KatsBits
The advent of nextGen content and the use of bumpmaps brings with it it's own little oddities, one of which is what happens when you rotate textures. There's a peculiar problem that happens because of the way Normal maps work in the Doom 3 engine that means if a texture is rotated around an axis the normal map wasn't renderbumped from originally it'll start to show problems with inverted or incorrect shadow casting.

Why is this happening?
The reason for this is surprisingly straightforward.

When a texture is rendered the normals from the highpoly mesh have a specific colour index depending on the direction in which they point. This gives Quake 4 a definitive statement that, for example, the normals associated with the colour 'blue' are orientated (pointing) in a 'westerly' direction.

For instance, if the default layout of the four cardinal points of an object are like this;
  • North = Purple
  • East = Blue
  • South = Green
  • West = Pink
Quote
Design note: if you look at the image opposite above you'll notice that 'east' and 'west' are the 'opposite' way around; 'West' is in fact 'Blue' and 'East' is 'Pink'. This isn't wrong, it in fact tells the Quake 4 engine that the normals are pointing outwards which in effect raises the surface upwards creating the rivet bump. If the normal colours were the 'correct' way around (as the text list above indicates) it would tell Quake 4 to render the bump inwards as a depression or 'bent' in the surface.

Relative to the textures default orientation, if you then rotate the texture 90° (clockwise) you get the following on the cardinal points;
  • North = Pink
  • East = Purple
  • South = Blue
  • West = Green
Quote
Design note: keep in mind the note above; we're still rotating the Normal map with colour orientating telling Quake 4 to render a raised rivet.

What Quake 4 now does with this is look at the image as if one of the RGB channels is inverted. Basically this means that if a light were placed next to this texture in-game the shadow would render on the wrong side; for example, in the case of left/right (east/west) now being incorrect the shadow renders on the same side as the light rather than the opposite.

How do I correct this?
In game you can't. It leaves us with two choices
  • If it's a custom texture you or someone else did, if you have access to the original highres model or image template you can simply re-render the texture with the correct orientation.
  • Open the original offending texture into a photo editing app and invert the RGB channels until you get the correct colour orientation in game. What that will be will depend on the texture and the orientation error you're getting in game, however, it's usually either the 'green' or 'red' channels that get flipped or can be flipped to correct the problem.
Additional Reading
The following links cover similar topics on making and using Normal maps;