The mip_rayswitch and mip_rayswitch_advanced utility
shaders allows different types of rays to return different results.
There are many cases in which this can be useful, including but not
limited to:
The mip_rayswitch shader is a simple shader that accepts a
set of other colors (generally set to other subshaders) to apply for
certain classes of rays.
For primary rays, eye sets the result for eye rays.
For secondary rays, transparent is the result for
transparency rays, reflection for reflection rays
and environment for environment rays.
The finalgather is the result for final gather rays
as well as child rays to final gather rays.
Similarly, shadow is the result for shadow rays,
photon catches all photon rays.
Finally, the default is the result for any other
ray type. It is not a fall-through default, however, each
of the above returns their respective result whether connected
to a shader or not (i.e. generally 0 0 0 0 black).
If one wants fall-through defaults, one must use the advanced
version of the shader:
This shader works very similar to mip_rayswitch, but
instead of accepting inputs of type "color", it accepts inputs
of type "shader".
While this no longer allows assigning a fixed color directly, it
instead allows fall-through defaults.
Each of the parameters works in a similar way: eye is
the shader for eye rays, transparent for transparency
rays, reflection for reflection rays, refraction
for refraction rays, etc.
The difference is if one of these shaders are not specified,
one of the fallthrough cases take over. If either of the specific
secondary ray type shaders are not specified, and a ray of that
type arrives, the any_secondary acts as a catch-all
for all the secondary ray types not explicitly set.
Similarly, the default parameter works as a catch all
for every unspecified shader above it.
A classical issue one runs into with mental ray is that there is simply
a single concept of "the environment", whereas one often, in practical
use, wants to separate the concept of a background to that of
an environment.
This shader accomplishes exactly that:
The shader returns background for any eye ray, transparency
ray that is a child of an eye ray, or any refracted ray that travels
in the same direction as said transparency ray would (i.e. rays of type
miRAY_REFRACT, but that was refracted by an IOR of 1.0 and is a direct
child of an eye ray).
For any other type of rays (reflection, refraction, final gathering etc.)
the shader returns the environment color.
The shader is intended to be used as the camera environment, but will
function anywhere in a shading graph as a ray switching node, in many
cases where one need to distinguish between "primary" and
"secondary" rays.
For example, this is the ideal shader to switch between primary-
and secondary rays to support the "best of both worlds" usage
of mip_matteshadow described on page
Best-of-both-worlds.
Generic Switchers
declare shader "mip_rayswitch" (
color "eye",
color "transparent",
color "reflection",
color "refraction",
color "finalgather",
color "environment",
color "shadow",
color "photon",
color "default"
)
version 1
apply material, texture, environment
end declare
declare shader "mip_rayswitch_advanced" (
shader "eye",
shader "transparent",
shader "reflection",
shader "refraction",
shader "finalgather",
shader "environment",
shader "any_secondary",
shader "shadow",
shader "photon",
shader "default"
)
version 1
apply material, texture, environment
end declare
Environment Switcher
declare shader "mip_rayswitch_environment" (
color "background" default 0 0 0 0,
color "environment" default 0 0 0 0,
)
apply texture, environment
version 1
end declare