In the visual effects industry it is common to shoot a picture of a
mirror ball (aka a "light probe") on set, as well as a gray ball
for lighting reference.
Ideally, one shoots these at multiple exposures and uses a tool
1 to combine
these into a single high dynamic range image and/or
unwrap the mirrored/gray ball into a spherical environment map.
However, it is often difficult to regain the proper orientation of
spherical map so it matches the camera used to render the CG scene.
Furthermore, a single photo of a mirror/gray ball contains poor data
for certain angles that one want to avoid seeing in the final render.
These shaders are intended to simplify a special case: When the
mirror/gray ball is already shot from the exact camera angle
that the final image will be rendered from.
It simply utilizes the mental ray camera coordinate space and applies
the mirror/gray ball in this space, hence the orientation of the
reflections will always 'stick' to the rendering camera.
Mirror Ball
This shader is intended as an environment shader, since it looks
up based on the ray direction. It will map the proper direction to a
point on the mirrored ball and retrieve its color.
declare shader "mip_mirrorball" (
color texture "texture",
scalar "multiplier" default 1.0,
scalar "degamma" default 1.0,
scalar "blur" default 0.0,
)
apply texture, environment
version 3
end declare
The texture parameter should point to an image of a mirrored ball
that is cropped so the ball exactly touches the edges of the image.
Ideally it should point directly to a mental ray color texture but it
can also be another shader.
If necessary, the shader can apply an inverse gamma correction to
the texture by the degamma parameter. If gamma is handled
by other shaders in the chain, or if the global mental ray gamma
is used, use a value of 1.0, which means "unchanged".
The color is multiplied by the multiplier and
if the texture parameter points to a literal mental ray texture,
the blur parameter can be used to blur it.
Gray Ball
This shader is can be used either as an environment shader or a
texture shader, since it looks up based on the direction of the surface
normal. It will map the normal vector direction to a point on the gray
ball and retrieve its color.
declare shader "mip_grayball" (
color texture "texture",
scalar "multiplier" default 1.0,
scalar "degamma" default 1.0,
scalar "blur" default 0.0,
)
apply texture, environment
version 3
end declare
The parameters are identical to mip_mirrorball.
Examples
Here are the photos used for the example renderings:
The mirror ball photo
The gray ball photo
Here are a few objects with an environment made using mip_mirrorball.
The objects are also lit by final gathering based on same environment:
One angle
Another angle
What is noteworthy in the above images is how the orientation of reflections
stay constant parallel to the camera. Therefore, this shader is only intended
to be used when the rendering camera direction (roughly) matches the direction
from which the mirror ball was photographed.
When using the gray ball shader:
Raw mip_grayball shader
Using ambient occlusion
The left image is the raw output of the mip_grayball shader,
but in the right the shader is put into the bright slot of
the mib_amb_occlusion shader, where it is occluded and looked
up with bent normals2.
More usage tips can be found on page matteuseagetips.
Footnotes
1
For example Photosphere (Mac) or HDRShop (PC)
2
If one do not desire the bent normal lookup of mib_amb_occlusion,
set its mode parameter to -1. Then the bright parameter
is looked up using the original (un-bent) normal, which can yield a
smoother result.