Predefined Materials

There are  several engine-predefined materials that are automatically assigned to entities dependent on their type and flags, unless the entity has an own material. You can change the overall lighting of a level by adjusting the properties of those materials:

mat_flat for flat map surfaces
mat_shaded for shaded map surfaces
mat_terrain for terrain entities
mat_model for model entities
mat_sprite for sprite entities
mat_particle for particles (not yet used)
mat_sky for dome or scene sprites
mat_metal for any entity with METAL flag.
mat_unlit for any entity with UNLIT flag.
mat_shadow for defining stencil shadow transparency and color

Example:

vec_set(mat_model.ambient_blue,vector(255,0,0));
// gives all models a bluish tint by reflecting only the blue part of static lights

Predefined Surface Shaders

The mtlFX.c library in the code subfolder contains a collection of predefined surface shaders. All shaders can be examined and edited in the Shader Viewer. For using a surface shader, include mtlFX.c in your main script, assign the shader action to the entity, and adjust the entity skills that serve as shader parameters.

The following surface shaders are available (for details see the comments in mtlFX.c):

Action
Material
Shader
Lights Lightmap
Remarks
fx_toon mtl_toon Cartoon shading 1 no  
fx_gooch mtl_gooch Gooch shading 1 no  
fx_bump mtl_bump Bump mapping (Lambert) 2 yes Normal map on 2nd skin
fx_specBump mtl_specBump Specular bump mapping (Phong) 2 yes Normal map on 2nd skin
fx_specBump2 mtl_specBump2 Specular bump mapping (Blinn) 2 yes Normal map on 2nd skin
fx_parallax mtl_parallax Parallax mapping (Lambert) 1 no Normal map on 2nd skin, height map on 3rd skin
fx_specParallax mtl_specParallax Parallax mapping (Phong) 1 no Normal map on 2nd skin, height map on 3rd skin
fx_specParallax2 mtl_specParallax2 Parallax mapping (Blinn) 1 no Normal map on 2nd skin, height map on 3rd skin
fx_pom mtl_pom Occlusion mapping (Lambert) 1 no Normal map on 2nd skin, height map on 3rd skin
fx_specPom mtl_specPom Occlusion mapping (Phong) 1 no Normal map on 2nd skin, height map on 3rd skin
fx_specPom2 mtl_specPom2 Occlusion mapping (Blinn) 1 no Normal map on 2nd skin, height map on 3rd skin
fx_envMap mtl_envMap Environment mapping n/a n/a Uses level sky cube
fx_envBump mtl_envBump Environment bump mapping n/a n/a Normal map on 2nd skin
fx_envPara mtl_envPara Environment parallax mapping n/a n/a Normal map on 2nd skin, height map on 3rd skin
fx_envPom mtl_envPom Environment occlusion mapping n/a n/a Normal map on 2nd skin, height map on 3rd skin
fx_terraintex mtl_terraintex Terrain multitexture effect 8 no Fixed function effect, unlimited textures
fx_terraintex3 mtl_terraintex3 Terrain 3-texture shader 6 yes Use action for assignment; lightmap on alpha
fx_water_mirror mtl_water_mirror Water ripple realtime reflection n/a n/a Use action for assignment
fx_floor_mirror mtl_floor_mirror Floor realtime reflection n/a n/a Use action for assignment
fx_waterEnv mtl_waterEnv Water environment reflection n/a n/a Use action for assignment
fx_uvspeed mtl_uvspeed Texture shifting 8 yes  
fx_treeWindAni mtl_treeWindAni Tree/grass wind animation 6 no  

The Lights column indicates the number of simultaneously supported lights, and the Lightmap column indicates whether the shader also supports lightmaps on blocks, models, or terrain. For details about the shaders please see the comments inside mtlFX.c.

Remarks

For adding a shader to an entity action in a lite-C script, set the 4 shader variables and the material at the beginning of the entity action:

Example (lite-C):

#include "mtlFX.c"
...
action bumpy_warrior()
{
  my.skill41 = floatv(50);  // facAmbient
  my.skill42 = floatv(50);  // facDiff
  my.skill43 = floatv(50);  // facSpec
  my.skill44 = floatv(50);  // shininess
  my.material = mtl_specBump();
  ...
}
For applying a lightmap-supporting shader to a block or group in WED, look under Apply Shaders. Shader variables for level block shaders can be set globally through skill41..skill44 of the level_ent entity.

Predefined Postprocessing Shaders

The mtlView.c library in the code subfolder contains a collection of predefined postprocessing shaders. All postprocessing shaders can also be examined and edited in the Shader Viewer. For using a postprocessing shader, define a view stage and assing the shader material to it. The following postprocessing shaders are available:

Material
Shader Remark
mtl_blur Blur filter  
mtl_bloomblur Bloom blur  
mtl_gaussian Gaussian blur  
mtl_dilate Dilatation filter  
mtl_displace Displacement filter  
mtl_erode Erosion filter  
mtl_kuwahara Kuwahara filter  
mtl_median Median filter  
mtl_sharpen Sharpen  
mtl_sharpen2 Sharpen more  
mtl_bleach Bleach  
mtl_desaturate Desaturate  
mtl_sepia Sepia tone  
mtl_monochrome Monochrome  
mtl_negative Negative  
mtl_colorshift Colorshift  
mtl_colorspin Colorspin  
mtl_emboss Emboss effect  
mtl_laplace Laplace filter  
mtl_sobel Sobel filter  
mtl_posterize Posterize effect  
mtl_lens Lens effect  
mtl_bias Bias effect  
mtl_stencilBlur Stencil Blur Call stencil_switch(1); for activating

For editing a postprocessing shader and observing the results in real time, copy the pp_....fx shader code from the code folder into the projects\shadertest folder, and edit it with SED. If the same shader is selected in the Shader Viewer, the results can be immediately observed whenever the shader code is saved. For adding a new postprocessing shader, copy mtlView.c into the projects\shadertest folder, and add a new material and a new .fx effect just like the already defined shaders.

For assigning a postprocessing stage to a view, use the function pp_set(VIEW*,MATERIAL*).

Example (lite-C):

#include "mtlView.c"
... 
function main()
{
   pp_set(camera,mtl_blur);
   ...
} 

See also:

entity.material, view.material

► latest version online