How to Apply Shaders

Here's a step by step guide how to apply normalmapping or other shaders to level block surfaces. If you want to use the standard shaders that come with Gamestudio, version 7.50 Commercial or above is required. 7.5  C 

1. Add a normal map

If a texture name ends with "_n" , the texture is used as a normal map for a base texture with the same name. So if you want to add a normalmapping shader for a surface texture named "stones2", use a normal map texture that is named "stones2_n" . Below you can see a typical tiled texture and its normal map:

rock rock_n

In the Gamestudio online store you can purchase a high resolution replacement of the standard textures, including a WAD file that contains normal maps for all surface textures. For adding the normal maps to the level, open the [Presets] Window, right click on [Textures], select [Add WAD] and then open the hires_nm.wad that comes with the high resolution pack. This adds all normal maps from the WAD to the level.

Alternatively if you're using textures from an image folder, just copy a normal map image ending with "_n" into that folder (such as "stones2_n.bmp").  !!  Make sure that the texture name plus the "_n" and the extension does not exceed 15 characters, which is the limit for texture names in the WMB file!

2. Add a material script

A normalmap alone is not sufficient - you'll also need to apply a material with a normalmapping shader to the level surface on which you want the effect to appear. Materials are contained in a script. The predefined shaders that come with Gamestudio are contained in the mtlFX.c script. If your level already has a .c script (.wdl won't do), just make sure that this script contains a line #include <mtlFX.c> . If your level has no script yet, create one: select File/Map Properties, click on the [New] icon next to the Script field, and select A7_lite_C_project. This will automatically generate a script and include the mtlFX.c shader collection.

3. Apply the material

Once you've added the script, mark the block or group you want to apply the shader to, and click the [Choose] icon next to the Material field on the Properties Panel. You'll now get a collection of materials to choose from. For normalmapping, select mtl_bump, mtl_specBump, or mtl_specBump2.

4. Place a dynamic light

The third element you need for normal mapping is one or more lights. Select File/Map Properties and make sure that you've activated Sun light. Or place a light source next to the normal mapped surface, make sure that the surface is within the range of the light and the [Dynamic] flag of the light source is checked (A7.6 or above). Or place a dynamic light in the script, with a function like this:

function light_place(x,y,z,r,g,b,range)
{ 
  ENTITY* light = ent_create(NULL,vector(x,y,z),NULL);
  light.red = r;
  light.green = g;
  light.blue = b;
  light.lightrange = range;
}


function main()
{
  ...
  level_load(...);
  light_place(100,100,100,0,0,255,1000);
  ...
}

5. Be stunned by the result

Build the level (Meshes always activated!) , then click the [Run] icon next to the [Build] icon on the toolbar. Use the cursor keys or mouse to navigate to the block you've applied the shader to. If the shader effect can be adjusted with entity skills, as with skill41..skill44 for the predefined shaders, set the skills globally on the level_ent entity pointer after loading the level. If the result does not look this great, start over...

► latest version online