# NormalMap3

Keywords: normal maps

## Summary

This demo includes several objects that utilize tangent space normal maps that are defined relative to the surface rather than the object’s local coordinate system. In this example, the same normal map is applied to the sides of a wooden crate, which requires the map to be rotated into the coordinate system relative to each side rather than be interpreted in the coordinate system of the entire object.

## Related Materials

The following demos, manuals and tutorials can provide additional information about the topics at the focus of this demo:

- Related Demos

  - NormalMap1

  - NormalMap2

- Related Manuals

  - Maps Manual

  - GLIST Manual

- Related Tutorials

  - N/A

## Important Files

This section highlights key files important to the simulation.

### The Geometry Setup

The `geometry/demo.glist` file assembles the floor, walls, crate and barrel objects into a scene. For the tangent space normal map option to work correctly, the tangent vector for the crate geometry should be explicitly compiled into the scene data model used by DIRSIG. This tangent data is what alows the normal map to be correctly and unambigously rotated into the plane of each side of the crate object. Requesting the tangent data is accomplished via the explicit tangent data option in the GLIST file:

The GLIST configuration for the crate object.

      <object>
        <basegeometry>
          <obj generatetangents="true">
            <filename>Crate.obj</filename>
          </obj>
        </basegeometry>
        <staticinstance>
          <translation>
            <point><x>-1.562</x><y>-1.648</y><z>0.616</z></point>
          </translation>
          <rotation units="radians" rotationorder="xyz">
            <cartesiantriple><x>0.0</x><y>0.0</y><z>0.0</z></cartesiantriple>
          </rotation>
          <scale>
            <cartesiantriple><x>0.01</x><y>0.01</y><z>0.01</z></cartesiantriple>
          </scale>
        </staticinstance>
      </object>

### The Map Setup

The `Crate` material in the `demo.mat` file includes the normal map definition. The `Crate.obj` geometry was created with each side of the crate using it’s own UV space, meaning that the same normal map can be applied to each side of the crate. The normal map RGB image is shown below.

Figure 1. The RGB normal map image for the crate sides.

The `Crate` material in the `demo.mat` file includes the normal map configuration using the UV projection method with the `SPACE = TANGENT` option:

    MATERIAL_ENTRY {
        ID           = Crate
        NAME         = Crate (RGB, w/ Normal Map)
        DOUBLE_SIDED = TRUE
        RAD_SOLVER_NAME = Classic
        RAD_SOLVER {
            ENABLE_SAMPLED_DIFFUSE = FALSE
        }

        NORMAL_MAP {
            NAME = WoodCrate_normal.png
            UV_PROJECTOR {
                SPACE = TANGENT
                ORIGIN = IMAGE
                FLIPX = FALSE
                FLIPY = FALSE
                EXTENDX = MIRROR
                EXTENDY = MIRROR
            }
            IMAGE_FILENAME = WoodCrate_normal.png
            OPTIONS {
                SCALE = 4.0
            }
        }

        SURFACE_PROPERTIES {
            REFLECTANCE_PROP_NAME = RgbImage
            REFLECTANCE_PROP {
                IMAGE_FILENAME = WoodCrate_basecolor.png
                SCALE = 0.003921569
                UV_PROJECTOR {
                    ORIGIN = IMAGE
                    FLIPX = FALSE
                    FLIPY = TRUE
                    EXTENDX = MIRROR
                    EXTENDY = MIRROR
                }
            }
        }
    }
    MATERIAL_ENTRY {

Without the `TANGENT` space option, the normal map will be interpreted in the object coordinate system. As a result, the RGB values in the normal map applied to the sides would produce normals that are generally in the +Z direction, which is in the plane of the crate sides rather than generally normal too it. The `TANGENT` option rotates the normal map into the tangent plane of the sides, so that the resulting normals are generally normal to the sides of the crate.

## Simulations and Results

This simulation can be run in the GUI or via the command line:

    $ dirsig5 demo.jsim

Load the resulting `demo.img` radiance file in the DIRSIG image viewer and display the RGB bands using the 2%$ and gamma = 2 range and scaling options.

Figure 2. The RGB image simulation.

The RGB texture image can mask the effects of the normal map. To verify the impact of the normal map, the truth imagery can be used to visualize the surface orientation. The images below show the normal and view angle cosine truth, which confirm the manipulations of the normal across the otherwise flat sides of the crate.

Figure 3. The normal truth displayed as an RGB image.
Figure 4. The view angle cosine truth.

If the `SPACE` option in the map projector is set to `OBJECT`, the normal map will not be rotated into the coordinate system of each face, and the derived normals will be constant across a complex object. In this case, all the surfaces on the crate will have their normals pointing in the same direction:

Figure 5. The normal truth when using the `OBJECT` space projection.