Shaders
Shaders are programs used for the production of appropriate levels of light and color within an image, to produce special effects, or do post-processing. Shaders in Kanzi are based on the OpenGL ES 2.0 shading language.
Each material type in Kanzi comes with shaders that define the shading algorithm. The shaders consists of vertex shaders (.frag.glsl) and fragment shaders (.vert.glsl).
In Kanzi Studio, the shader programs are stored as external files. 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 shaders that ship with Kanzi in <KanziInstallation>/Studio/Asset Library/MaterialTypes:
- ES2_High contains slower-performing material types with pixel-based shaders.
- ES2_Low contains fast-performing material types with vertex-based shaders.
- General contains material types with general purpose shaders. Because these shaders are more concerned with functionality and quality than performance, these material types are suitable for development purposes.
Kanzi comes with these shaders:
- FontDefault renders text font. This shader combines the glyph texture with font color and displays the output. You can use it with Text Block 3D and Text Block 2D objects. See Using the Text Block nodes and .
- Phong implements the Blinn-Phong shading model. Shader supports at most two point lights and one directional light in ES2_Low and ES2_High profiles. In the General profile the shader supports at most two directional lights, two point lights, and two spot lights. In ES2_Low profile the shader calculates the lighting for each vertex, in the ES2_High and General profiles for each fragment.
- Ambient term controls the term in lighting model that is reflected constantly for all points rendered.
- Diffuse term controls the ratio of reflection of incoming light.
- Specular term controls the ratio of specular reflection (light reflection compared to viewer) of incoming light.
- Specular exponent controls how much the reflectance is spread.
- Emissive term controls how much light is emitted constantly for all points rendered.
- Textured displays texture data. See Creating textured materials and Textures
- PhongCube displays cube map reflection, calculated from view vector and surface normal's reflection, and combines it with phong shading.
- PhongTextured displays combined Phong and Textured shaders.
- PhongTexturedCube displays combined PhongCube and Textured shaders.
- PhongSkinned transforms vertices based on multiple transformations and weights, commonly referred to as vertex skinning. The matrix palette and weights are part of mesh attributes, if defined in 3D software. Finally the result is combined with phong shading. Note that this shader is not compatible with geometry that doesn't contain skin data (matrix palette and weights) in mesh data.
- PhongTexturedSkinned displays combined PhongSkinned and Textured shaders.
- PhongTexturedShadowMap combines PhongTextured shader with shadow map. Shadow map is a 2D texture containing the depth information from the light source to the scene. Shader combines the depth map to the actual calculated depth from viewer, and when the calculated depth is larger than the view, the output intensity is decreased, as the fragment is in shadow.
- PhongTexturedNormalMap calculates the surface normal based on mesh geometry and deforms it using additional normal map. NormalMapStrength property controls how much the normals are deformed.
This shader is included only in the ES2_High and General profiles.
- PhongTexturedCubeNormalMap combines PhongTexturedNormalMap shader with cube map reflection, calculated from view vector and surface normal's reflection.
This shader is included only in the ES2_High and General profiles.
The main advantages of shaders is that they are programmable and that it is easy to create your own. See Editing shaders.
In Kanzi you can also use binary shaders. Binary shaders are shader programs pre-compiled by hardware manufacturer-specific compilers before they are passed to the GPU. This allows for considerably shorter loading times. See Using binary shaders.
See also
Shaders best practices
Using binary shaders
Optimizing fragment shaders
Reducing shader switches
Editing shaders
Material types and materials
Open topic with navigation