Datatypes, Variables & Memory Usage

return to main index

Thanks for the Memory

When a shader is used by the renderer it has access not only to itw own data, which is loaded into its own private memory, but also to shared data that is maintained by the renderer.

Memory can be visualized as a long sequence of storage containers. Each container, or memory location, is capable of storing a single item of data. For example, the items shown in green P, N identify data that a displacement shader can read and modify.

The items shown in purple s, t, u, v identify data that a displacement shader can read but not modify.


Instance Variables

Shaders have access to data stored in instance variables. An example of an instance variable is Km shown below.

    displacement test(float Km = 0.1)

Data given to the shader from the RIB file is shown within the parentheses. The word float denotes a data type. The float data type indicates a single numeric value will be stored in memory.

The next word, Km, is the name of an instance variable. Essentially, Km is a label that identifies a memory container.


Local Variables

Shaders can also access data stored in local variables.

    float hump = 0;
    point n;

A shader must declare the memory containers it will use to store the results of any calculations it performs.

The word point is another data type. It indicates that three values will be stored in memory. Notice that "n" acts as a label to three memory containers that will eventually contain the X, Y and Z values of a location in space.

Because "n" has not been assigned an xyz value it will not contain any useful data - it contains "junk".


© 2002- Malcolm Kesson. All rights reserved.