next up previous contents
Next: 2. Physics Shaders/A> Up: 1. Base Shaders/A> Previous: 1.11 Shadow

1.12 Light Mapping

mental ray 3.0 supports  light mapping. This is a two-stage process that runs on certain objects (whose materials contain a  lightmap shader) to compute illumination or other information, and write the result into a texture or elsewhere. The first stage calls the lightmap shader in vertex mode once for every vertex of the object, and collects the returned information. The second stage calls the lightmap shader in output mode to use the collected information to paint a texture or other output data by looping over all triangles of the object.

The  lightmap shaders in the base shader library collect direct and indirect illumination, and create a  writable texture map from it. Although mental ray knows only about one  lightmap shader, the base lightmap shader is split into the main shader that handles the output stage, and a separate shader for the vertex stage that is called by the main shader. This makes it easier to substitute only one stage with another user-written shader.

Illumination Sampling

The lightmap illumination sampling shader is a simple color shader that samples the surface light influx density. It gathers direct illumination and optionally indirect illumination. It should not be used in a material; instead, it should be assigned to the input parameter of the  mib_lightmap_write shader.

  

    color "mib_lightmap_sample" (
        boolean         "indirect",
        integer         "flip",
        array light     "lights"
    )

indirect tells the shader to sample  indirect illumination too.

flip is an integer value, selecting the side of the geometry to be illuminated. A value of 0 selects the direction of the normal (front side), 1 selects the opposite direction (back side) and 2 selects that illumination be sampled from both directions and combined.

lights is the array of lights from which  direct illumination should be sampled.

Lightmap Generation

The lightmap generation shader is the main  lightmap shader. It gathers geometric information and texture coordinates on the triangle vertices and then writes a triangular region of texture for each triangle. For each pixel of the texture that the triangle covers, a sampling function is called and the results are written to the shader. The lightmap shader is attached to a material using the lightmap keyword.

  

    struct {
        vector          "point",
        vector          "normal",
        vector          "tex"
    } "mib_lightmap_write" (
        color texture   "texture",
        vector texture  "coord",
        color texture   "input"
    )

texture is the  writable texture where the lightmap will be written. It must have been declared with the writable keyword.

coord is a shader that returns the texture  UV coordinates at the current particular point, such as  mib_texture_remap.

input is a shader returning the data to be written to each texture pixel. For example, using mib_lightmap_sample here is useful to gather illumination to write into the light map.


next up previous contents
Next: 2. Physics Shaders/A> Up: 1. Base Shaders/A> Previous: 1.11 Shadow
Copyright 2001 by mental images