Shaders

Shaders are programs you use to create appropriate levels of light and color in an image, to produce special effects, or do post-processing. Shaders in Kanzi are based on the OpenGL ES shading language.

Each material type in Kanzi comes with shaders that define the shading algorithm. The shaders consist of vertex shaders (.vert.glsl) and fragment shaders (.frag.glsl).

In Kanzi Studio projects shader programs are stored as files on the computer hard drive. When you add shaders to the <KanziWorkspace>/Projects/<ProjectName>/Shaders directory of your Kanzi Studio project, Kanzi Studio automatically shows them in the Library > Resource Files > Shaders.

You can find the shaders that come with Kanzi in <KanziInstallation>/Studio/Asset Library/MaterialTypes:

  • Common directory contains material types with general purpose shaders. These shaders are suitable for prototyping and are not optimized for performance. See General-purpose shaders.

  • FragmentPhong directory contains material types with pixel-based Phong shaders. See Pixel-based Phong shaders.

  • PhysicallyBasedRendering directory contains material types with physically-based shaders. See Physically-based shaders.

  • Unlit directory contains material types with shaders that do not use lights. See Unlit shaders.

  • VertexPhong directory contains material types with vertex-based Phong shaders. See Vertex-based Phong shaders.

You can also write your own shaders. See Editing shaders.

In Kanzi you can also use binary shaders. Binary shaders are shader programs you pre-compile with compilers provided by hardware manufacturers before the application passes them to the device GPU. This enables your target device to load your application faster. See Using binary shaders.

General-purpose shaders

The <KanziInstallation>/Studio/Asset Library/MaterialTypes/Common directory contains material types with general-purpose shaders. These shaders are suitable for prototyping and are not optimized for performance.

Shader

Description

ColorTexture

Displays colored texture data.

DefaultBlit

Default shader used by the Blit Render Pass. See Rendering.

FontDefault

Renders text font. This shader combines the glyph texture with font color and displays the output. You can use it with the Text Block and Text Box nodes. See Using the Text Block nodes and Using the Text Box nodes.

MaskTexture

Displays texture data where one texture masks another texture.

SweepTextures

Displays texture data with a transition from one texture to another.

Textured

Displays texture data. See Textures and Creating textured materials.

Pixel-based Phong shaders

The <KanziInstallation>/Studio/Asset Library/MaterialTypes/FragmentPhong directory contains material types with pixel-based Phong shaders for use with OpenGL ES2. Most of the GPU specific computation, including applying lights using the Phong reflection model, is done in the fragment shader. This offers better image quality often at the cost of performance.

Shader

Description

FragmentPhong

Implements the Blinn-Phong shading model. By default this shader supports one directional, one spot light, and two point lights. The shader calculates the lighting for each fragment.

FragmentPhongCube

Displays cube map reflection, calculated from the view vector and reflection of the surface normal, and combines the result with the Phong shading.

FragmentPhongSkinned

Displays skinned mesh data. See Using skinned meshes.

FragmentPhongTextured

Displays texture data you can use on 3D nodes. See Textures and Creating textured materials.

FragmentPhongTexturedSkinned

Combines the FragmentPhongSkinned and FragmentPhongTextured shaders.

FragmentPhongTexturedCube

Combines the FragmentPhongCube and FragmentPhongTextured shaders.

FragmentPhongTexturedNormalMap

Calculates the surface normal based on mesh geometry and deforms it using additional normal map. The NormalMapStrength property controls how much the normals are deformed.

FragmentPhongTexturedCubeNormalMap

Combines the FragmentPhongTexturedNormalMap shader with cube map reflection, calculated from the view vector and reflection of the surface normal.

Vertex-based Phong shaders

The <KanziInstallation>/Studio/Asset Library/MaterialTypes/VertexPhong directory contains material types with vertex-based Phong shaders optimized for use with OpenGL ES2. Most of the GPU specific computation, including applying lights using the Phong reflection model, is done in the vertex shader. This is a good starting point for most devices.

Shader

Description

VertexPhong

Implements the Blinn-Phong shading model. By default this shader supports one directional, one spot light, and two point lights. The shader calculates the lighting for each vertex.

VertexPhongCube

Displays cube map reflection, calculated from the view vector and reflection of the surface normal, and combines the result with the Phong shading.

VertexPhongMorph

Enables morphing. See Using Morph resources.

VertexPhongSkinned

Displays skinned mesh data. This shader transforms vertices based on multiple transformations and weights, and combines the result with the Phong shading.

If you define the matrix palette and weights in a third-party content creation tool, they are part of mesh attributes.

This shader is not compatible with geometry that does not contain skin data (matrix palette and weights) in mesh data.

See Using skinned meshes.

VertexPhongTextured

Displays texture data you can use on 3D nodes. See Textures and Creating textured materials.

VertexPhongTexturedCube

Combines the VertexPhongCube and VertexPhongTextured shaders.

VertexPhongTexturedMorph

Combines the VertexPhongMorph and VertexPhongTextured shaders.

VertexPhongTexturedSkinned

Combines the VertexPhongSkinned and VertexPhongTextured shaders.

Physically-based shaders

The <KanziInstallation>/Studio/Asset Library/MaterialTypes/PhysicallyBasedRendering directory contains material types with physically-based shaders intended for OpenGL ES3 applications. These shaders implement physically-based rendering (PBR) principles. The properties of physically-based materials represent physical properties, such as metalness, and are therefore intuitive to control. Most of the GPU specific computation, including applying lights using a physically-based lighting model, is done in the fragment shader. This offers a more realistic rendering result in many lighting conditions.

Shader

Description

PhysicallyBased

Implements a physically-based shading model and by default enables:

  • Setting roughness and metalness

  • One directional, one spot light, and two point lights

  • Base color alpha

  • Reinhard tone mapping

PhysicallyBasedClearCoat

Uses physically-based rendering to render a material covered with a clear coat. This is commonly used for vehicle paint.

PhysicallyBasedMorph

Enables morphing with 3 targets by default. See Using Morph resources.

PhysicallyBasedSkinned

Enables skinning of meshes with up to 64 bones by default. See Using skinned meshes.

PhysicallyBasedTextured

Enables the use of textures that contain the base color, normal, roughness, metallic, and occlusion maps, and the light emitted from the material. See Creating a physically-based textured material.

PostProcessTonemap

Full-screen post-processing material which by default applies Reinhard tone mapping.

Unlit shaders

The <KanziInstallation>/Studio/Asset Library/MaterialTypes/Unlit directory contains material types with shaders that use the unlit shading model defined by the KHR_materials_unlit glTF extension. The unlit shaders provide an alternative to physically-based shaders, which you can use for performance or aesthetic reasons. For example, you can use unlit materials to achieve a "hand-drawn" look where you do not want lighting.

Shader

Description

Unlit

Implements an alternative to the physically-based shading models without lighting calculations, tone mapping, and extraneous texture maps and factors.

UnlitMorph

Enables morphing with 3 targets by default. See Using Morph resources.

UnlitSkinned

Enables skinning of meshes with up to 64 bones by default. See Using skinned meshes.

UnlitTextured

Enables the use of textures for an unlit material.