Shader System

Overview

Shaders in Lightning Engine are special renderer plug-ins used to configure how a piece of geometry is rendered. A shader is a combination of multiple shader programs (usually a triplet of vertex / geometry / fragment programs with all their permutations) and the renderer's state (e.g blending, depth testing, etc.) required for rendering an object at a specific pass of a specific render path. Each shader can be executed multiple times per-object in the same frame, allowing complex effects such as fur to be implemented easily.
Hierarchical shader interfaces used by a surface shader

Shader interfaces are used in order to generate shader permutations automatically without the need to write special case shader programs. For example, all shaders using lights from the scene (e.g. per-pixel phong shading) use shader interfaces, for abstracting light based calculations (light vector, shadows, attenuation, etc.), allowing for faster implementation and testing of (e.g) new shadowing algorithms. The same base shader is used, with all its permutations generated on the fly automatically by the engine, when and if they are needed (e.g. the shader is generated the first time an object gets in the light's effective area).

More informations about the connection between shaders and the renderer can be found here.

Lightning Visual Shader Builder

Lightning Engine's toolbox includes an application for automatic generating shader DLLs, named Shader Builder. Shader Builder is designed to give artists the flexibility programmers have when writing C++ code for shaders. Artists don't have to know any programming language in case to build new shaders.

Shader Builder uses a graph for visually representing a shader program. All you have to do is to create the appropriate nodes and connect them together in case to compose a shader program. When you have built all the neccessary programs, you can specify all the state changes required by the shader, and by clicking one button you have your shader ready for use inside the engine.

Graph nodes are essentially chunks of shader code, with extra information about the needed input and the produced output. Anyone who knows a high level shading language, such as Cg or GLSL, can write custom nodes from within Shader Builder and save them in a library for later use.

Inside Shader Builder there is the material editor for creating new materials as well as configuring existing material parameters. The preview window displays the result exactly as it will appear inside the engine. This way artists can fine-tune material parameters and shader program graphs, by previewing the changes in real time, without the need to run the engine. Below are some example materials as they appear inside Shader Builder.