Shader Scripts
From Multiverse
Contents |
What is a shader?
A shader is a program (a script, actually) that runs directly on the client machine's graphics card. Shaders are sometimes referred to as vertex or fragment programs.
There are two primary types of shaders: vertex shaders and pixel shaders.
Vertex shaders
Each time the client draws a model (a mesh), it runs the vertex shader for the current material for every vertex of that mesh. Vertex shaders are typically responsible for transforming the vertex coordinates and performing per-vertex lighting calculations. The vertex shader typically moves vertices when performing skeletal animation.
Other examples of use of vertex shaders are ocean waves and grass blowing in the wind. In the case of the ocean, the mesh is actually a flat plane. The wave motion is added by the vertex shader computing a function (involving multiple sine waves) based on the vertex location and the current time. In the case of grass, each grass instance is a quad (a rectangle built from two triangles). The vertex shader is responsible for aligning the quad so that it is always facing the camera, and also animated the upper two vertices of the quad to simulate the grass waving in the wind.
Pixel shaders
The client runs a pixel shader for every pixel that it draws to determine the color of the pixel. In the simplest case, the shader does this by multiplying the lighting color produced by the vertex shader with the texture color fetched for that particular pixel. More complex uses of pixel shaders include normal mapping, where the surface normal used in the lighting calculation is fetched from a texture, and the lighting calculation performed at every pixel, rather than every vertex.
Shader libraries
A shader library is a collection of pre-coded shaders that implement a variety of functionality and special effects that you can use in your materials.
Languages
The Multiverse Client supports vertex programs written in:
