Home | About Us | Media | Support | News | Contact Us
Copyright ACE Studios

In this tutorial we will cover the basis of using the ogre material and shader system to create a Normal Mapping material with per-pixel specular light support.

The normal mapping technique uses a texture to replace the geometry normals to add details to the shading (displayed image) without using more polygons.

Note: This tutorial requires hardware gpu shader support

1. Create a torus on the viewport
2. Activate the "Generate Mapping Coords." option to create texture coordinates for the mesh.

With this setting, texture images can be correctly rendered on the object

3. Open the Object Properties panel and activate the "Generate Tangent Vectors" option for the torus mesh.

This generated vectors are used to transform the light to tangent space (the space where normal map is defined) in the gpu shader

4. Create an omni light to illuminate the scene

5. Activate the Ogre Viewport
6. Assign an Standard default material to the object, then evaluate this material to an Ogre Material, see Evaluating to Ogre Materials section for details
7. Click on the auto created Technique, then on the auto created Pass. This will be the base ambient pass so change its name to "Base_Pass". Spaces between words are handled correctly but as a good practice we use the ' _ ' character instead
8. Locate the "Vertex Shader(Program)" rollup section of the pass material, and select "Ogre/BasicVertexPrograms/AmbientOneTexture" from the list of available vertex shader programs
9. Click on "Activate" option to enable this shader use in the material
The object should disappear in the display as the shader properties are not configured yet, the render system is using the assigned vertex shader to render the object this material is assigned to, but as the shader program is not configured with valid parameters for its properties, it wont display the object

10. Now we need to configure the vertex shader properties, click on the "Edit" button

The shader properties editor will be displayed, here we can set the proper parameters for the shader program

this shader program uses two parameters, the worldViewProjection matrix used to convert the object vertex positions to screen space positions, and the ambient color. These parameters uses the engine state automatic constants.

11. Click on the "auto constant" checkbox on the first parameter, the icon on the left changes to a green icon with the A letter to reflect the new parameter type

12. Set the proper type on the auto constant parameter list for this parameter, the "WORLDVIEWPROJ_MATRIX"
13. And the same procedure for the ambient parameter, but in this case we use AMBIENT_LIGHT_COLOUR
The first pass is configured, close the shader editor dialog

14. Now we will create the Lighting Pass, return to the Parent Technique and create a new Pass

Rename this pass to "Normal_Map_pass"

15. Set the scene blend of this pass to 
        Src Blend: "one"
        Dst Blend: "one"

This pass will be blended, to use the ambient light from the base pass
16. Set "Once per Light" option so multiple lights can be used

The effect will be rendered for each of the nearest lights in the scene, up to 8 lights (or the selected value)

17. In the vertex shader section, select the "Examples/BumpMapVPSpecular" program form the list, and activate it
18. Click on "Edit" to display the shader properties editor
This vertex shader program has 3 properties, lightPosition vector, eyePosition vector, and worldViewProj matrix

This properties needs the engine "auto constants"

19. Change lightPosition to an "auto constant parameter" and set its value to "LIGHT_POSITION_OBJECT_SPACE". The extra value for this parameter represents the index of the light to be used in the shader, set it to "0" (the index of the first light) as the pass is configured to iterate "once per light"

20. Change the other parameters to auto parameters too, for the eyePosition set its value to "CAMERA_POSITION_OBJECT_SPACE" and the worldViewProj to "WORLDVIEWPROJ_MATRIX"

21. In the Pixel Shader(Program) rollup section, select the "Examples/BumpMapFPSpecular" program from the list of available pixel shaders, and click on activate

22. Click on "Edit" to display the shader properties editor.

This shader has 5 parameters, 2 configurable and 3 read-only parameters.

Change the parameters to "auto constant parameters" and set the values to "LIGHT_DIFFUSE_COLOUR" and "LIGHT_SPECULAR_COLOUR" as shown in the image

The read-only parameters are of type "Sampler2D" and "SamplerCube", that means they are texture units needed by the shader program

23. The first of the "sampler" parameters is called normalMap, so the first texture unit needed is the normal map image

Add an "ogreTextureUnit" by clicking on the first texture button of the Texture Units section of the pass

24. In the created TextureUnit click on the "Bitmap" button, browse and select the "rockwall_NH.tga" image
25. In the Color Blend Mode list select "source 1"

This blend mode is equal to "replace" (the color of the texture will replace previously drawed pixels)

26. The next of the "sampler" parameters is called normalCubeMap, so the next texture unit needed is the normalisation cube map image

Add a new "ogreTextureUnit" by clicking on the next texture button of the Texture Units section of the pass

27. In this TextureUnit, set the Type to "cubic" (the type of the image is important and should be set first before loading the image file)

Set the Map Channel to "1" to use the tangent vectors created and set Address Mode to "clamp"

28. Select the nm.dds image file for the bitmap section
(You can download the normalization cube image
here or here)
29. The next of the "sampler" parameters is similar to the previous normalCubeMap, so we will copy the texture unit

In the pass material, drag the previous created texture unit in the next unit button, select "copy" in the method dialog and click ok

30. Select the new copied TextureUnit and set the Map Channel to "2"
31. The display now should be similar to the next image, where you can see how the normal mapping shader adds high detail resolution to the object

We need the decal pass and we are ready

32. Create a new pass on the technique material and rename it to "Decal_Pass"

33. Set Blend mode to modulate,
          Src Blend: "dest color"
          Dst Blend: "zero"

and unselect Lighting
34. Add a TextureUnit that will contain the decal image (the texture)
and select the "rockwall.tga' image for the bitmap
35. For the vertex shader, select the "Ogre/BasicVertexPrograms/AmbientOneTexture" from the list of available vertex shader programs and activate it

36. Edit shader parameters similar to the steps 10 to 12, for the ambient property we will select a white color (this pass will add texture color only)

The result will be an object with high amount of details without the need for extra geometry, and a high-end per-pixel lighting model

Artist center
      tutorial 1
tutorial 2
tutorial 3
tutorial 4
tutorial 5
Example Scenes
The complete scene can be downloaded in the Scenes section