<html>
<head>
<title>Builtin</title>
</head>
<body bgcolor="#ffffff">
<tab id=0 indent=0>
<tab id=1 indent=4>
<tab id=2 indent=8>
<tab id=3 indent=12>
<tab id=4 indent=16>
<tab id=5 indent=20>
<tab id=6 indent=24>
<tab id=7 indent=28>
<tab id=8 indent=32>
<tab id=9 indent=36>
<tab id=10 indent=40>
<tab id=11 indent=44>
<tab id=12 indent=48>
<tab id=13 indent=52>
<tab id=14 indent=56>
<tab id=15 indent=60>
<tab id=16 indent=64>
<tab id=17 indent=68>
<tab id=18 indent=72>
<tab id=19 indent=76>
<p><a name=cB><h1>Built-in Shaders</h1></a> 

<p>Built-in shaders exist to support SOFTIMAGE and Wavefront compatibility. All shaders are described by listing their parameters, both in .mi scene file format and as a C structure. The C structure is particularly useful if custom shaders are written that improve on the operation of existing shaders by building or re-using the C structures of existing shaders and calling them, and modifying the results. 

<p>The <a name=iBCBB></a><u>shading model</u>s supported by the SOFTIMAGE and Wavefront material are given as equations, which use the following variables: 

<p> 
<p><pre> <i>n<sub>s</sub></i> is the <a name=iBCBC></a><u>shinyness</u>,
 <i>d</i>  is the <a name=iBCBD></a><u>transparency</u>,
 <i>t</i>  is the <a name=iBCBE></a><u>refraction</u>,
 <i>n<sub>r</sub></i> is the <a name=iBCBF></a><u>reflectivity</u>,
 <i>k<sub>a</sub></i> is the <a name=iBCBG></a><u>ambient color</u>,
 <i>k<sub>d</sub></i> is the <a name=iBCBH></a><u>diffuse color</u>,
 <i>k<sub>s</sub></i> is the <a name=iBCBI></a><u>specular color</u>,
 <i>f<sub>t</sub></i> is the <a name=iBCBJ></a><u>transmission filter</u>,
 <i>N</i>  is the surface <a name=iBCCA></a><u>normal</u>,
 <i>V</i>  is the vector pointing at the viewer,
 <i>n</i>  is the number of light sources,
 <i>L<sub>i</sub></i> is the vector pointing at <a name=iBCCB></a><a href=scene.html#iDHH>light</a> <i>i</i>,
 <i>H</i>  is the vector halfway between <i>V</i> and the direction of the <a name=iBCCC></a><u>reflection</u>,
 <i>H<sub>i</sub></i> is the vector halfway between <i>V</i> and <i>L<sub>i</sub></i>
 <i>f</i>  is the <a name=iBCCD></a><u>Fresnel</u> function.
 <i>I<sub>i</sub></i> is the intensity contributed by <a name=iBCCE></a><a href=scene.html#iDHH>light</a> <i>i</i>,
 <i>I<sub>r</sub></i> is the intensity contributed by <a name=iBCCF></a><u>reflection</u>, and
 <i>I<sub>t</sub></i> is the intensity contributed by transmission<a name=iBCCG></a> (<a name=iBCCH></a><u>transparency</u>).
 
</pre><p> 

<p>Note that the Wavefront <a name=iBCCI></a><u>dissolve</u> parameter is equivalent to <i> 1 - transparency</i> in mental ray. 

<p><br>
 <p><a name=cC><h2>SOFTIMAGE Shaders</h2></a> 

<p>Seven shaders implement SOFTIMAGE compatibility. The material and light shader are controlled by a mode parameter that controls which behavior is desired. There are also five compatibility shaders that are no longer required for SOFTIMAGE compatibility, but were present in version 1.8 of mental ray and are still supported to allow version 1.8 .mi scene files to be read. These shaders are not recommended for new developments and may not be supported in future versions of mental ray. 

<p><a name=iBCCJ></a> 
<p><pre> <i>name</i>                    <i>operation</i> 
 <hr>
 <tt><b>soft_material</b></tt>           material shader, also used as shadow shader
 <tt><b>soft_color</b></tt>              2D texture shader 
 <tt><b>soft_color_3d</b></tt>           3D texture shader 
 <tt><b>soft_vertex_color</b></tt>       RGB vertex color shader 
 <tt><b>soft_vertex_color_alpha</b></tt> RGBA vertex color shader 
 <tt><b>soft_light</b></tt>              light shader: point, infinite, spot 
 <tt><b>soft_displace</b></tt>           displacement shader 
 <tt><b>soft_env_sphere</b></tt>         spherical environment shader 
 <tt><b>soft_fog</b></tt>                standard fog volume shader 
 <tt><b>soft_layered_fog</b></tt>         layered fog volume shader 
 <tt><b>lens_depth_of_field</b></tt>     depth-of-field lens shader 
 <hr>
 <tt><b>soft_shadow</b></tt>             obsolete shadow shader, calls <tt><b>soft_material</b></tt> 
 <tt><b>soft_point</b></tt>              point light shader, calls <tt><b>soft_light</b></tt>
 <tt><b>soft_infinite</b></tt>           directional light shader, calls <tt><b>soft_light</b></tt>
 <tt><b>soft_spot</b></tt>               spot light shader, calls <tt><b>soft_light</b></tt>
 <hr>
 
</pre><p> 

<p>If any of these shaders is used in a .mi scene file, the scene file must include the <tt><b>softimage.mi</b></tt> header file that contains the shader declarations, using a <tt><b>$include</b></tt> command<a name=iBCDA></a> (see <a href=scene.html#iDEG>include command</a>) . The C structures are declared in a file <a name=iBCDB></a><u><tt><b> mi_softshade.h</b></tt></u>, to be included in the C source file of custom shaders making direct calls to SOFTIMAGE shaders. Note that these files must always match the version of mental ray, or shaders will operate incorrectly or even crash. 

<p> <p><a name=cD><h3>soft_material</h3></a> 

<p><a name=iBCDC></a><a name=iBCDD></a> (see <a href=scene.html#iDJH>material shader</a>) The material shader implements constant, Lambert, Phong, and Blinn shading. <a name=iBCDE></a><a name=iBCDF></a><a name=iBCDG></a><a name=iBCDH></a><a name=iBCDI></a>Its operation includes inside/outside determination, texture evaluation, light <a name=iBCDJ></a><u>illumination</u>, <a name=iBCEA></a><u>reflection</u>, and <a name=iBCEB></a><u>transparency</u>. 

<p>This shader can also be used as a <a name=iBCEC></a><a href=scene.html#iECC>shadow shader</a>; it recognizes this case automatically and performs the subset of the material evaluation required for determining the color of light transmitted by the material. This includes testing whether the light that cast the shadow ray is in the shadow material's light list, collecting the diffuse<a name=iBCED></a> and <a name=iBCEE></a><u>transparency</u> contributions of textures only, and calculating the resulting transmission color. All other operations are omitted. The material shader considers itself a shadow shader if the state variable <i>type</i> has the value <tt><b>miRAY_LIGHT</b></tt>. 

<p>For a general explanation of shading in computer graphics, refer to [Hall 89] or [Foley 90].  The illumination of a surface using Phong mode is computed according to 

<p>
<p><center> k<sub>a</sub> + k<sub>d</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,L<sub>i</sub>&gt; I<sub>i</sub><br>
+ k<sub>s</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,H<sub>i</sub>&gt;<sup>n<sub>s</sub></sup> I<sub>i</sub><br>
+ n<sub>r</sub> I<sub>r</sub><br>
+ t I<sub>t</sub><br>
.
</center><p>
 

<p>Blinn mode differs from the Phong mode in that it attenuates the specular highlights by a geometrical attenuation factor <i>G</i> (see [Foley 90]).  The illumination of a surface with this <a name=iBCEF></a><a href=scene.html#iDJG>material</a> is computed according to 

<p>
<p><center> k<sub>a</sub> + k<sub>d</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,L<sub>i</sub>&gt; I<sub>i</sub><br>
+ k<sub>s</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,H<sub>i</sub>&gt;<sup>n<sub>s</sub></sup> G(&lt;L<sub>i</sub>,H<sub>i</sub>,V,N&gt;) I<sub>i</sub><br>
+ n<sub>r</sub> I<sub>r</sub><br>
+ t I<sub>t</sub><br>
.
</center><p>
 

<p>Lambert mode only calculates the contribution of the <a name=iBCEG></a><u>ambient color</u> and <a name=iBCEH></a><u>diffuse color</u> and omits the specular component.<a name=iBCEI></a>: 

<p>
<p><center> k<sub>a</sub> + k<sub>d</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,L<sub>i</sub>&gt; I<sub>i</sub><br>
+ n<sub>r</sub> I<sub>r</sub><br>
+ t I<sub>t</sub><br>
.
</center><p>
 

<p>Constant shading simply assigns the <a name=iBCEJ></a><u>diffuse color</u>, without actually performing illumination calculation, and disregards both the <a name=iBCFA></a><u>ambient color</u> and <a name=iBCFB></a><u>specular color</u>: 

<p>
<p><center> k<sub>d</sub> + n<sub>r</sub> I<sub>r</sub><br>
+ t I<sub>t</sub><br>
.
</center><p>
 

<p>The material shader has the following .mi scene file declaration: 

<p><pre>
     declare "soft_material" (
        integer         "mode",         # 0=flat, 1=lambert, 2=phong, 3=blinn
        color           "ambient",
        color           "diffuse",
        color           "specular",
        color           "ambience",
        scalar          "shiny",
        scalar          "transp",
        scalar          "reflect",
        scalar          "ior",
        
        array struct    "texture" {
        
                color texture   "map",
                integer         "space",
                integer         "mask",
                integer         "comp",
                integer         "method",
                scalar          "blend",
                scalar          "ambient",
                scalar          "diffuse",
                scalar          "specular",
                scalar          "transp",
                scalar          "reflect",
                scalar          "bump",
                scalar          "u_unit",
                scalar          "v_unit",
                scalar          "u_wrap",
                scalar          "v_wrap",
                boolean         "blackwhite"
        },
        array light     "lights",
        boolean         "sblur",
        scalar          "sblurdecay",
        boolean         "notrace",
        array light     "difflights"
     )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct soft_material {
       miInteger      mode;        /* flat,lmb,phong,blinn*/
       miColor        ambient;     /* ambient color */
       miColor        diffuse;     /* diffuse color */
       miColor        specular;    /* specular color */
       miColor        ambience;    /* ambience factor */
       miScalar       shiny;       /* specular decay */
       miScalar       transp;      /* transparency */
       miScalar       reflect;     /* reflectivity */
       miScalar       ior;         /* refraction index */
       int            i_texture;   /* index of 1st texture*/
       int            n_texture;   /* number of textures */
       struct Tex {
          miTag       map;         /* texture file */
          miInteger   space;       /* texture vertex space*/
          miInteger   mask;        /* 0=none,1=alpha,2=int*/
          miInteger   comp;        /* 1=alpha,2=intens */
          miInteger   method;      /* 0..4=XY,YZ,XZ,UV,cyl*/
          miScalar    blend;       /* overall blending */
          miScalar    ambient;     /* ambient weight */
          miScalar    diffuse;     /* diffuse weight */
          miScalar    specular;    /* specular weight */
          miScalar    transp;      /* transparency weight */
          miScalar    reflect;     /* reflectivity weight */
          miScalar    bump;        /* bump mapping weight */
          miScalar    u_unit;      /* epsilon dist in tex */
          miScalar    v_unit;      /* space, for bump grad*/
          miScalar    u_wrap;      /* u_unit if u+u_unit */
          miScalar    v_wrap;      /* is outside of [0, 1)*/
          miBoolean   blackwhite;  /* white or black-&gt;t=0 */
       }              *texture;    /* texture array */

       int            i_light;     /* index of first light*/
       int            n_light;     /* number of lights */
       miTag          *light;      /* list of lights */

       miBoolean      sblur;       /* static blur mode */
       miScalar       sblurdecay;  /* sblur falloff */
       miBoolean      notrace;     /* no refl, just env */

       int            i_difflight; /* index of first */
       int            n_difflight; /* number of lights */
       miTag          *difflight;  /* diffuse lights */
    };
</pre>


<p>If the shader is used as a <a name=iBCFC></a><a href=scene.html#iECC>shadow shader</a>, only the <tt><b>diffuse</b></tt> <a name=iBCFD></a> and <tt><b>transparency</b></tt><a name=iBCFE></a> components, the light list<a name=iBCFF></a> and the diffuse light list (the material is ignored if it does not list the shadow-casting light in either list), and the texture array are used. Of the texture array elements, only <tt><b>map</b></tt>, <tt><b>mask</b></tt>, <tt><b>comp</b></tt>, <tt><b>blend</b></tt>, <tt><b>diffuse</b></tt>, and <tt><b>transp</b></tt> are used. All other fields are ignored in shadow shader mode. 

<p>The shader assumes that there are enough texture coordinates and <a name=iBCFG></a><u>bump basis vectors</u> stored in the state to satisfy all <tt><b>space</b></tt> parameters. That is, if there the largest <tt><b>space</b></tt> parameter is <i>n</i>, there must be <i>n+1</i> texture coordinates. No bump basis vectors are required for bump mapping, they are computed on the fly. 

<p>As described in the ``Writing Shaders'' chapter, every array appears in the C structure as two integers giving the index of the first element and the number of elements, and the array itself, with one member regardless of the true array size. Arrays are indexed with code like 

<p><pre>
     for (n=0; n &lt; paras-&gt;n_array; n++)
             do_something(paras-&gt;array[paras-&gt;i_array + n]);
</pre>


<p>In the rest of this chapter, the array support integers prefixed with <tt><b>i_</b></tt> and <tt><b>n_</b></tt> follow these rules and are not described explicitly. This is a list of all material shader parameters: 

<p> 
<dl>

<dt><tt><b>mode</b></tt>
<dd>    This integer selects the <a name=iBCFH></a><u>shading model</u> of the material: 0 for constant, 1 for Lambert, 2 for Phong, and 3 for Blinn. <a name=iBCFI></a><a name=iBCFJ></a><a name=iBCGA></a><a name=iBCGB></a> 
<dt><tt><b>ambient</b></tt>
<dd>    The <a name=iBCGC></a><u>ambient color</u> of the material that is always added, regardless of the illumination, in modes 1, 2, and 3. It is ignored in mode 0. The ambient color is multiplied by the ambience before being added, see below. This and the next three colors are RGB colors, alpha is ignored. 

<p>
</dl>

<dl>

<dt><tt><b>diffuse</b></tt>
<dd>    The <a name=iBCGD></a><u>diffuse color</u> of the material. It determines the color of the material in mode 0. In all other modes, it is added to the material color after multiplication with factor depending on the <a name=iBCGE></a><u>illumination</u> direction and the normal, evaluated once for each light. 

<p>
</dl>

<dl>

<dt><tt><b>specular</b></tt>
<dd>    The <a name=iBCGF></a><u>specular color</u> is added to the material color in modes 2 and 3, after multiplication with a factor depending on the mode, the illumination direction, and the normal, and the shinyness factor, evaluated once for each light. 

<p>
</dl>

<dl>

<dt><tt><b>ambience</b></tt>
<dd>    The <a name=iBCGG></a><u>ambience color</u> is a factor that is used by SOFTIMAGE to adjust the amount and color of ambient illumination in the entire scene. Each ambient component is multiplied by the corresponding ambience component. Typically, all materials in a scene contain the same ambience color. 

<p>
</dl>

<dl>

<dt><tt><b>shiny</b></tt>
<dd>    The <a name=iBCGH></a><u>shinyness</u> factor is used in modes 2 and 3 to control the size of the highlight. It is also know as <a name=iBCGI></a><u>Phong exponent</u>. Larger numbers reduce the highlight size. 50.0 is a typical value for dull metals. 

<p>
</dl>

<dl>

<dt><tt><b>transp</b></tt>
<dd>    The <a name=iBCGJ></a><u>transparency</u> of the material. Transparency causes <a name=iBCHA></a><u>transparency</u> or <a name=iBCHB></a><u>refraction</u> rays to be cast, depending on whether <tt><b>ior</b></tt> is 1.0 or not, to determine the color of the next object ``behind'' the current one that can be seen through the material. 0.0 is fully opaque; 1.0 is fully transparent. The contribution of the material color is reduced by <i>1 - transp</i>. Transparency is evaluated after textures. 

<p>
</dl>

<dl>

<dt><tt><b>reflect</b></tt>
<dd>    The reflectivity of the material. Reflections are calculated by casting <a name=iBCHC></a><u>reflection</u> rays. 0.0 is nonreflecting, 1.0 is fully reflecting. The contribution of the material color and transparency is reduced by <i>1 - reflect</i>. Reflectivity is evaluated after textures and after transparency. 

<p>
</dl>

<dl>

<dt><tt><b>ior</b></tt>
<dd>    The <a name=iBCHD></a><u>index of refraction</u> is used if the object is transparent to determine the direction of the continuing ray. The index of refraction is typically set to 1.0 for air, 1.33 for water and 1.5 for glass. The material shader uses its inside/outside calculation<a name=iBCHE></a> to determine the refraction direction. 

<p>
</dl>

<dl>

<dt><tt><b>sblur</b></tt>
<dd>    This flag turns on <a name=iBCHF></a><u>static blur</u>ring, which increases the transparency proportionally to the angle between the incident ray and the normal. The effect fades the edges of an object, resulting in a glow effect. To achieve SOFTIMAGE compatibility, this should be used in conjunction with an expansion of the object by translating all vertices along their normals by a constant amount. This expansion can be performed by a translator or a displacement shader; a material shader has no control over geometry. There is a trivial displacement shader <a name=iBCHG></a><u><i>soft_staticblur</i></u> that returns a constant value given by its only argument, <i>width</i>. 

<p>
</dl>

<dl>

<dt><tt><b>sblurdecay</b></tt>
<dd>    If static blurring is enabled, this value controls the falloff of the static blur. 

<p>
</dl>

<dl>

<dt><tt><b>lights</b></tt>
<dd>    The light array lists the lights for which the diffuse and specular color contributions should be accumulated. If the shader is used as a shadow shader, the current shadow-casting light is looked up in the <a name=iBCHH></a><u>light list</u>, and the material is ignored if the light is not found. 

<p>
</dl>

<dl>

<dt><tt><b>difflights</b></tt>
<dd>    The diffuse light array lists more lights for which only the diffuse color contributions should be accumulated. Even if the <i>mode</i> indicates Phong (2) or Blinn (3) shading, these lights contribute only diffuse light. 

<p>
</dl>

<dl>

<dt><tt><b>texture</b></tt>
<dd>    SOFTIMAGE materials allow an arbitrary number of <a name=iBCHI></a><a href=scene.html#iDJA>texture</a>s that are layered ``on top of'' the base color computed from the ambient, diffuse, and specular colors and their factors.Future versions of mental ray  will replace the texture pointer with an array of size [1]. The alpha value of textures is taken into account for blending. Each texture comes with a number of parameters that describe the attributes of layering:<a name=iBCHJ></a> 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].map</b></tt>
<dd>    The map is the texture to look up. This can either be a procedural texture or an image texture. The SOFTIMAGE translator always stores a procedural texture (such as <i>soft_color</i>) here. The texture is given as a tag, which can be evaluated by calling <a name=iBCIA></a><a href=shaders.html#iBAEF><i>mi_call_shader</i></a>, which looks up the texture and returns the color at the proper location on the texture, or returns <tt><b>miFALSE</b></tt> if the texture does not apply. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].space</b></tt>
<dd>    Different textures can use different mappings, such as orthographic, spherical, or cylindrical projections. The <i>state<i>-&gt;</i>tex_list</i> contains an array of texture coordinates, one for each projection on this material. The <a name=iBCIB></a><a href=scene.html#iGJI>texture space</a> is an index into this array. When evaluating texture <i>i</i>, the material shader copies <i> </i> state<i>-&gt;</i>tex_list[paras<i>-&gt;</i>texture[i].space] into <i>state<i>-&gt;</i>tex</i> before evaluating the map, which is where the texture shader picks it up. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].mask</b></tt>
<dd>    Masking controls the blending method. If <tt><b>mask</b></tt> is 0, the texture is layered opaquely disregarding its alpha, <tt><b>mask</b></tt> 1 makes the texture transparent where its alpha is less than 1.0, and <tt><b>mask</b></tt> 2 does the same but uses the texture intensity instead of the texture alpha. The <tt><b>blend</b></tt> factor is multiplied by the result of this calculation. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].comp</b></tt>
<dd>    The <tt><b>comp</b></tt> flag selects whether the scalar mapping factors <tt><b> </b></tt> transp, <tt><b>reflect</b></tt>, and <tt><b>bump</b></tt> should be derived from the texture alpha (if <tt><b>comp</b></tt> is 1) or the texture intensity (if <tt><b> </b></tt> comp is 2). 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].method</b></tt>
<dd>    The original texture projection method selected in the texture menu:  0 for XY, 1 for YZ, 2 for XZ, 3 for UV, or 4 for cylindrical or spherical projections. The method number of 3D textures is 666. This variable does not control the mapping itself; mapping is controlled by texture vertices. It is used for the computation of bump basis vectors to ensure that the normal is perturbed in the correct direction depending on the projection. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].blend</b></tt>
<dd>    Blending reduces the effect of layering the texture. If <tt><b>blend</b></tt> is 0.0, the texture is ignored; if <tt><b>blend</b></tt> is 1.0, it is added opaquely, and values in between fade the texture. The <tt><b>mask</b></tt> parameter can be used to ``punch holes'' into the texture at places where it has a low alpha or a low intensity; <tt><b>blend</b></tt> is the global blending factor. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].ambient</b></tt>
<dd>    This factor adjusts the effect of the texture on the ambient component. It works like an additional blending factor that controls the ambient color only. 1.0 does not reduce ambient contribution, 0.0 turns it off. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].diffuse</b></tt>
<dd>    This factor does the same thing for the diffuse color. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].specular</b></tt>
<dd>    This factor does the same thing for the specular color. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].transp</b></tt>
<dd>    This factor does the same thing for transparency. In addition, negative values are allowed that in effect reverse the transparency map; transparent areas become opaque and vice versa. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].reflect</b></tt>
<dd>    This factor does the same thing for reflectivity. Negative values are also allowed. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].bump</b></tt>
<dd>    This factor does the same thing for <a name=iBCIC></a><u>bump map</u>ping. Negative values are also allowed; they effectively turn bumps into dents and vice versa. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].u_unit, texture[ ].v_unit</b></tt>
<dd>    Bump mapping is done by evaluating the texture three times, at the current location and a small distance above and to the right, and using the two differences to perturb the normal. The <tt><b>u_unit</b></tt> and <tt><b> </b></tt> v_unit parameters determine the distance in texture space, which ranges from <i>(0, 0)</i> in the lower left corner to <i>(1, 1)</i> in the upper right corner. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].u_wrap, texture[ ].v_wrap</b></tt>
<dd>    For bump mapping: if <tt><b>u + u_unit</b></tt> is outside the interval <i>[0,1)</i>, the texture lookup is dependent on <tt><b>u_wrap</b></tt>: If <tt><b> </b></tt> u_wrap is zero, the differences to perturb the normal are calculated to the left (below) at <tt><b>u - u_unit</b></tt>. If <tt><b>u_wrap</b></tt> is different from zero, texture wrapping is assumed and the lookup is performed at <tt><b>u + u_wrap</b></tt>.  The same procedure applies to the <tt><b>v_wrap</b></tt> parameter. 

<p>
</dl>

<dl>

<dt><tt><b>blackwhite</b></tt>
<dd>    This flag enables a mode where the transparency is set to 1.0 if the color returned by the texture map is either completely white or completely black (all three color components are either less than or equal to <i>0.004</i> or greater than or equal to <i>0.996</i>). 

<p>

<p>
</dl>
<br>
 <p><a name=cE><h3>soft_color</h3></a> 

<p><a name=iBCID></a><a name=iBCIE></a> (see <a href=scene.html#iDJD>texture shader</a>) <a name=iBCIF></a>This shader implements 2D textures. It works by calculating the <a name=iBCIG></a><a href=scene.html#iDJA>texture</a> coordinate and looking up an image texture. Standard SOFTIMAGE 2D textures are always evaluated in two stages, the first being a procedural texture shader, and the second being an image file. This shader implements the first stage. It can perform various cropping, scaling, rotation, and swapping operations. This is the .mi scene file declaration: 

<p><pre>
    declare "soft_color" (
        color texture   "texture",
        integer         "repu",
        integer         "repv",
        boolean         "altu",
        boolean         "altv",
        boolean         "swap",
        scalar          "minu",
        scalar          "maxu",
        scalar          "minv",
        scalar          "maxv",
        transform       "transform",
        boolean         "u_torus",
        boolean         "v_torus",
        integer         "method"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct soft_color {
        miTag       texture;      /* texture shader */
        miInteger   repu, repv;   /* repetition, &gt;= 1 */
        miBoolean   altu, altv;   /* flip alternates */
        miBoolean   swap;         /* swap U and V coords */
        miScalar    minu, maxu;   /* horizontal cropping */
        miScalar    minv, maxv;   /* vertical cropping */
        miMatrix    transform;    /* transformation */
        miBoolean   u_torus;      /* map is cyl/spherical */
        miBoolean   v_torus;      /* wrap V (patch only) */
        miInteger   method;       /* 0..5=XY, YZ, XZ, UV, */
                                  /* cyl/sphere, UV wrap */
    };
</pre>


<p>
<dl>

<dt><tt><b>texture</b></tt>
<dd>    The tag of the image texture that actually delivers the colors. The shader uses it to retrieve multiple colors for each sample, and filters them to a single result value. 

<p>
</dl>

<dl>

<dt><tt><b>repu, repv</b></tt>
<dd>    Repetition packs multiple copies of the image texture, after cropping, into the available space defined by the <tt><b>transform</b></tt> matrix. No repetition is done if both parameters are 1. <tt><b>repu</b></tt> controls repetition in the U parameter direction, and <tt><b>repv</b></tt> in the V direction. The UV parameter values are taken from the X and Y components of the texture coordinate <i>state<i>-&gt;</i>tex</i> and then transformed with <tt><b> </b></tt> transform. 

<p>
</dl>

<dl>

<dt><tt><b>altu, altv</b></tt>
<dd>    These flags control flipping of alternate tiles for repeating textures. If <tt><b>repu</b></tt> is greater than 1 and <tt><b>altu</b></tt> is <tt><b>miTRUE</b></tt>, every other copy of the texture is flipped horizontally. <tt><b>altv</b></tt> flips every other copy vertically. 

<p>
</dl>

<dl>

<dt><tt><b>swap</b></tt>
<dd>    This flag, if <tt><b>miTRUE</b></tt>, exchanges the U and V coordinates after transformation, before repetition and tiling. The result is a diagonal mirror. 

<p>
</dl>

<dl>

<dt><tt><b>minu, maxu, minv, maxv</b></tt>
<dd>    These parameters control <a name=iBCIH></a><u>texture cropping</u>. All four work in texture image space, with <i>(0, 0)</i> in the lower left corner and <i>(1, 1)</i> in the upper right corner. <tt><b>minu</b></tt> is the width of the left margin, <tt><b> </b></tt> 1 <i>- </i>maxu is the right margin, <tt><b>minv</b></tt> is the bottom margin, and <tt><b>1 <i>- </i>maxv</b></tt> is the top margin. The image is not cropped if <tt><b> </b></tt> minu<i>=</i>minv<i>= 0</i> and <tt><b>maxu<i>=</i>maxv<i>= 1</i></b></tt>. 

<p>
</dl>

<dl>

<dt><tt><b>transform</b></tt>
<dd>    The texture transformation matrix converts the texture coordinate <i> </i> state<i>-&gt;</i>tex to UV coordinates. As an optimization, the shader ignores the matrix if <i>matrix[15]</i> is 0. Transformation may result in areas on the surface where the object result in U or V coordinates less than 0 or greater than 1. If this is the case for the current sample, it is considered a ``<a name=iBCII></a><u>texture miss</u>'', and the shader returns <tt><b>miFALSE</b></tt>. The caller (usually the material shader) then ignores this texture. The torus flags provide exceptions to this rule. 

<p>
</dl>

<dl>

<dt><tt><b>u_torus, v_torus</b></tt>
<dd>    The rules for texture mapping have two exceptions controlled by these flags. First, spherical and cylindrical mappings cause the texture, if translated, to ``wrap around'' the U seam (where the U coordinate wraps from 1 back to 0). If <tt><b>u_torus</b></tt> is <tt><b>miTRUE</b></tt>, the shader performs this wrapping, rather than clipping the texture at the U=1 seam and leaving blank space at the U=0 seam.<a name=iBCIJ></a> This does not apply to the V direction. The second exception applies if the object is a closed patch. On closed patches, the texture always wraps around in the parameter directions the closing applies to, so either or both of <tt><b>u_torus</b></tt> and <tt><b> </b></tt> v_torus may be <tt><b>miTRUE</b></tt>. 

<p>
</dl>

<dl>

<dt><tt><b>method</b></tt>
<dd>    The original texture projection method selected in the texture menu:  0 for XY, 1 for YZ, 2 for XZ, 3 for UV, 4 for cylindrical or spherical projections, or 5 for UV with seamless wrapping. This is used by the <i>remap_parameters</i> subroutine of <i>soft_color</i> to check for UV coordinate mode (3 or 5), and use a different approach to finite repetition that emulates SOFTIMAGE UV texture mapping. 

<p>

<p>
</dl>
<br>
 <p><a name=cF><h3>soft_color_3d</h3></a> 

<p><a name=iBCJA></a><a name=iBCJB></a> (see <a href=scene.html#iDJD>texture shader</a>) 3D textures, like 2D textures, are based on texture coordinates as found in <i>state<i>-&gt;</i>tex</i>. However, 3D textures use all three texture coordinates X, Y, and Z, and compute the texture based on these coordinates without referring to a texture image. Three types of textures are supported: cloud, wood, and marble. Here is the .mi scene file declaration: 

<p><pre>
    declare "soft_color_3d" (
        integer         "seq",
        integer         "type",
        scalar          "spacing",
        scalar          "angle",
        scalar          "strength",
        scalar          "power",
        integer         "iteration",
        scalar          "weight1",
        scalar          "weight2",
        scalar          "weight3",
        color           "color0",
        color           "color1",
        color           "color2",
        color           "color3",
        color           "color4",
        transform       "transform"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct soft_color_3d {
        miInteger   seq;         /* unique seq. number */
        miInteger   type;        /* marble, wood, cloud */
        miScalar    spacing;     /* spacing (density) */
        miScalar    angle;       /* rotation */
        miScalar    strength;    /* amount of noise */
        miScalar    power;       /* deformation strength */
        miInteger   iteration;   /* polynomial order */
        miScalar    weight1;     /* color weights */
        miScalar    weight2;
        miScalar    weight3;
        miColor     color0;      /* 5-color color spread */
        miColor     color1;
        miColor     color2;
        miColor     color3;
        miColor     color4;
        miMatrix    transform;   /* xlate,scale,rotation */
    };
</pre>


<p>
<dl>

<dt><tt><b>seq</b></tt>
<dd>    Every instance of a 3D shader must have a unique sequential number. This number is used by the shader to uniquely identify the shading context, such that the interdependency of samples for one object can be maintained. Sequential numbers begin at 0. 

<p>
</dl>

<dl>

<dt><tt><b>type</b></tt>
<dd>    Three types are defined: 0 for marble, 1 for wood, and 2 for clouds. 

<p>
</dl>

<dl>

<dt><tt><b>spacing</b></tt>
<dd>    The spacing controls the distance between marble layers or wood grains. Valid values range from 0 to 10, the default is 1. Greater numbers decrease the distance. 

<p>
</dl>

<dl>

<dt><tt><b>angle</b></tt>
<dd>    This value rotates the texture. Valid values range from 0 to 45 degrees. (This field is the only one in mental ray that is defined in degrees, not radians.) 

<p>
</dl>

<dl>

<dt><tt><b>strength</b></tt>
<dd>    This parameter controls the amount of perturbation. Values range from 0 to 20, default is 1. Greater values increase the perturbation. 

<p>
</dl>

<dl>

<dt><tt><b>power</b></tt>
<dd>    If the iteration is sufficiently high, deforms the pattern in a way similar to strength, but at a ``macroscopic'' level. Values range from 0 to 20, the default is 0. 

<p>
</dl>

<dl>

<dt><tt><b>iteration</b></tt>
<dd>    The iteration controls the degree of the polynomial used to evaluate the texture. Valid values range from 1 to 8, default is 1. Higher values calculate more detail. 

<p>
</dl>

<dl>

<dt><tt><b>weight1, weight2, weight3</b></tt>
<dd>    The weights distribute the five colors. The five-color spread is distributed from one marble layer or wood cylinder to the next, on a range from 0 to 1. Color 0 is at 0, color 1 is at <tt><b>weight1</b></tt>, color 2 is at <tt><b>weight2</b></tt>, color 3 is at <tt><b>weight3</b></tt>, and color 4 is at 1. This means that the weights must be specified in increasing order: <tt><b>0 <i>&lt;= </i>weight1<i> &lt;= </i>weight2<i> &lt;= </i>weight3<i> &lt;= 1</i></b></tt>. 

<p>
</dl>

<dl>

<dt><tt><b>color0, color1, color2, color3, color4</b></tt>
<dd>    These colors define the five-color spread, as RGBA colors. 

<p>
</dl>

<dl>

<dt><tt><b>transform</b></tt>
<dd>    This transformation matrix is applied to the raw texture coordinate found in <i>state<i>-&gt;</i>tex</i> before the pattern is calculated. 

<p>

<p>
</dl>
<p><a name=cG><h3>soft_vertex_color</h3></a> 

<p><a name=iBCJC></a><a name=iBCJD></a> (see <a href=scene.html#iDJD>texture shader</a>) The vertex color shader is very simple. It interprets the XYZ texture coordinate components as an RGB color, sets alpha to 1.0 and returns. Together with a translator that stores colors instead of texture coordinates for this shader, this implements vertex coloring. No lookup or other computation is required, and no parameters are accepted: 

<p><pre>
    declare "soft_vertex_color" ()
</pre>


<p>

<p><p><a name=cH><h3>soft_vertex_color_alpha</h3></a> 

<p><a name=iBCJE></a><a name=iBCJF></a> (see <a href=scene.html#iDJD>texture shader</a>) This is a variation of the previous shader. It exists for Softimage compatibility and is not recommended for other uses. It interprets the XYZ texture vector as an RGB color in the value range <i>(0..255)</i>, instead of <i>(0..1)</i>, taking each integer modulo 255. Additionally, the X component of the texture vector, divided by 256 and taken modulo 255, is used to set the alpha component of the returned color. With this trick four color components are extracted from three vector components. No lookup or other computation is done, and no parameters are accepted: 

<p><pre>
    declare "soft_vertex_color_alpha" ()
</pre>


<p>

<p><br>
 <p><a name=cI><h3>soft_light</h3></a> 

<p><a name=iBCJG></a><a name=iBCJH></a> (see <a href=scene.html#iDHI>light shader</a>) This shader implements the infinite (directional) lights<a name=iBCJI></a>, <a name=iBCJJ></a><a href=shaders.html#iJGA>point light</a>s, and <a name=iBDAA></a><a href=shaders.html#iJGD>spot light</a>s supported by SOFTIMAGE. The behavior is controlled by a mode parameter.  Infinite lights use the light direction in the state, while point and spot lights use the origin in the state. Point and spot lights can have a distance <a name=iBDAB></a><u>attenuation</u>, causing the light intensity to fall off with distance. The only difference between point lights and spot lights is that spot lights offer angle attenuation, which implements the spot effect by emitting the lights along a spot direction axis with a programmable falloff depending on the angle to that axis. Spot lights do not use the direction in the state as a spot direction axis. 

<p>This is the .mi scene file declaration: 

<p><pre>
    declare "soft_light" (
        integer         "mode",
        color           "color",
        boolean         "shadow",
        scalar          "factor",
        boolean         "atten",
        scalar          "start",
        scalar          "stop",
        vector          "direction",
        scalar          "cone",
        scalar          "spread"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct soft_light {
        miInteger   mode;         /* 0=inf,1=point,2=spot */
        miColor     color;        /* color of light source*/
        miBoolean   shadow;       /* light casts shadows */
        miScalar    factor;       /* penetrate opaque objs*/
                                  /* --- point/spot only: */
        miBoolean   atten;        /* distance attenuation */
        miScalar    start, stop;  /* if atten, dist range */
                                  /* --- spot only: */
        miVector    direction;    /* spot direction */
        miScalar    cone;         /* inner solid cone */
        miScalar    spread;       /* outer fuzzy cone */
    };
</pre>


<p>
<dl>

<dt><tt><b>mode</b></tt>
<dd>    The mode controls the operation of the light: 0 selects an infinite (directional) light, 1 selects a point light, and 2 selects a spot light. 

<p>
</dl>

<dl>

<dt><tt><b>color</b></tt>
<dd>    The color of the light is an RGB color (no alpha) that specifies the color of the emitted light. If shadows are enabled using the <tt><b>shadow</b></tt> parameter, the shader casts shadow rays back towards the point to be illuminated in order to attenuate the light color depending on the <a name=iBDAC></a><a href=scene.html#iECC>shadow shader</a>s of occluding objects. Occluding objects may change the light color based on their transparency. The end result is returned by the light shader. 

<p>
</dl>

<dl>

<dt><tt><b>shadow</b></tt>
<dd>    If the <a name=iBDAD></a><u>shadow</u> flag is <tt><b>miTRUE</b></tt>, the light shader attempts to cast shadow rays back to the illuminated point as found in <i> </i> state<i>-&gt;</i>point, giving the shadow shaders of occluding objects a chance to attenuate the light color. If the global shadow flag for the entire scene is turned off, no shadow shaders will be called, regardless of the <tt><b>shadow</b></tt> parameter. 

<p>
</dl>

<dl>

<dt><tt><b>factor</b></tt>
<dd>    The <a name=iBDAE></a><u>shadow factor</u> provides a way to reduce the effect of occlusion by objects between the light and the illuminated point. If the shadow factor is greater than 0, it will blend the color reduced by the shadow shaders toward the light color. If the shadow factor is 1, no shadow rays are cast. The shadow factor can be seen as the degree to which the light can penetrate opaque shadow-casting objects. 

<p>
</dl>

<dl>

<dt><tt><b>atten</b></tt>
<dd>    This flag applies to point and spot lights only. It turns distance <a name=iBDAF></a><u>attenuation</u> on, based on the distance to the illuminated object as found in <i>state<i>-&gt;</i>dist</i> and the <tt><b>start</b></tt> and <tt><b> </b></tt> stop parameters. 

<p>
</dl>

<dl>

<dt><tt><b>start, stop</b></tt>
<dd>    If <tt><b>mode</b></tt> is 1 or 2, and if <tt><b>atten</b></tt> is <tt><b>miTRUE</b></tt>, these parameters bound the distance attenuation. If the distance is less than <tt><b>start</b></tt>, no attenuation takes place. If the distance is greater than <tt><b>stop</b></tt>, no light reaches the object, and a black color is returned. If the distance is beetween <tt><b>start</b></tt> and <tt><b>stop</b></tt>, the light color is faded to black in a linear way. Distance attenuation is applied before shadow rays are cast. 

<p>
</dl>

<dl>

<dt><tt><b>direction</b></tt>
<dd>    If the light is a spot light, the direction vector specifies the direction of maximum illumination, i.e., the direction the spot light is pointing. This must not be confused with the direction of a directional light, which is taken from <i>state<i>-&gt;</i>dir</i>. 

<p>
</dl>

<dl>

<dt><tt><b>cone</b></tt>
<dd>    If the light is a spot light, the cone value defines the radius of the cone around the <tt><b>direction</b></tt> axis in which the full light intensity is emitted without any angle <a name=iBDAG></a><u>attenuation</u>. The value is specified as the cosine of the angle. Angle attenuation is applied to the light color before shadow rays are cast. 

<p>
</dl>

<dl>

<dt><tt><b>spread</b></tt>
<dd>    If the light is a spot light, the spread value defines the radius of a cone around the <tt><b>direction</b></tt> axis outside of which no light is emitted at all. If the angle from the axis direction to the direction towards the illuminated point is greater than specified with <tt><b>spread</b></tt>, the light shader returns black; if the angle is less than specified by <tt><b>cone</b></tt>, no angle attenuation takes place. There is a linear falloff if the angle is between the angles determined by <tt><b>cone</b></tt> and <tt><b>spread</b></tt>. Like <tt><b>cone</b></tt>, <tt><b>spread</b></tt> must be set to the cosine of the desired angle. 

<p>
</dl>
<br>
 <p><a name=cJ><h3>soft_displace</h3></a> 

<p><a name=iBDAH></a><a name=iBDAI></a>The displacement shader is called once for every vertex generated by surface tesselation, and returns a value that specifies how far the vertex should be translated along its normal. The displacement shader derives this value from one or more textures, using a texture lookup much like the <i>soft_material</i> material shader. The scalar return value is derived from the RGBA result of the texture lookups in the same way and using the same parameters that the material shader uses to derive transparency, reflectivity, and bump intensity. Its parameters are declared in the .mi scene file as: 

<p><pre>
    declare "soft_displace" (
        array struct    "texture" {
            color texture   "map",
            integer         "space",
            integer         "comp",
            scalar          "displace"
        }
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct soft_displace {
        int           i_texture;   /* index of 1st texture*/
        int           n_texture;   /* number of textures */
        struct DisTex {
           miTag      map;         /* texture file */
           miInteger  space;       /* texture vertex space*/
           miInteger  comp;        /* 1=alpha,2=intens */
           miScalar   displace;    /* weight of texture */

        }             *texture;    /* list of textures */
    };
</pre>


<p>The parameters are evaluated once for each texture, and their results are added.Future versions of mental ray will replace the  texture pointer with an array of size [1].

<p>
<dl>

<dt><tt><b>texture[ ].map</b></tt>
<dd>    The map is the texture to look up. This can either be a procedural texture or an image texture. The SOFTIMAGE translator always stores a procedural texture (such as <i>soft_color</i>) here. The texture is given as a tag, which can be evaluated by calling <a name=iBDAJ></a><a href=shaders.html#iBAEF><i>mi_call_shader</i></a>, which looks up the texture and returns the color at the proper location on the texture, or returns <tt><b>miFALSE</b></tt> if the texture does not apply. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].space</b></tt>
<dd>    Different textures can use different mappings, such as orthographic, spherical, or cylindrical projections. The <i>state<i>-&gt;</i>tex_list</i> contains an array of texture coordinates, one for each projection on this material. The <a name=iBDBA></a><a href=scene.html#iGJI>texture space</a> is an index into this array. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].comp</b></tt>
<dd>    The <tt><b>comp</b></tt> flag selects whether the <tt><b>displace</b></tt> factor should be derived from the texture alpha (if <tt><b>comp</b></tt> is 1) or the texture intensity (if <tt><b>comp</b></tt> is 2). 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].displace</b></tt>
<dd>    This factor adjusts the effect of the texture on the returned value. 1.0 adds the full result from the texture lookup, 0.0 turns it off. Negative values invert the direction of the displacement. Values greater than 1.0 (or less than -1.0) magnify the effect. 

<p>
</dl>
<br>
 <p><a name=cBA><h3>soft_env_sphere</h3></a> 

<p><a name=iBDBB></a><a name=iBDBC></a> (see <a href=shaders.html#iHGE>environment shader</a>) Environment maps are called to evaluate the color returned by a primary or secondary ray that goes to infinity without hitting an object, or to evaluate the color of a reflected secondary ray quickly without checking for intersections with other objects. The second case is called a ``non-raytraced <a name=iBDBD></a><u>reflection map</u>'' in the SOFTIMAGE Creative Environment. 

<p>This shader works by assuming a sphere of infinite radius around the entire scene. One or more textures are mapped on this sphere, so that the color lookup operates in exactly the same way as texture lookups in the material and displacement shaders. The <i>soft_env_sphere</i> shader accepts the same types of arguments as these two shaders. Here are the .mi scene file declarations: 

<p><pre>
    declare "soft_env_sphere" (
        scalar          "rotate",
        array struct    "texture" {
            color texture   "map",
            integer         "mask",
            scalar          "blend"
        }
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct soft_env_sphere {
        miScalar      rotate;      /* global rotation */
        int           i_texture;   /* index of 1st texture*/
        int           n_texture;   /* number of textures */
        struct EnvTex {
           miTag      map;         /* texture file */
           miInteger  mask;        /* none, alpha, intens */
           miScalar   blend;       /* overall blending */
        }             *texture;    /* list of textures */
    };
</pre>


<p>
<dl>

<dt><tt><b>rotate</b></tt>
<dd>    This parameter, if nonzero, rotates the texture around the Y coordinate. 

<p>
</dl>
The following parameters are evaluated once for each texture, and their results are added.Future versions of mental ray will replace the  texture pointer with an array of size [1]. Note the similarity to the material and displacement shader parameters. No texture coordinates, and hence no <tt><b>space</b></tt> parameter, are required because the sphere is always mapped spherically. 

<p>
<dl>

<dt><tt><b>texture[ ].map</b></tt>
<dd>    The map is the texture to look up. This can either be a procedural texture or an image texture. The SOFTIMAGE translator always stores a procedural texture (such as <i>soft_color</i>) here. The texture is given as a tag, which can be evaluated by calling <a name=iBDBE></a><a href=shaders.html#iBAEF><i>mi_call_shader</i></a>. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].mask</b></tt>
<dd>    Masking controls the blending method. If <tt><b>mask</b></tt> is 0, the texture is layered opaquely disregarding its alpha, <tt><b>mask</b></tt> 1 makes the texture transparent where its alpha is less than 1.0, and <tt><b>mask</b></tt> 2 does the same but uses the texture intensity instead of the texture alpha. The <tt><b>blend</b></tt> factor is multiplied by the result of this calculation. 

<p>
</dl>

<dl>

<dt><tt><b>texture[ ].blend</b></tt>
<dd>    Blending reduces the effect of layering the texture. If <tt><b>blend</b></tt> is 0.0, the texture is ignored; if <tt><b>blend</b></tt> is 1.0, it is added opaquely, and values in between fade the texture. The <tt><b>mask</b></tt> parameter can be used to ``punch holes'' into the texture at places where it has a low alpha or a low intensity; <tt><b>blend</b></tt> is the global blending factor. 

<p>
</dl>
<br>
 <p><a name=cBB><h3>soft_fog</h3></a> 

<p><a name=iBDBF></a><a name=iBDBG></a> (see <a href=shaders.html#iHGA>volume shader</a>) <a name=iBDBH></a> (see <a href=shaders.html#iJCI>fog</a>) <a name=iBDBI></a> (see <a href=shaders.html#iJCJ>atmosphere</a>) The fog shader is a volume shader that implements simple distance-based fog. Whenever a visible or light ray is cast, the resulting color is modified by the fog shader based on the distance the ray travelled, as found in <i>state<i>-&gt;</i>dist</i>, by fading the color towards a fog color.  The camera is considered to be surrounded by spherically shaped layer of fog whose inner radius is the start distance and whose outer layer is the end distance. The <a name=iBDBJ></a><u>attenuation</u> is a linear function of the distance traveled through this fog.  This is the .mi scene file declaration: 

<p><pre>
    declare "soft_fog" (
        scalar          "start",
        scalar          "stop",
        scalar          "rate",
        color           "transmit",
        boolean         "lightrays"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct soft_fog {
        miScalar        start, stop;
        miScalar        rate;
        miColor         transmit;
        miBoolean       lightrays;
    };
</pre>


<p>
<dl>

<dt><tt><b>start, stop</b></tt>
<dd>    These parameters specify the distance where the fog begins and where it is totally opaque. Between these distances, the fog density is linearly interpolated between totally transparent (at <tt><b>start</b></tt>) to totally opaque as defined by <tt><b>rate</b></tt> (at <tt><b>stop</b></tt>). 

<p>
</dl>

<dl>

<dt><tt><b>rate</b></tt>
<dd>    The rate allows to adjusts the maximum density of the fog. If <tt><b>rate</b></tt> is 0.0, the fog becomes totally opaque at <tt><b>stop</b></tt>; values between 0.0 and 1.0 reduce the maximum opacity. 

<p>
</dl>

<dl>

<dt><tt><b>transmit</b></tt>
<dd>    The color of the fog that ray colors are faded towards. 

<p>
</dl>

<dl>

<dt><tt><b>lightrays</b></tt>
<dd>    This flag controls whether light rays are also attenuated by fog. If it is <tt><b>miTRUE</b></tt>, light <a name=iBDCA></a><u>illumination</u> is subject to fog <a name=iBDCB></a><u>attenuation</u>; if it is <tt><b>miFALSE</b></tt>, lights can illuminate objects at any distance regardless of fog. 

<p>
</dl>
<br>
 <p><a name=cBC><h3>soft_layered_fog</h3></a> 

<p><a name=iBDCC></a><a name=iBDCD></a> (see <a href=shaders.html#iHGA>volume shader</a>) <a name=iBDCE></a> (see <a href=shaders.html#iJCI>fog</a>) <a name=iBDCF></a><a name=iBDCG></a> (see <a href=shaders.html#iJCJ>atmosphere</a>) This shader attempts to emulate the SOFTIMAGE layered fog shader while trying to avoid its problems. A layer of fog with a vertical extent in world space is simulated. The density of the fog is given by a Poisson distribution (numerically given) that is centered around half the fog layer's height, and drops to half of the maximum value at the edges. In addition to the vertical extent of the layer, the volume filled with fog can be specified by giving a start and a stop distance along the ray, which correspond to the ray entering and leaving the volume. To turn this distance clipping off, a starting distance of 0.0 and a very large ending distance such as 10000.0 should be chosen. 

<p>Note that distance clipping emulates a peculiarity of the SOFTIMAGE layered-fog shader: it only works correctly for <a name=iBDCH></a><u>primary rays</u>; <a name=iBDCI></a><a href=shaders.html#iHJI>secondary ray</a>s such as reflected or refracted rays are treated as if they originated at the camera. The immediate effect is that, for start distances greater than 0.0, the first segment of the length as given by the start parameter of secondary rays is not affected by fog, even if the ray originates in the middle of the fog layer. 

<p>Here is the .mi scene file declaration: 

<p><pre>
    declare "soft_layered_fog" (
        scalar          "start",
        scalar          "stop",
        scalar          "base",
        scalar          "thickness",
        scalar          "density",
        color           "fogcolor",
        boolean         "lightrays"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct soft_layered_fog {
        miScalar        start, stop;
        miScalar        base;
        miScalar        thickness;
        miScalar        density;
        miColor         fogcolor;
        miBoolean       lightrays;
    };
</pre>


<p>
<dl>

<dt><tt><b>start, stop</b></tt>
<dd>    These parameters specify the distance where the fog begins and where it ends. Fog appears only between these two distances. 

<p>
</dl>

<dl>

<dt><tt><b>base</b></tt>
<dd>    The base is the Y coordinate of the bottom edge of the fog in world space. There will be no fog below this base height. 

<p>
</dl>

<dl>

<dt><tt><b>thickness</b></tt>
<dd>    The height of the fog layer above the base height. Fog will be visible between the Y coordinates <i>base</i> and <i>base + thickness</i> in world space. In this range, the density of the fog follows a Poisson distribution with a maximum at <i>base + 0.5 *thickness</i>, falling off to one half of the maximum density at <i>base</i> and <i>base + thickness</i>. 

<p>
</dl>

<dl>

<dt><tt><b>density</b></tt>
<dd>    The fog density is multiplied by this factor. No fog appears if the density is 0.0. Typical values range between 0.0 and 1.0. 

<p>
</dl>

<dl>

<dt><tt><b>fogcolor</b></tt>
<dd>    The color of the fog that ray colors are faded towards. 

<p>
</dl>

<dl>

<dt><tt><b>lightrays</b></tt>
<dd>    This flag controls whether light rays are also attenuated by fog. If it is <tt><b>miTRUE</b></tt>, light <a name=iBDCJ></a><u>illumination</u> is subject to fog <a name=iBDDA></a><u>attenuation</u>; if it is <tt><b>miFALSE</b></tt>, lights can illuminate objects at any distance regardless of fog. 

<p>
</dl>
<br>
 <p><a name=cBD><h3>lens_depth_of_field</h3></a> 

<p><a name=iBDDB></a><a name=iBDDC></a><a name=iBDDD></a> (see <a href=shaders.html#iHGG>lens shader</a>) This lens shader implements depth of field by defining a focus plane parallel to the viewing plane, and a lens size as a radius. Depth-of-field blurring is performed using adaptive distribution ray tracing, by varying the camera ray origin over a disc centered at the camera with a specified radius, while also adjusting the ray direction such that it always passes through the original point at the focus plane. The effect is that there is no difference for objects at the focus plane, but objects closer or farther away are seen at jittered angles. Adaptive sampling is used to anti-alias the result by taking multiple samples for such points. The sample locations and directions are chosen using a <a name=iBDDE></a><a href=functionality.html#iCAJ>Monte Carlo</a> or <a name=iBDDF></a><a href=functionality.html#iCBA>Quasi-Monte Carlo</a> algorithm, depending on the <tt><b>-mc</b></tt> or <tt><b>-qmc</b></tt> command-line options. The .mi scene file declaration is: 

<p><pre>
    declare "lens_depth_of_field" (
        scalar          "plane",
        scalar          "radius"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct lens_depth_of_field {
        miScalar        plane;
        miScalar        radius;
    };
</pre>


<p>
<dl>

<dt><tt><b>plane</b></tt>
<dd>    The negative distance of the focus plane from the camera. It may not be greater than or equal to 0.0. Since the scene is defined in camera space, the <tt><b>plane</b></tt> parameter is essentially the Z coordinate of a plane normal to the Z axis; the camera always looks down the negative Z axis. 

<p>
</dl>

<dl>

<dt><tt><b>radius</b></tt>
<dd>    The radius of the disc centered at the camera, parallel to the focus plane. A value of 0.0 turns off depth of field; values greater than 0.0 increase the depth-of-field effect. 

<p>
</dl>
<br>
 <p><a name=cBE><h3>out_depth_of_field</h3></a> 

<p><a name=iBDDG></a><a name=iBDDH></a><a name=iBDDI></a> (see <a href=shaders.html#iHGH>output shader</a>) This output shader implements depth of field by defining a a near and a far focus plane parallel to the viewing plane, and a lens size as a radius. All objects between the focus planes are in focus; objects outside this range are blurred. Unlike <i>lens_depth_of_field</i>, this shader computes the depth-of-field effect as a postprocessing step, using information collected during rendering. The shader must be installed in the <tt><b>view</b></tt> using an <tt><b>output</b></tt> statement, listed before the <tt><b>output</b></tt> statement that writes the image to a file: 

<p><pre>
     output "z,rgba" "out_depth_of_field" (...)
</pre>


<p>The .mi scene file declaration is: 

<p><pre>
    declare "out_depth_of_field" (
        scalar          "near",
        scalar          "far",
        scalar          "radius",
        integer         "max",
        scalar          "infinity"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct out_depth_of_field {
        miScalar        near;
        miScalar        far;
        miScalar        radius;
        miInteger       max;
        miScalar        infinity;
    };
</pre>


<p>
<dl>

<dt><tt><b>near</b></tt>
<dd>    The distance of the near focus plane from the camera. It may not be equal to 0.0. For compatibility with <i>lens_depth_of_field</i>, <i>near</i>, <i>far</i>, and <i>infinity</i> can bei either given as positive distances or negative Z coordinates; the absolute value is used. 

<p>
</dl>

<dl>

<dt><tt><b>far</b></tt>
<dd>    The distance of the far focus plane from the camera. Its absolute value must be equal to or greater than the absolute value of <i>near</i>. Points whose Z coordinate is between <i>near</i> and <i>far</i> are in focus, all others are blurred. 

<p>
</dl>

<dl>

<dt><tt><b>radius</b></tt>
<dd>    The radius of the disc centered at the camera, parallel to the focus plane. A value of 0.0 turns off depth of field; values greater than 0.0 increase the depth-of-field effect. 

<p>
</dl>

<dl>

<dt><tt><b>max</b></tt>
<dd>    Cutoff value for the radius of the filter, in pixels. The filter size depends on the distance of objects; this value allows to avoid very large filter sizes that make no visible difference to the effect. 

<p>
</dl>

<dl>

<dt><tt><b>infinity</b></tt>
<dd>    Reserved for internal use. 

<p>
</dl>
Note that this output shader, as opposed to the lens depth-of-field shader, is a fast and smooth, but not physically correct simulation of depth of field. In particular, it only uses the depth of the frontmost object to decide how much to blur. A glass window in front of the scene will cause incorrect blurring. 

<p><br>
 <p><a name=cBF><h3>soft_shadow</h3></a> 

<p><a name=iBDDJ></a><a name=iBDEA></a> (see <a href=scene.html#iECC>shadow shader</a>) This shader is obsolete. mental ray 1.8 and higher use the material shader as shadow shader, which avoids the need to duplicate the texture parameter block for a separate shadow shader. The shadow shader still exists for backwards compatibility reasons, in order to be able to read .mi scene files created before the change. It is strongly recommended to not use this shader in new develeopments. 

<p>The name <tt><b>soft_shadow</b></tt> indicates a SOFTIMAGE shadow shader and should not be confused with a mechanism generating soft shadows. 

<p>The parameter declaration in the .mi scene file and the C structure are identical to the parameter declarations of the <i>soft_material</i> shader. The <i>soft_shadow</i> shader does nothing but call <tt><b> </b></tt> soft_material. 

<p>

<p><p><a name=cBG><h3>soft_infinite</h3></a> 

<p><a name=iBDEB></a><a name=iBDEC></a> (see <a href=scene.html#iDHI>light shader</a>) <a name=iBDED></a>This shader has been replaced with the <i>soft_light</i> shader described above. It only exists for backwards compatibility with old .mi scene files. It has a declaration and a C data structure that differs slightly in layout from the parameter declaration of <tt><b> </b></tt> soft_light; the shader itself copies the parameter structure, selects an appropriate <tt><b>mode</b></tt>, and calls <i>soft_light</i>. The declaration in .mi scene files is: 

<p><pre>
    declare "soft_infinite" (
        color           "color",
        vector          "null",
        boolean         "shadow",
        scalar          "factor"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct soft_infinite {
        miColor     color;     /* color of light source */
        miVector    null;      /* spot has dir vector here*/
        miBoolean   shadow;    /* light casts shadows */
        miScalar    factor;    /* penetrate opaque objects*/
    };
</pre>


<p>For a description of these parameters, see <i>soft_light</i>. 

<p>

<p><p><a name=cBH><h3>soft_point</h3></a> 

<p><a name=iBDEE></a><a name=iBDEF></a> (see <a href=scene.html#iDHI>light shader</a>) <a name=iBDEG></a> (see <a href=shaders.html#iJGA>point light</a>) This shader has also been replaced with the <i>soft_light</i> shader. It only exists for backwards compatibility with old .mi scene files. It has a declaration and a C data structure that differs slightly in layout from the parameter declaration of <tt><b>soft_light</b></tt>; the shader itself copies the parameter structure, selects an appropriate <tt><b>mode</b></tt>, and calls <i>soft_light</i>. The declaration in .mi scene files is: 

<p><pre>
    declare "soft_point" (
        color           "color",
        vector          "null",
        boolean         "shadow",
        scalar          "factor",
        boolean         "atten",
        scalar          "start",
        scalar          "stop"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct soft_point {
        miColor     color;       /* color of light source */
        miVector    null;        /* spot has dir vec here */
        miBoolean   shadow;      /* light casts shadows */
        miScalar    factor;      /* penetrate opaque objs */
        miBoolean   atten;       /* distance attenuation */
        miScalar    start, stop; /* if atten, dist range */
    };
</pre>


<p>For a description of these parameters, see <i>soft_light</i>. 

<p><p><a name=cBI><h3>soft_spot</h3></a> 

<p><a name=iBDEH></a><a name=iBDEI></a> (see <a href=scene.html#iDHI>light shader</a>) <a name=iBDEJ></a> (see <a href=shaders.html#iJGA>point light</a>) This is yet another light shader that has been replaced with the <tt><b> </b></tt> soft_light shader. It is also obsolete and only exists for backwards compatibility with old .mi scene files. It has a declaration and a C data structure that differs slightly in layout from the parameter declaration of <i>soft_light</i>; the shader itself copies the parameter structure, selects an appropriate <tt><b>mode</b></tt>, and calls <i>soft_light</i>. The declaration in .mi scene files is: 

<p><pre>
    declare "soft_spot" (
        color           "color",
        vector          "direction",
        boolean         "shadow",
        scalar          "factor",
        boolean         "atten",
        scalar          "start",
        scalar          "stop",
        scalar          "cone",
        scalar          "spread"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct soft_spot {
        miColor     color;       /* color of light source */
        miVector    direction;   /* spot direction */
        miBoolean   shadow;      /* light casts shadows */
        miScalar    factor;      /* penetrate opaque objs */
        miBoolean   atten;       /* distance attenuation */
        miScalar    start, stop; /* if atten, dist range */
        miScalar    cone;        /* inner solid cone */
        miScalar    spread;      /* outer fuzzy cone */
    };
</pre>


<p>For a description of these parameters, see <i>soft_light</i>. 

<p>

<p><br>
 <p><a name=cBJ><h2>Wavefront Shaders</h2></a> 

<p>Seven shaders implement Wavefront compatibility. The material shader is controlled by a illumination mode parameter that controls which shading model is desired. Note that Wavefront shader do not deal with the <a name=iBDFA></a><u>alpha channel</u>; all alpha components are ignored and none are computed, with one exception: the <tt><b>mi_wave_material</b></tt> shader always returns an alpha of 1.0. This makes sure that a legal alpha channel is written to image files that contain an alpha channel. 

<p><a name=iBDFB></a>
<p><pre> <i>name</i>                   <i>operation</i> 
 <hr>
 <tt><b>mi_wave_material</b></tt>       material shader: all shading models 
 <tt><b>mi_wave_scalar_texture</b></tt> scalar texture shader 
 <tt><b>mi_wave_vector_texture</b></tt> vector texture shader 
 <tt><b>mi_wave_color_texture</b></tt>  color texture shader 
 <tt><b>mi_wave_light</b></tt>          light shader: point, infinite, spot 
 <tt><b>mi_wave_shadow</b></tt>         shadow shader 
 <tt><b>mi_wave_reflection_map</b></tt> environment shader 
 <hr>
 
</pre><p> 

<p>If any of these shaders is used in a .mi scene file, the scene file must include the <tt><b>wavefront.mi</b></tt> header file that contains the shader declarations, using a <tt><b>$include</b></tt> command<a name=iBDFC></a> (see <a href=scene.html#iDEG>include command</a>) . The C structures are declared in a file <a name=iBDFD></a><u><tt><b> mi_wavefront.h</b></tt></u>, to be included in the C source file of custom shaders making direct calls to Wavefront shaders. 

<p> <p><a name=cCA><h3>mi_wave_material</h3></a> 

<p><a name=iBDFE></a><a name=iBDFF></a> (see <a href=scene.html#iDJH>material shader</a>) <a name=iBDFG></a><a name=iBDFH></a><a name=iBDFI></a><a name=iBDFJ></a><a name=iBDGA></a> (see <a href=builtin.html#iBDFB>Wavefront shaders</a>) The material shader implements the Wavefront shading models 0 through 9. Illumination model 0 gives the surface a uniform color equal to the diffuse color.  The illumination of a surface with this <a name=iBDGB></a><a href=scene.html#iDJG>material</a> is computed according to 

<p>
<p><center> k<sub>d</sub><br>
.
</center><p>
 

<p>Model 1 is purely diffuse.<a name=iBDGC></a> The illumination of a surface with this material is computed according to 

<p>
<p><center> k<sub>a</sub> + k<sub>d</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,L<sub>i</sub>&gt; I<sub>i</sub><br>
.
</center><p>
 

<p>Model 2 includes both diffuse<a name=iBDGD></a> and specular <a name=iBDGE></a>components.  The illumination of a surface with this <a name=iBDGF></a><a href=scene.html#iDJG>material</a> is computed using <a name=iBDGG></a><u>Phong shading</u> according to 

<p>
<p><center> k<sub>a</sub> + k<sub>d</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,L<sub>i</sub>&gt; I<sub>i</sub><br>
+ k<sub>s</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,H<sub>i</sub>&gt;<sup>n<sub>s</sub></sup> I<sub>i</sub><br>
.
</center><p>
 

<p>In addition to diffuse and specular components (<a name=iBDGH></a><u>Phong shading</u>), model 3 includes the illumination contributed by <a name=iBDGI></a><u>reflection</u>s or <a name=iBDGJ></a><a href=builtin.html#iBDBD>reflection map</a>ping.  The illumination of a surface with this <a name=iBDHA></a><a href=scene.html#iDJG>material</a> is computed according to 

<p>
<p><center> k<sub>a</sub> + k<sub>d</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,L<sub>i</sub>&gt; I<sub>i</sub><br>
+ k<sub>s</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,H<sub>i</sub>&gt;<sup>n<sub>s</sub></sup> I<sub>i</sub><br>
+ k<sub>s</sub> I<sub>r</sub><br>
.
</center><p>
 

<p>Model 4 is similar to model 3 but is more suitable for a simulation of glass where the <a name=iBDHB></a><u>transparency</u> is nearly 1.0, but the highlights should not be affected (should not fade out, as they would with model 3).  The illumination of a surface with this material is computed according to 

<p>
<p><center> k<sub>a</sub> + k<sub>d</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,L<sub>i</sub>&gt; I<sub>i</sub><br>
+ k<sub>s</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,H<sub>i</sub>&gt;<sup>n<sub>s</sub></sup> I<sub>i</sub><br>
+ k<sub>s</sub> (1.0 + (d /1.0 - d - 1.0) / 5.0) I<sub>r</sub><br>
.
</center><p>
 

<p>Model 5 is similar to model 3 but with <a name=iBDHC></a><u>Fresnel</u> calculation of reflected<a name=iBDHD></a> light.  The illumination of a surface with this <a name=iBDHE></a><a href=scene.html#iDJG>material</a> is computed according to 

<p>
<p><center> k<sub>a</sub> + k<sub>d</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,L<sub>i</sub>&gt; I<sub>i</sub><br>
+ k<sub>s</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,H<sub>i</sub>&gt;<sup>n<sub>s</sub></sup> f(&lt;L<sub>i</sub>,H<sub>i</sub>&gt;,k<sub>s</sub>,n<sub>s</sub>) I<sub>i</sub><br>
+ k<sub>s</sub> f(&lt;N,V&gt;,k<sub>s</sub>,n<sub>s</sub>) I<sub>r</sub><br>
.
</center><p>
 

<p>In addition to diffuse, specular and <a name=iBDHF></a><u>reflection</u> contributions, model 6 includes refracted light similar to the calculation used by <a name=iBDHG></a><u>Whitted</u>.<a name=iBDHH></a> Note that the distance the ray travels through the material is not taken into account.  See also [Whitted 80].  The illumination of a surface with this material is computed according to 

<p>
<p><center> k<sub>a</sub> + k<sub>d</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,L<sub>i</sub>&gt; I<sub>i</sub><br>
+ k<sub>s</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,H<sub>i</sub>&gt;<sup>n<sub>s</sub></sup> I<sub>i</sub><br>
+ k<sub>s</sub> I<sub>r</sub><br>
+ (1.0 - k<sub>s</sub>) f<sub>t</sub> I<sub>t</sub><br>
.
</center><p>
 

<p>Model 7 is the same as model 6 but with <a name=iBDHI></a><u>Fresnel</u> calculation of <a name=iBDHJ></a>reflected and <a name=iBDIA></a>refracted color.  The illumination of a surface with this <a name=iBDIB></a><a href=scene.html#iDJG>material</a> is computed according to 

<p>
<p><center> k<sub>a</sub> + k<sub>d</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,L<sub>i</sub>&gt; I<sub>i</sub><br>
+ k<sub>s</sub> Sum<sub>i=0</sub><sup>n-1</sup> &lt;N,H<sub>i</sub>&gt;<sup>n<sub>s</sub></sup> f(&lt;L<sub>i</sub>,H<sub>i</sub>&gt;,k<sub>s</sub>,n<sub>s</sub>) I<sub>i</sub><br>
+ k<sub>s</sub> f(&lt;N,V&gt;,k<sub>s</sub>,n<sub>s</sub>) I<sub>r</sub><br>

</center><p>
 
<p><center>     + (1.0 - k<sub>s</sub>) f(&lt;N,V&gt;,1.0-k<sub>s</sub>,n<sub>s</sub>) f<sub>t</sub> I<sub>t</sub><br>
.
</center><p>
 

<p>Models 8 and 9 are identical to 3 and 4, respectively, except that the contribution from reflected illumination can only come from a <a name=iBDIC></a><a href=builtin.html#iBDBD>reflection map</a>, not from reflected rays.  This is useful to improve performance.<a name=iBDID></a> (see <a href=scene.html#iDJH>material shader</a>)  

<p>The material shader has the following .mi scene file declaration: 

<p><pre>
    declare "wave_material" (
        integer         "illum",
        color           "ambient",
        color           "diffuse",
        color           "specular",
        color           "transmit",
        scalar          "dissolve",
        scalar          "ns",
        scalar          "ni",
        color texture   "ambient_map",
        color texture   "diffuse_map",
        color texture   "specular_map",
        scalar texture  "dissolve_map",
        scalar texture  "ns_map",
        vector texture  "bump_map",
        array light     "lights",
        boolean         "use_reflectivity",
        color           "reflect"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct wave_material {
        miInteger illum;
        miColor   ambient;
        miColor   diffuse;
        miColor   specular;
        miColor   transmit;
        miScalar  dissolve;
        miScalar  ns;
        miScalar  ni;
        miTag     ambient_map;
        miTag     diffuse_map;
        miTag     specular_map;
        miTag     dissolve_map;
        miTag     ns_map;
        miTag     bump_map;
        int       i_lights;
        int       n_lights;
        miTag     *lights;
        miBoolean use_reflectivity;
        miColor   reflect;
    };
</pre>


<p>If one of the texture maps is defined, the shader requires exactly one set of texture coordinates, plus a set of <a name=iBDIE></a><u>bump basis vectors</u> if a <a name=iBDIF></a><u>bump map</u>, in the state. 

<p> 
<dl>

<dt><tt><b>illum</b></tt>
<dd>    This integer selects the <a name=iBDIG></a><u>shading model</u> of the material as described above. 

<p>
</dl>

<dl>

<dt><tt><b>ambient</b></tt>
<dd>    The <a name=iBDIH></a><u>ambient color</u> of the material that is always added, regardless of the illumination, in modes other than 0. It is ignored in mode 0. This and the next three colors are RGB colors, alpha is ignored. 

<p>
</dl>

<dl>

<dt><tt><b>diffuse</b></tt>
<dd>    The <a name=iBDII></a><u>diffuse color</u> of the material. It determines the color of the material in mode 0. In all other modes, it is added to the material color after multiplication with a factor depending on the <a name=iBDIJ></a><u>illumination</u> direction and the normal, evaluated once for each light. 

<p>
</dl>

<dl>

<dt><tt><b>specular</b></tt>
<dd>    The <a name=iBDJA></a><u>specular color</u> is the color of diffuse specular highlights. 

<p>
</dl>

<dl>

<dt><tt><b>transp</b></tt>
<dd>    The amount of light transmitted by the material; basically, the amount of <a name=iBDJB></a><u>transparency</u> for each of the R, G, and B components. This takes the index of refraction into account and uses mental ray's <a name=iBDJC></a><u>refraction</u> feature. 

<p>
</dl>

<dl>

<dt><tt><b>dissolve</b></tt>
<dd>    Dissolve<a name=iBDJD></a> (see <a href=builtin.html#iBCCI>dissolve</a>)  is an non-physical effect that fades or blends the object out of the scene. The index of refraction is not taken into account. This is basically a switcher effect. It uses mental ray's <a name=iBDJE></a><u>transparency</u> feature. 

<p>
</dl>

<dl>

<dt><tt><b>ns</b></tt>
<dd>    The <a name=iBDJF></a><u>shinyness</u> factor, which is used in Phong and Fresnel calculations to control the size of the highlight. It is also know as <a name=iBDJG></a><u>Phong exponent</u>. Larger numbers reduce the highlight size. 50.0 is a typical value for dull metals. 

<p>
</dl>

<dl>

<dt><tt><b>ni</b></tt>
<dd>    The <a name=iBDJH></a><u>index of refraction</u> of the material. It is used if the object is transparent (<tt><b>transp</b></tt> is not <i>(0, 0, 0)</i>) to determine the direction of the continuing ray. The index of refraction is typically set to 1.0 for air, 1.33 for water and 1.5 for glass. No inside/outside calculation<a name=iBDJI></a> is done to reverse the effect when an object is exited. 

<p>
</dl>

<dl>

<dt><tt><b>ambient_map</b></tt>
<dd>    If this parameter is nonzero, the <a name=iBDJJ></a><u>ambient color</u> is taken from this color texture map. 

<p>
</dl>

<dl>

<dt><tt><b>diffuse_map</b></tt>
<dd>    If this parameter is nonzero, the <a name=iBEAA></a><u>diffuse color</u> is taken from this color texture map. 

<p>
</dl>

<dl>

<dt><tt><b>specular_map</b></tt>
<dd>    If this parameter is nonzero, the <a name=iBEAB></a><u>specular color</u> is taken from this color texture map. 

<p>
</dl>

<dl>

<dt><tt><b>dissolve_map</b></tt>
<dd>    If this parameter is nonzero, the <a name=iBEAC></a><a href=builtin.html#iBCCI>dissolve</a> parameter that fades the object is taken from this scalar texture map. 

<p>
</dl>

<dl>

<dt><tt><b>ns_map</b></tt>
<dd>    If this parameter is nonzero, the <a name=iBEAD></a><u>shinyness</u> scalar that controls the highlight size is taken from this scalar texture map. 

<p>
</dl>

<dl>

<dt><tt><b>bump_map</b></tt>
<dd>    If this parameter is nonzero, a <a name=iBEAE></a><u>bump map</u> is applied to the object by performing a vector texture lookup and perturbing the surface <a name=iBEAF></a><u>normal</u> according to the <a name=iBEAG></a><u>bump basis vectors</u>. 

<p>
</dl>

<dl>

<dt><tt><b>lights</b></tt>
<dd>    The light array lists the lights for which the diffuse and specular color contributions should be taken into account.Future versions  of mental ray may replace the light pointer with an array of size [1].

<p>
</dl>

<dl>

<dt><tt><b>use_reflectivity</b></tt>
<dd>    If this parameter is zero, the strength <a name=iBEAH></a><u>reflection</u>s is determined by the <tt><b>specular</b></tt> or <tt><b>specular_map</b></tt> parameters. That is, the color of the reflected objects is multiplied by the specular color. If the <tt><b>use_reflectivity</b></tt> parameter is nonzero, the color of the reflected object is multiplied by the <tt><b>reflect</b></tt> color instead, thus allowing to specify reflectivity independently of diffuse specular highlights. 

<p>
</dl>

<dl>

<dt><tt><b>reflect</b></tt>
<dd>    If <tt><b>use_reflectivity</b></tt> is nonzero, the color of reflected objects is multiplied by this color. If it is black <i>(0, 0, 0)</i>, no reflection rays are cast. 

<p>

<p>
</dl>
<br>
 <p><a name=cCB><h3>mi_wave_scalar_texture</h3></a> 

<p><a name=iBEAI></a><a name=iBEAJ></a> (see <a href=scene.html#iDJD>texture shader</a>) This shader implements a texture lookup function for scalar textures. Scalar textures are used for mapping the <a name=iBEBA></a><a href=builtin.html#iBCCI>dissolve</a> and <a name=iBEBB></a><u>shinyness</u> parameters in the material. The shader requires a scalar texture image, it does not extract alpha or intensity from a color image. This is the .mi scene file declaration: 

<p><pre>
    declare "wave_scalar_texture" (
        scalar texture  "tex",
        vector          "origin",
        vector          "scale",
        scalar          "base",
        scalar          "gain"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct wave_scalar_texture {
        miTag           tex;
        miVector        origin;
        miVector        scale;
        miScalar        base;
        miScalar        gain;
    };
</pre>


<p>
<dl>

<dt><tt><b>tex</b></tt>
<dd>    The scalar texture to look up with the texture coordinate <i> </i> state<i>-&gt;</i>tex after the scale and origin parameters were applied. The scalar texture is evaluated at the point <i>(state-&gt;tex /scale - origin</i>). 

<p>
</dl>

<dl>

<dt><tt><b>origin</b></tt>
<dd>    This parameter specifies the origin in the texture, effectively shifting the texture down and to the left for positive origin values. 

<p>
</dl>

<dl>

<dt><tt><b>scale</b></tt>
<dd>    Scaling changes the size of the texture. Values greater than 1.0 reduce the size. 

<p>
</dl>

<dl>

<dt><tt><b>base</b></tt>
<dd>    After the texture was looked up, the returned scalar is scaled into the range <i>(<tt><b>base</b></tt> ... <tt><b>gain</b></tt>)</i>. The base specifies the lowest possible result. 

<p>
</dl>

<dl>

<dt><tt><b>gain</b></tt>
<dd>    The gain specifies the highest possible result. 

<p>

<p>
</dl>
<br>
 <p><a name=cCC><h3>mi_wave_vector_texture</h3></a> 

<p><a name=iBEBC></a><a name=iBEBD></a> (see <a href=scene.html#iDJD>texture shader</a>) This shader implements a texture lookup function for vector textures. Vector textures are used for bump mapping. This shader is similar to <a name=iBEBE></a><a href=builtin.html#iBEAI><i>mi_wave_scalar_texture</i></a>, except that it deals with 3D vectors and not with scalars. This is the .mi scene file declaration: 

<p><pre>
    declare "wave_vector_texture" (
        vector texture  "tex",
        vector          "origin",
        vector          "scale",
        vector          "base",
        vector          "gain"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct wave_vector_texture {
        miTag           tex;
        miVector        origin;
        miVector        scale;
        miScalar        base;
        miScalar        gain;
    };
</pre>


<p>
<dl>

<dt><tt><b>tex</b></tt>
<dd>    The vector texture to look up with the texture coordinate <i> </i> state<i>-&gt;</i>tex after the scale and origin parameters were applied. The vector texture is evaluated at the point <i>(state-&gt;tex /scale - origin</i>). 

<p>
</dl>

<dl>

<dt><tt><b>origin</b></tt>
<dd>    This parameter specifies the origin in the texture, effectively shifting the texture down and to the left for positive origin values. 

<p>
</dl>

<dl>

<dt><tt><b>scale</b></tt>
<dd>    Scaling changes the size of the texture. Values greater than 1.0 reduce the size. 

<p>
</dl>

<dl>

<dt><tt><b>base</b></tt>
<dd>    After the texture was looked up, the X, Y, and Z components of the returned vector are scaled into the range <i>(<tt><b>base</b></tt> ... <tt><b>gain</b></tt>)</i>. The base specifies the lowest possible result. 

<p>
</dl>

<dl>

<dt><tt><b>gain</b></tt>
<dd>    The gain specifies the highest possible result. 

<p>

<p>
</dl>
<br>
 <p><a name=cCD><h3>mi_wave_color_texture</h3></a> 

<p><a name=iBEBF></a><a name=iBEBG></a> (see <a href=scene.html#iDJD>texture shader</a>) This shader implements a texture lookup function for color textures. Color textures are used for ambient, diffuse, and specular color mapping. This shader is similar to <a name=iBEBH></a><a href=builtin.html#iBEAI><i>mi_wave_scalar_texture</i></a>, except that it deals with RGB colors and not with scalars. This is the .mi scene file declaration: 

<p><pre>
    declare "wave_color_texture" (
        color texture   "tex",
        color           "origin",
        color           "scale",
        color           "base",
        color           "gain"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct wave_color_texture {
        miTag           tex;
        miVector        origin;
        miVector        scale;
        miScalar        base;
        miScalar        gain;
    };
</pre>


<p>
<dl>

<dt><tt><b>tex</b></tt>
<dd>    The color texture to look up with the texture coordinate <i> </i> state<i>-&gt;</i>tex after the scale and origin parameters were applied. The color texture is evaluated at the point <i>(state-&gt;tex /scale - origin</i>). 

<p>
</dl>

<dl>

<dt><tt><b>origin</b></tt>
<dd>    This parameter specifies the origin in the texture, effectively shifting the texture down and to the left for positive origin values. 

<p>
</dl>

<dl>

<dt><tt><b>scale</b></tt>
<dd>    Scaling changes the size of the texture. Values greater than 1.0 reduce the size. 

<p>
</dl>

<dl>

<dt><tt><b>base</b></tt>
<dd>    After the texture was looked up, the RGB components of the returned color are scaled into the range <i>(<tt><b>base</b></tt> ... <tt><b>gain</b></tt>)</i>. The base specifies the lowest possible result. 

<p>
</dl>

<dl>

<dt><tt><b>gain</b></tt>
<dd>    The gain specifies the highest possible result. 

<p>

<p>
</dl>
<br>
 <p><a name=cCE><h3>mi_wave_light</h3></a> 

<p><a name=iBEBI></a><a name=iBEBJ></a> (see <a href=scene.html#iDHI>light shader</a>) This shader implements Wavefront's omnidirectional, directional, and infinite light sources. In mental ray terminology, these are called <a name=iBECA></a><a href=shaders.html#iJGA>point light</a>s, <a name=iBECB></a><a href=shaders.html#iJGD>spot light</a>s, and <a name=iBECC></a><u>directional light</u>s. Point and spot lights may have distance <a name=iBECD></a><u>attenuation</u>; spot lights have angle attenuation. Various kinds of falloff are available. 

<p>This is the .mi scene file declaration: 

<p><pre>
    declare "wave_light" (
        color           "color",
        vector          "dir",
        boolean         "dist_linear",
        scalar          "dist_start",
        scalar          "dist_end",
        boolean         "dist_inverse",
        scalar          "dist_power",
        boolean         "angle_linear",
        scalar          "angle_outer",
        scalar          "angle_inner",
        boolean         "angle_cosine",
        scalar          "angle_power"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct wave_light {
        miColor         color;
        miVector        dir;
        miBoolean       dist_linear;
        miScalar        dist_start;
        miScalar        dist_end;
        miBoolean       dist_inverse;
        miScalar        dist_power;
        miBoolean       angle_linear;
        miScalar        angle_outer;
        miScalar        angle_inner;
        miBoolean       angle_cosine;
        miScalar        angle_power;
    };
</pre>


<p>
<dl>

<dt><tt><b>color</b></tt>
<dd>    The color of the light is an RGB color (no alpha) that specifies the color of the emitted light. If global shadows are enabled, the shader casts shadow rays back towards the point to be illuminated in order to attenuate the light color depending on the <a name=iBECE></a><a href=scene.html#iECC>shadow shader</a>s of occluding objects. Occluding objects may change the light intensity (but not the light color) based on their transparency. The end result is returned by the light shader. 

<p>
</dl>

<dl>

<dt><tt><b>dir</b></tt>
<dd>    If the light is a spot light, the direction vector specifies the direction of maximum illumination, i.e., the direction the spot light is pointing. 

<p>
</dl>

<dl>

<dt><tt><b>dist_linear</b></tt>
<dd>    If this parameter is <tt><b>miTRUE</b></tt>, linear distance <a name=iBECF></a><u>attenuation</u> is enabled. The light intensity is not attenuated for distances less than <tt><b>dist_start</b></tt>, then falls off linearly until no light at all remains at distance <tt><b>dist_end</b></tt>. 

<p>
</dl>

<dl>

<dt><tt><b>dist_start</b></tt>
<dd>    This parameter is used only if <tt><b>dist_linear</b></tt> is <tt><b>miTRUE</b></tt>. It specifies the distance where <a name=iBECG></a><u>attenuation</u> begins. 

<p>
</dl>

<dl>

<dt><tt><b>dist_end</b></tt>
<dd>    This parameter is used only if <tt><b>dist_linear</b></tt> is <tt><b>miTRUE</b></tt>. It specifies the maximum distance the light will reach. 

<p>
</dl>

<dl>

<dt><tt><b>dist_inverse</b></tt>
<dd>    If this parameter is <tt><b>miTRUE</b></tt> and <tt><b>dist_linear</b></tt> is <tt><b> </b></tt> miFALSE, inverse distance attenuation is enabled. The light intensity is attenuated logarithmically based on the distance, proportional to the factor <i> 1 /distance<sup>dist_power</sup></i>. 

<p>
</dl>

<dl>

<dt><tt><b>dist_power</b></tt>
<dd>    If <tt><b>dist_linear</b></tt> is <tt><b>miTRUE</b></tt>, this parameter specifies the speed of the falloff. For example, if it is 2.0, light intensity falls of with the square of the distance, with full illumination only directly at the light source. 

<p>
</dl>

<dl>

<dt><tt><b>angle_linear</b></tt>
<dd>    If this parameter is <tt><b>miTRUE</b></tt>, angular attenuation is enabled. The light intensity is not attenuated for illuminations direction that form an angle of less than <tt><b>angle_inner</b></tt> to the illumination direction <tt><b>dir</b></tt>. If the angle is grater than <tt><b>angle_outer</b></tt>, no illumination takes place. Between the inner and outer angles, illumination falls off linearly. 

<p>
</dl>

<dl>

<dt><tt><b>angle_outer</b></tt>
<dd>    If <tt><b>angle_linear</b></tt> is <tt><b>miTRUE</b></tt>, the angle of the inner full-intensity light cone. 

<p>
</dl>

<dl>

<dt><tt><b>angle_inner</b></tt>
<dd>    If <tt><b>angle_linear</b></tt> is <tt><b>miTRUE</b></tt>, the angle of the outer soft light cone, outside of which no illumination takes place. 

<p>
</dl>

<dl>

<dt><tt><b>angle_cosine</b></tt>
<dd>    If this parameter is <tt><b>miTRUE</b></tt> and <tt><b>angle_linear</b></tt> is <tt><b> </b></tt> miFALSE, cosine angular <a name=iBECH></a><u>attenuation</u> is enabled. The light intensity is attenuated proportionally to the cosine of the angle formed by the illumination direction <i>L<sub>i</sub></i> and the spot direction <tt><b>dir</b></tt>, raised to <tt><b>angle_power</b></tt>: <i>1 /cos(angle)<sup>angle_power</sup> = 1 /(L<sub>i</sub> *dir)<sup>angle_power</sup></i>. 

<p>
</dl>

<dl>

<dt><tt><b>angle_power</b></tt>
<dd>    If cosine angular attenuation is enabled, the power to which the cosine of the illumination direction and the spot light direction. 

<p>
</dl>
Wavefront <a name=iBECI></a><u>area light</u> sources are supported by mental ray's rectangular area light source type. This area light attribute can be used with any light source without changing light shader parameters. 

<p>

<p><br>
 <p><a name=cCF><h3>mi_wave_shadow</h3></a> 

<p><a name=iBECJ></a><a name=iBEDA></a> (see <a href=scene.html#iECC>shadow shader</a>) Shadow shaders are called when a shadow ray intersects an object occluding the light source as seen from the illuminated point. The <i>mi_wave_shadow</i> shader reduces the intensity of the light color based on the <a name=iBEDB></a><a href=builtin.html#iBCCI>dissolve</a> value of the object, which can be either constant or texture-mapped. The object color is not taken into account. Here are the .mi scene file declarations: 

<p><pre>
    declare "wave_shadow" (
        scalar          "dissolve",
        color texture   "dissolve_map"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct wave_shadow {
        miScalar        dissolve;
        miTag           dissolve_map;
    };
</pre>


<p>The parameters are normally duplicates of the respective parameters of the <a name=iBEDC></a><a href=builtin.html#iBDFE><i>mi_wave_material</i></a> shader. Unlike the SOFTIMAGE shaders, the Wavefront material shader does not double as shadow shader. 

<p>
<dl>

<dt><tt><b>dissolve</b></tt>
<dd>    Dissolve<a name=iBEDD></a> (see <a href=builtin.html#iBCCI>dissolve</a>)  is an non-physical effect that fades or blends the object out of the scene. The index of refraction is not taken into account. This is basically a switcher effect. It uses mental ray's <a name=iBEDE></a><u>transparency</u> feature. 

<p>
</dl>

<dl>

<dt><tt><b>dissolve_map</b></tt>
<dd>    If this parameter is nonzero, the <a name=iBEDF></a><a href=builtin.html#iBCCI>dissolve</a> parameter that fades the object is taken from this scalar texture map, using a straight filtered scalar texture lookup. 

<p>

<p>
</dl>
<br>
 <p><a name=cCG><h3>mi_wave_reflection_map</h3></a> 

<p><a name=iBEDG></a><a name=iBEDH></a>Environment maps are called to evaluate the color returned by a primary or secondary ray that goes to infinity without hitting an object, or to evaluate the color of a reflected secondary ray quickly without checking for intersections with other objects. The Wavefront environment shader assumes that a single <a name=iBEDI></a><a href=scene.html#iDJA>texture</a> is mapped on the inside of an infinite sphere enclosing the scene. It looks up a color on the texture map based on the direction of the ray. This is the .mi scene file declaration: 

<p><pre>
    declare "wave_reflection_map" (
        color texture   "tex",
        transform       "transform"
    )
</pre>


<p>The corresponding C structure is: 

<p><pre>
    struct wave_reflection_map {
        miTag           tex;
        miMatrix        transform;
    };
</pre>


<p>
<dl>

<dt><tt><b>tex</b></tt>
<dd>    This parameter specifies the color texture to wrap on the infinite sphere. 

<p>
</dl>

<dl>

<dt><tt><b>transform</b></tt>
<dd>    The transformation is applied to the ray direction <i>state<i>-&gt;</i>dir</i> before the coordinate on the texture map is calculated. It can be used to shift or rotate the texture map. 

<p>
</dl>
 <br>
 <p><a name=cCH><h2>SOFTIMAGE Material Implementation</h2></a> 

<p>The Softimage material shader is a very complex shader that handles <a name=iBEDJ></a><u>object inside/outside</u> calculations, <a name=iBEEA></a><a href=scene.html#iDJA>texture</a> compositing, light <a name=iBEEB></a><u>illumination</u>, <a name=iBEEC></a><a href=shaders.html#iHJI>secondary ray</a>s, and <a name=iBEED></a><u>static blur</u>, and is also usable as a shadow shader. This chapter explains the internals of this shader, to allow shader writers to write modified versions. For a general description of the shader parameters, see above. 

<p>The functions described in this chapter are all callable by external shaders. Note that they all rely on a material structure that is either identical to <tt><b>struct soft_material</b></tt>, or begins with a structure identical to <tt><b>struct soft_material</b></tt>. 

<p>Here is the actual source code of the <i>soft_material</i> shader mainline: 

<p><a name=iBEEE></a><pre>
     miBoolean soft_material(
        register miColor     *result,
        register miState     *state,
        struct soft_material *paras)
     {
        struct soft_material m;              /* work area */
        miScalar             ior_in,ior_out; /* refr index*/

        if (state-&gt;type == miRAY_SHADOW) {
             if (!mi_mtl_is_casting_shadow(state, paras))
                        return(miFALSE);
        } else
             mi_mtl_refraction_index(state, paras,
                                        &amp;ior_in, &amp;ior_out);

        m = *paras;
        mi_mtl_textures(state, &amp;m, paras, &amp;state-&gt;normal,
                                        &amp;state-&gt;dot_nd);
        mi_mtl_static_blur(state, &amp;m);

        if (state-&gt;type == miRAY_SHADOW)
             return(mi_mtl_compute_shadow(result, &amp;m));

        mi_mtl_illumination(result, state, &amp;m, paras,
                                        ior_in, ior_out);
        mi_mtl_reflection(result, state, &amp;m);
        mi_mtl_refraction(result, state, &amp;m,
                                        ior_in, ior_out);
        return(miTRUE);
     }
</pre>


<p>This shader is based on a copy <i>m</i> of the material parameters <i>paras</i>. This copy is modified by certain functions, particularly <i>mi_mtl_textures</i>, avoiding a large number of pointer arguments such as <i>ambient</i> or <i>transparency</i>. Note that only those parts of the <i>paras</i> structure are copied that are defined by <tt><b>struct soft_material</b></tt>; this does not include the array contents, which is the reason why some functions have both a <i>paras</i> and an <i>m</i> argument. The <i>mi_mtl_illumination</i> function, for example, needs access to both the light array <i>paras-&gt;lights</i> and the ambient, diffuse, and specular colors in <i>m</i>, as calculated by <i>mi_mtl_textures</i>. This shader also checks twice if it is called as a shadow shader, by checking <i>state-&gt;type</i>, to shortcut certain operations only needed in material shaders. 

<p>The functions used by <i>soft_material</i> are: 

<p><pre>
     miBoolean mi_mtl_is_casting_shadow(
        register miState                *state,
        register struct soft_material   *paras)
     {
        register int                    num;

        for (num=0; num &lt; paras-&gt;n_light; num++)
                if (state-&gt;instance ==
                    paras-&gt;light[paras-&gt;i_light + num])
                        return(miTRUE);
        for (num=0; num &lt; paras-&gt;n_difflight; num++)
                if (state-&gt;instance ==
                    paras-&gt;difflight[paras-&gt;i_difflight
                                                + num])
                        return(miTRUE);
        return(miFALSE);
     }
</pre>


<p>This function is used only in the shadow shader case. It checks whether the light casting the shadow is in the material shader's light list (the shadow shader gets the same parameters as the material shader because the <tt><b>shadow soft_material</b></tt> statement in the .mi file has an empty parameter list). 

<p><pre>
     void mi_mtl_refraction_index(
        miState              *state,
        struct soft_material *paras,
        miScalar             *ior_in,
        miScalar             *ior_out)
     {
        register int         num;
        register miState     *s, *s_in;

        num = state-&gt;type == miRAY_REFRACT ||
              state-&gt;type == miRAY_TRANSPARENT;
        for (s_in=0, s=state-&gt;parent; s; s=s-&gt;parent) {
                if ((s-&gt;type == miRAY_REFRACT ||
                     s-&gt;type == miRAY_TRANSPARENT) &amp;&amp;
                     s-&gt;shader == state-&gt;shader) {
                        num++;
                        if (!s_in)
                                s_in = s-&gt;parent;
                }
        }
        if (num &amp; 1) {
                *ior_in  = paras-&gt;ior;
                *ior_out = s_in &amp;&amp; s_in-&gt;ior != 0 ?
                                          s_in-&gt;ior : 1;
                state-&gt;refraction_volume = s_in
                                ? s_in-&gt;refraction_volume
                                : state-&gt;camera-&gt;volume;
        } else {
                *ior_out = paras-&gt;ior;
                *ior_in  = state-&gt;parent &amp;&amp;
                           state-&gt;parent-&gt;ior != 0 ?
                                  state-&gt;parent-&gt;ior : 1;
                if (!state-&gt;refraction_volume)
                        state-&gt;refraction_volume =
                                              state-&gt;volume;
        }
        state-&gt;ior = *ior_out;
     }
</pre>


<p>This function computes the indices of refraction on the incoming and outgoing ray, and sets the appropriate volume shader in the state. It operates by following the state parent links all the way back to the primary ray, and counts the number of times this shader was called before. If it was called an odd number of times, the ray is exiting the object, otherwise it is entering. For example, on the back side of a sphere, this function will find that the material has been called once before (for the front side); 1 is an odd number so this ray must be exiting. Materials are distinguished by their parameters. Note that this implements a heuristic; mental ray operates with intersections, not volumes, and allows rendering non-volume objects such as SOFTIMAGE ``grids'' and collections of polygons with different materials where inside/outside calculations cannot be performed meaningfully. 

<p><pre>
     void mi_mtl_textures(
        miState              *state,   /* ray state */
        struct soft_material *m,       /* ret. new paras */
        struct soft_material *paras,   /* shader paras */
        miVector             *normal,  /* bumpmapped n */
        miScalar             *dot_nd,  /* n &lt;dot&gt; dir */
     {
        *normal = state-&gt;normal;
        *dot_nd = state-&gt;dot_nd;

        for (n=0; n &lt; paras-&gt;n_texture; n++) {
             tex = &amp;paras-&gt;texture[paras-&gt;i_texture + n];
             if (!mi_lookup_color_texture
                           (&amp;result, state, (miTag)tex-&gt;map,
                            &amp;state-&gt;tex_list[tex-&gt;space])
                     || result.a &lt; -0.001)
                  continue;
             { calculate blend and mask }
             { calculate m-&gt;diffuse }
             { calculate m-&gt;transp }
             if (state-&gt;type == miRAY_SHADOW)
                  continue;
             { calculate m-&gt;ambient }
             { calculate m-&gt;specular }
             { calculate m-&gt;reflect }
             if (tex-&gt;bump != 0 &amp;&amp; !state-&gt;contour) {
                  { take color sample u_unit to the side }
                  { take color sample v_unit above }
                  { calculate bump basis vectors }
                  { perturb *normal according to diffs }
                  mi_vector_normalize(normal);
                  *dot_nd = mi_vector_dot(normal,
                                          &amp;state-&gt;dir);
          }
        }
        { multiply m-&gt;ambient by m-&gt;ambience }
     }
</pre>


<p>This function looks up textures and applies the results to the copy <i>m</i> of the material parameters. Note that the light loop uses <i>paras</i>, not <i>m</i>, because <i>m</i> does not contain a copy of the arrays. The result of the texture lookup is checked for negative alphas to provide backwards compatibility to texture shaders written for version 1.8 of mental ray. The actual calculations are given as pseudocode enclosed in braces; the actual sorce code re-implements algorithms developed by SOFTIMAGE. 

<p><pre>
     miBoolean mi_mtl_compute_shadow(
        miColor                *result,
        struct soft_material   *m)
</pre>


<p>This function multiplies the <i>result</i> color by a color computed from <i>m-&gt;diffuse</i> and <i>m-&gt;transp</i>, and returns <tt><b> </b></tt> miTRUE if the resulting color is not black. 

<p><pre>
     void mi_mtl_static_blur(
        miState              *state, /* ray tracer state */
        struct soft_material *m)     /* textured mtl paras*/
</pre>


<p>If <i>m-&gt;sblur</i> is <tt><b>miTRUE</b></tt>, this function modifies <i>m-&gt;transp</i> according to <i>state-&gt;dir</i>, <i>state-&gt;normal</i>, and <i>m-&gt;sblurdecay</i>. 

<p><pre>
     void mi_mtl_illumination(
        register miColor     *result,  /* ret.illum color */
        miState              *state,   /* ray state */
        struct soft_material *m,*paras)/* mtl paras */
     {
        int                  n;        /* light counter */
        register miTag       *light;   /* current light */
        miColor              col;      /* light color */
        miVector             dir;      /* dir toward light*/
        miScalar             dot_nl;   /* normal &lt;dot&gt; dir*/
        miScalar             ns;       /* specular factor */

        if (m-&gt;transp &gt;= 1) {
             result-&gt;r = result-&gt;g =
             result-&gt;b = result-&gt;a = 0;
             return;
        }
        if (m-&gt;mode == 0 || state-&gt;contour) {
             *result = m-&gt;diffuse;
             result-&gt;a = 1;
             return;
        }
        *result = m-&gt;ambient;
        for (n=0; n &lt; paras-&gt;n_light; n++) {
            light = &amp;paras-&gt;light[paras-&gt;i_light + n];
            if (mi_trace_light(&amp;col, &amp;dir, &amp;dot_nl,
                                 state, (char *)*light)) {
                result-&gt;r += dot_nl * m-&gt;diffuse.r * col.r;
                result-&gt;g += dot_nl * m-&gt;diffuse.g * col.g;
                result-&gt;b += dot_nl * m-&gt;diffuse.b * col.b;
                if (m-&gt;mode == 2) {
                    ns = mi_phong_specular(m-&gt;shiny,
                                           state, &amp;dir);
                    result-&gt;r += ns * m-&gt;specular.r * col.r;
                    result-&gt;g += ns * m-&gt;specular.g * col.g;
                    result-&gt;b += ns * m-&gt;specular.b * col.b;
                }
                if (m-&gt;mode == 3) {
                    ns = mi_blinn_specular(m-&gt;shiny,
                                           state, &amp;dir);
                    result-&gt;r += ns * m-&gt;specular.r * col.r;
                    result-&gt;g += ns * m-&gt;specular.g * col.g;
                    result-&gt;b += ns * m-&gt;specular.b * col.b;
                }
            }
        }
        for (n=0; n &lt; paras-&gt;n_diff_light; n++) {
            light = &amp;paras-&gt;diff_light[paras-&gt;i_diff_light
	                                               + n];
            if (mi_trace_light(&amp;col, &amp;dir, &amp;dot_nl,
                                 state, (char *)*light)) {
                result-&gt;r += dot_nl * m-&gt;diffuse.r * col.r;
                result-&gt;g += dot_nl * m-&gt;diffuse.g * col.g;
                result-&gt;b += dot_nl * m-&gt;diffuse.b * col.b;
            }
        }
        result-&gt;a = 1;
     }
</pre>


<p>This function calculates a result color based on the ambient, diffuse, and specular colors computed by <i>mi_mtl_texture</i>. It is a straightforward implementation of standard Lambert, Phong, and Blinn shading. The alpha of the resulting color is set to 1, effectively making the material opaque. If refraction rays are cast, the alpha will be reduced by <i>mi_mtl_refraction</i> later. 

<p><pre>
     void mi_mtl_reflection(
        register miColor     *result, /* ret. illum color */
        miState              *state,  /* ray tracer state */
        struct soft_material *m)      /* mtl paras */
     {
        miColor              color;   /* reflect ray color*/
        miVector             dir;     /* dir towards light*/

        if (m-&gt;reflect &gt; 0) {
             miScalar f = 1 - m-&gt;reflect;
             result-&gt;r *= f;
             result-&gt;g *= f;
             result-&gt;b *= f;

             if (!state-&gt;contour
               &amp;&amp; state-&gt;reflection_level &lt;
                            state-&gt;options-&gt;reflection_depth
               &amp;&amp; state-&gt;reflection_level +
                  state-&gt;refraction_level &lt;
                            state-&gt;options-&gt;trace_depth) {

                  mi_reflection_dir(&amp;dir, state);
                  if (!m-&gt;notrace &amp;&amp;
                      mi_trace_reflection (&amp;color, state,
                                           &amp;dir) ||
                      mi_trace_environment(&amp;color, state,
                                           &amp;dir)) {

                          result-&gt;r += m-&gt;reflect * color.r;
                          result-&gt;g += m-&gt;reflect * color.g;
                          result-&gt;b += m-&gt;reflect * color.b;
                  }
             }
        }
     }
</pre>


<p>If the material is reflective, and mental ray is not in contour rendering mode, this shader casts a reflection ray, and merges the result from that ray with the <i>result</i> color. The alpha value is not changed. 

<p><pre>
     void mi_mtl_refraction(
        register miColor     *result, /* ret. illum color */
        miState              *state,  /* ray tracer state */
        struct soft_material *m,      /* mtl paras */
        double               ior_in,  /* refraction index */
        double               ior_out;
     {
        miColor              color;   /* reflect ray color*/
        miVector             dir;     /* dir towards light*/

        if (m-&gt;transp &gt; 0) {
             miScalar f = 1 - m-&gt;transp;
             result-&gt;r *= f;
             result-&gt;g *= f;
             result-&gt;b *= f;
             result-&gt;a *= f;
             if (state-&gt;contour)
                     return;
             state-&gt;refraction_level--;
             if (mi_refraction_dir(&amp;dir, state, ior_in,
                                                ior_out)) {
                  miTag env_save = state-&gt;environment;
                  state-&gt;environment = 0;
                  ok = ior_in == ior_out
                     ? mi_trace_transparent(&amp;color, state)
                     : mi_trace_refraction (&amp;color, state,
                                            &amp;dir);
                  state-&gt;environment = env_save;
             } else {
                  mi_reflection_dir(&amp;dir, state);
                  ok = m-&gt;notrace
                     ? mi_trace_environment(&amp;color, state,
                                            &amp;dir)
                     : mi_trace_reflection (&amp;color, state,
                                            &amp;dir);
             }
             if (ok) {
                  result-&gt;r += m-&gt;transp * color.r;
                  result-&gt;g += m-&gt;transp * color.g;
                  result-&gt;b += m-&gt;transp * color.b;
                  result-&gt;a += m-&gt;transp * color.a;
             }
        }
     }
</pre>


<p>This function casts transparency or refraction rays if the material is transparent. In this case, the material alpha is reduced. If the incoming and outgoing indices of refractions are the same, the ray direction does not change and a transparency ray can be used; otherwise a refraction ray is used. Transparency rays are more efficient and can be performed by the scanline algorithm if enabled. If the index of refraction (less than 1.0) causes the ray to be cast on the same side as the incoming ray, a reflection ray is used instead. The environment state variable is cleared to prevent mental ray from sampling the environment if the refracted ray does not intersect with another object (which would be the normal behavior). Note that the indices of refraction are passed as <tt><b>double</b></tt>s to allow shaders written in classic K&R C to call this function. 

<p><br>
 <p><hr>
<a href=index.html#contents>Table of Contents</a>
</body>
</html>
