Recent Changes - Search:

PmWiki

pmwiki.org

edit SideBar

Shaders

What are the shaders?

Shaders are basically small programs which are run on your videocard for every vertex and pixel rendered.
They can be used for doing a variety of graphics tasks such as shading, lighting, special effects and much more.
Shaders are run on your videocard, so it makes it possible for the CPU to work on other tasks such as AI. Videocards are optimized for doing calculations with floating point numbers and vectors and thus it is possible to achieve performance which is tens of times bigger than what could be done using the CPU.
To use shaders, your videocard has to support them. They are supported on Radeon 9500 and more recent cards from ATI and on GeForce FX and more recent cards from NVidia.
Shaders used by Boson have to be written in GLSL - OpenGL Shading Language

What are shaders used for in Boson?

In Boson, shaders can be used for:

  • Terrain rendering
  • Unit rendering, including shadows

Shader filenames

In Boson, shaders are specified by names. Such names might be unit or ground-default. Note that the names do not have any extensions. This is because Boson supports different quality levels for shaders and filename is composed of the shader name, quality suffix and .shader extension.
Exact filename format is as follows:

<shader name><quality suffix>.shader

Quality suffix can be one of -vhi, -hi, -med and -low. When Boson is running, user can select a quality level and a list of allowed suffixes is composed. For example, when user selects "Medium" as shader quality level, then the suffix list would be -med,-low. When looking for a shader with name unit, Boson would then first look for a file unit-med.shader, then for unit-low.shader and finally for file without any quality suffix - unit.shader. Of those, first file which actually exists is used.
Usually, you can have your main shader logic in e.g. unit.shader and in files with quality suffixes, e.g. unit-low.shader, you just #define some constants (to disable or enable certain parts of your shader) and then #include the main shader.

Preprocessor and #include

Boson's shader preprocessor supports #include directive, so you can easily break your shader into multiple reusable files and then #include them into the main shader.
It works just like in C and C++:

#include "unit.shader"
#include "unit"

You can use <unit> instead of "unit" if you like, there is no difference between them.
#include searches for the included file first by using the given string as a filename and then as a shader name (which means that quality suffix and .shader will be appended). Note that the given filename or shader name has to be relative to themes/shaders/ which is where the shaders are stored.

Vertex and fragment shader

Boson doesn't use different files for vertex and fragment shaders (because by nature they belong together and thus I've found it easier to have both shaders in the same file when editing them). Instead, it uses special markers to let you specify which part of the shader file should be used for vertex shader and which for the fragment shader.
Such marker has to be on a separate line and can be either <vertex>, <fragment> or <all>. When such marker is encountered, following lines will be used either only for vertex shader, only for fragment shader or for both shaders. The default is <all> which means that lines from the beginning of the file until the first marker will be included in both shaders.

Edit - History - Print - Recent Changes - Search
Page last modified on October 21, 2005, at 15:07