Occlusion
Ambient Occlusion
Occlusion is a fast and simple method to simulate the effects of
global illumination. Occlusion is the extent to which the area
above a point is covered by other geometry. This is achieved by
tracing a number of probe rays inside the hemispherical area above
the point and testing to what extent this region is blocked.
Typical use of this shader is ambient occlusion, where
the shader is used to scale the contribution of ambient lighting
(which in turn may come from a diffuse environment map shader). For
this use the shader should be assigned to the ambient
parameters of materials like mib_illum_phong.
Another use of occlusion is reflective occlusion, where
the shader is used to scale the contribution from a reflection map.
For this use, the shader is generally plugged into an environment
or reflection shader slot of a material, and the actual environment
map image is plugged into the bright parameter. An
alternative is to allow the return value of the occlusion shader to
modulate the strength attribute of a reflection map shader.
A third use is to create files for external compositing, where
the occlusion shader is assigned as the primary material shader on
every object in the scene. The output can be used to modulate other
render passes to achieve proper compositing in post-production.
The shader may also be used as a light shader. The
light source must be an area light of the user type. This
generates an "ambient" lightsource with built in occlusion.
color "mib_amb_occlusion" (
integer "samples" default 16,
color "bright" default 1 1 1 1,
color "dark" default 0 0 0 0,
scalar "spread" default 0.8,
scalar "max_distance" default 0,
boolean "reflective" default off,
integer "output_mode" default 0,
boolean "occlusion_in_alpha" default off
# Version 2 parameters
scalar "falloff" default 1.0,
integer "id_inclexcl" default 0,
integer "id_nonself" default 0,
)
version 2
apply texture, light
- samples
- is the number of probe rays that will be sent. More rays yield
a smoother image. Occlusion mapping will never be as smooth as
well-tuned final gathering or photons, but is computationally
cheap.
- bright
- is the color used when no occluding objects are found and
dark is the color used when total occlusion occurs. In most
practical cases it is set to black. For partial occlusion, a
gradual mix between the two colors is returned.
- spread
- defines how large an area of the hemisphere above the point is
sampled. The value defines a cone around the sampling direction
which is narrower for small values and wider for large values. It
ranges from 0.0, for a cone that is a single direction, to 1.0 for
a cone that covers the entire hemisphere.
- max_distance
- is the range within which geometry is probed. If it is zero,
the entire scene is sampled. If it is a nonzero value, only objects
within this distance will be considered (which makes sampling much
faster) where objects outside this range do not occlude at all and
objects that are closer occlude more strongly as the distance
approaches zero.
- reflective
- if turned off sampling is performed in a cone area based around
the surface normal. If reflective is on, the samples are
instead distributed around the reflection direction. This generates
reflective occlusion which can enhance the realism of
reflection mapping greatly.
- output_mode
- defines what the returned color is: 0 enables standard
occlusion behaviour; 1 enables environment sampling. This changes
the behavior of the shader slightly. As directions are probed for
occlusion, the current environment is also sampled and weighted
based on how occluded that particular direction is. In mode 1 the
output of the function is the gathered weighted environment colors
multiplied by the bright color, and as a convenience the
dark color is added.
- Setting output_mode to 2 enables bent normals. The
average unoccluded world space normal direction is calculated and
returned encoded as a color where red is x, green is y and blue is
z. Setting output_mode to 3 is the same as 2 but the normals
are encoded in the camera coordinate space instead.
- occlusion_in_alpha
- if turned on, the scalar occlusion value is put in the returned
colors alpha component, regardless of what output_mode is
set to. The other color components remain as before.
- falloff
- only matters when max_distance is nonzero and defines
the speed at which the occlusion is attenuated by distance.
Technically, it is a power function applied to the normalized
distance from 0 to max_distance. The default value of 1.0
is a linear falloff. Values below 1.0 makes the falloff more rapid.
Practically this means that for lower values occlusion is stronger
for short distances (in small corners and crevices) and softer over
larger distances.
- id_inclexcl
- defines an object instance label (set with the tag
keyword of the object instance in the .mi file) to be included (or
excluded) from being considered occluding by the shader. Set to 0
the parameter has no effect. A positive integer means that only
object instances with a label that matches this number
will cause occlusion. A negative reverses the condition and
includes all object instances except those with a matching
label.
- id_nonself
- works similar to id_inclexcl in that it is an object
instance label determining which objects do not self- occlude. Set
to 0 it has no effect. Set to a positive integer will prevent any
object with that label from occluding other objects with the same
label. This is useful for "matte" or "stand-in" objects that
represents existing geometry in a photographic background since any
inter-occlusion between such objects are already present in the
background photo. Simple exclusion by id_inclexcl cannot
be used in this case because occlusion cast by "stand-in"
background geometry onto foreground geometry and vice versa is both
desired - only background-to-background occlusion needs to be
prohibited.
Ambient Occlusion using Final Gathering
The mental ray final gathering algorithm can return the scalar
occlusion value. This utitily shader simply returns this value as a
grayscale result.
color "mib_fg_occlusion" (
color "result_when_fg_is_off" default 1 1 1 1
)
version 1
- result_when_fg_is_off
- becomes the return value when final gathering is off. When
final gathering is on, the occlusion value is returned as a
grayscale value, and the parameter is never evaluated at all or
used in any way.
- Hence, if one puts mib_amb_occlusion into the
result_when_fg_is_off parameter, the result will be
occlusion calculated by final gathering when it is on, and
occlusion calculated by mib_amb_occlusion when final
gathering is off.
Bent Normals
"Bent normal" is a term used for the average un-occluded
direction vector from a surface point. For completely un-occluded
surfaces this is the same as the normal vector, but for surfaces
occluded by other geometry it points in the direction in which the
least amount of occluding geometry is found. Bent normals are used
as an acceleration technique for ambient occlusion, allowing very
fast rendering that look like global illumination or final
gathering lit by an environment at a small fraction of the
rendering time.
Ambient occlusion as done by the mib_amb_occlusion
shader (see mib_amb_occlusion)
is a ray tracing technique that casts potentially large numbers of
probe rays to determine to which extent a surface point is
occluded. The speed of this operation depends on the number of rays
(samples), the reach of the rays (max_distance) and
the complexity of the scene.
When rendering an animation (or multiple views of the same
scene), any object that does not move, does not change shape, or
has no moving occluding object nearby will yield the same result
for every frame. Therefore one can "bake" (render to a file) the
ambient occlusion solution once in a first rendering pass,
and re-use this result in subsequent rendering passes for any
number of frames, with potentially huge performance gains. If one
also "bakes" the average un-occluded direction (the bent normal) to
a texture, the entire process of lighting the object based on an
environment is moved to this second rendering pass, without having
to trace a single ray.
By setting the output_mode parameter to 2, 3, or 4 on the
ambient occlusion shader mib_amb_occlusion, bent normals
are returned with the vector being encoded as a color where x is
red, y is green, and z is blue. If occlusion_in_alpha is
enabled, the scalar occlusion value is returned in the alpha
channel. This color can be baked into a texture, for example with
the help of mib_lightmap_write (mib_lightmap_write)
by putting mib_amb_occlusion into its input
parameter and rendering.
Once the texture file is generated, mib_bent_normal_env
can be assigned to a surface shader (for example to the
ambient parameter of mib_illum_phong) to look up an
environment to light the object based on the baked bent normal
texture, which is placed in the bent_normals parameter of
mib_bent_normal_env.
This allows an extremely low-overhead simulation of global
illumination-like effects for rigid objects and is especially
suitable for animations. The technique does not work on deformable
objects since their occlusion, shape, and normals can vary from
frame to frame. For deformable objects, it is better to apply the
occlusion shader directly, without baking its output.
color "mib_bent_normal_env" (
color "bent_normals" default 0 0 0 1,
boolean "occlusion_in_alpha" default on,
color "occlusion" default 1 1 1,
scalar "strength" default 0.2,
shader "environment",
integer "coordinate_space" default 2,
integer "env_samples" default 1,
scalar "samples_spread" default 0.0,
transform "matrix" default 1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
)
- bent_normals
- is the bent normal data output by the occlusion shader. It
should be baked to the object. This is usually attached to a node
that does the texture lookup such as
mib_lookup_color_texture. The texture mapping used for
generating the texture must match with the one used for
lookup.
- occlusion_in_alpha
- specifies whether the scalar occlusion value is already baked
into the alpha channel of the "bent normals" pass. This uses
slightly less memory but many "bake to texture" functions of OEM
integrations of mental ray do not bake the alpha channel.
- occlusion
- is the separate occlusion channel, to be used if it was not
already baked into the alpha channel.
- strength
- is a simple scalar multiplier for the effect.
- environment
- is the environment shader to look up. If none is provided, the
environment from the material is used. To avoid image noise, it is
often desirable to use a separate, highly blurred environment map
with no high-resolution detail.
- coordinate_space
- defines the coordinate space of the bent normal:
- 0 is "unmodified". The bent normal data is assumed to be in
mental ray's internal space.
- 1 is "by matrix". The bent normal data is transformed with the
passed transformation matrix.
- 2 is world space.
- 3 is camera space.
- 4 is object space. This is often the most useful mode. If the
map is both created and used in object space, it will automatically
follow the object as it moves through an animation.
The coordinate space numbers match the output_mode parameter
values of the ambient occlusion shader, where 2 is world space, 3
is camera space, and 4 is object space.
- env_samples
- is the number of samples to take from the environment map.
Normally, a highly-blurred environment map is used where only one
sample is sufficient, but it is possible to multi-sample the
environment map by setting a non-zero value.
- sample_spread
- is the spread factor for each individual environment sample.
The range is from 0.0 (infinitely thin rays -- a single sample) to
1.0 (the entire hemisphere is sampled).
- matrix
- is an explicit transformation matrix applied to the normal data
when coordinate_space is 1. This allows arbitrary
transformations.
Copyright (©) 1986-2007 by mental images GmbH