Light Mapping

mental ray 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.

mib_lightmap_sample
    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.

mib_lightmap_write
    struct {
        vector          "point",
        vector          "normal",
        vector          "tex"
    } "mib_lightmap_write" (
        color texture   "texture",
        vector texture  "coord",
        color texture   "input",
        integer         "fg_mode"
    )
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.
fg_mode
when final gathering is enabled this mode allows to tune quality by controlling the placement of final gather points all over the surface. This is usually required to achieve quality on the backside of objects or in areas which are out of view of the camera, places that mental ray final gather view dependent optimizations might not cover. Supported values are:
-1off
 0force FG point on every vertex (of the tessellated geometry)
 1force FG point on every texture pixel (texel)
 2... every second texel
 3... every third texel (default)
n (n > 3)... every n-th texel

Copyright (©) 1986-2009 by mental images GmbH