Content deleted Content added
No edit summary Tags: Mobile edit Mobile web edit |
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags |
||
Line 6:
An example of a surface shader that defines a metal surface is:
<
surface metal (float Ka = 1; float Ks = 1; float roughness = 0.1;)
{
Line 14:
Ci = Os * Cs * (Ka * ambient() + Ks * specular (Nf, V, roughness));
}
</syntaxhighlight>
Shaders do the work by reading and writing special variables such as Cs (surface color), N (normal at given point), and Ci (final surface color).
The arguments to the shaders are global parameters that are attached to objects of the model (so one metal shader can be used for different metals and so on). Shaders have no return values, but functions can be defined which take arguments and return a value. For example, the following function computes vector length using the [[dot product]] operator ".":
<
float length (vector v) {
return sqrt (v . v); /* . is a dot product */
}
</syntaxhighlight>
==Further reading==
|