Predefined Postprocessing Shaders

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

Material / Effect
Shader Adjustable Parameters Remarks
mtl_hdr A8.12 HDR effect Strength, Threshold,
facExposure, timeExposure
facExposure = 0 disables exposure compensation (faster).
mtl_blur Blur filter facBlur  
mtl_gaussian Gaussian blur facBlur  
mtl_dilate Dilatation filter    
mtl_displace Displacement filter displacement  
mtl_erode Erosion filter    
mtl_kuwahara Kuwahara filter nPixels  
mtl_median Median filter    
mtl_sharpen Sharpen facSharpen  
mtl_sharpen2 Sharpen more    
mtl_bleach Bleach opacity  
mtl_desaturate Desaturate desat  
mtl_sepia Sepia tone    
mtl_monochrome Monochrome    
mtl_negative Negative    
mtl_colorshift Colorshift xShift, yShift, zShift  
mtl_colorspin Colorspin    
mtl_emboss Emboss effect    
mtl_laplace Laplace filter    
mtl_sobel Sobel filter    
mtl_posterize Posterize effect nColors, gamma  
mtl_lens Lens effect xPos, yPos  
mtl_bias Bias effect bias, gradient  
st_stencilblur.fx Poisson Stencil Blur   Call stencil_blur(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.

The adjustable parameters can be set up in skill1...skill4 of the material. They are in the floatv(0)...floatv(100) range.

The following functions are available in the mtlView.c library:

stencil_blur (dist)

Activates or deactivates Poisson blurring for stencil shadows.


dist - blur distance (0.1 .. 4), 1 for normal blur, or 0 for disabling blurred stencil shadows.

pp_set (VIEW*, MATERIAL*)

Assigns a postprocessing stage to a given view.

pp_add (MATERIAL*) A8.23

Adds a new postprocessing stage to the last stage.


VIEW* - view pointer.
MATERIAL* - material pointer with the postprocessing effect, or NULL for removing the effect from the last stage (single-stage effects only).

Example (lite-C):

#include <mtlView.c>
function main()
  pp_add(mtl_sepia); // combine HDR and sepia

See also:

entity.material, view.material, surface shaders

► latest version online