Los Angeles mental ray® User Group
 Home   About   Info   Summaries   Gallery   Forum   Resources   Contact   Jobs 


Resources Sections

General

Install/Setup

Options Settings

Performance Optimizations

mi Scene File

FG/AO/GI

Subsurface Scattering

Shiny Stuff

mrfm (Maya)

Shader Writing

Hair and Geometry Shaders

Hair and Transparency

c filemi declaration filesimple mi scene example
hairtex.chairtex.mihair.mi

  

When working with hair primitives, it is often useful to add transparency. In this example, we added transparency to the mib_illum_hair function, which comes as source for all releases of mental ray. The hair primitive will specify 4 texture scalars for rgb and alpha. We also add motion blur. In the left picture, we show it rendered with "-motion off".

Note that the mi file must specify the transparencies through an extra texture scalar included in the hair scalars. However, this could be moved into a geometry shader specifying larger groups of hair.

The key is to notice how to deconstruct the texture scalars, as we do with a simple texture function used as input for diffuse and/or ambient. From that function, which we name mib_hair_texture_color:
   *result = *(miColor *)&state->tex_list[0];
Now 4 interpolated color scalars are available for the hair material. We modify the hair material function, renaming to mib_illum_hair2, by using the alpha assuming it is passed in through the diffuse color. Look for this line:
   result->a = diffuse->a;

Example usage from an mi file might look something like:
shader "hair local default color" "mib_hair_texture_color" (
   "opaque" off
)
material "hair local default"
 "mib_illum_hair2" (
  "ambient" = "hair local default color",
  "diffuse" = "hair local default color",
  "ambience" 0.2 0.2 0.2,
  "specular" = "hair local default color",
  "exponent" 50,
  "lights" ["Spot Light_inst"]
 )
end material

object "hair"
 visible trace shadow
 hair
  material "hair local default"
  radius 0.03
  degree 2
  approximate 2
  vertex t 4
  scalar [210]
   -3.1881328 6.0e-6 -1.863712 0.03200989 0.016004944 0.006401978 1.0 -3.1881328 3.0 -1.863712 0.11497425 0.10748713 0.10299485 1.0 -3.1881328 5.999994 -1.863712 0.21845801 0.209229 0.2036916 1.0
   1.3208607 2.8183317e-6 4.4139824 0.009593022 0.004796511 0.0019186045 1.0 1.3208607 1.2181729 6.1554365 0.10763287 0.103816435 0.10152657 1.0 1.3208607 2.464304 7.876994 0.26312277 0.23156138 0.21262455 1.0
...
  hair [11]
   0 21 42 63 84 105 126 147 168 189 210
 end hair
end object


Here's a two hair example, for which we will add motion blur

  

We added motion blur to the above picture by using vertex m 3 with 3 extra motion vectors per hair vertex. Note in the right-hand picture that we also turned on full opacity to emphasizize the effect.

Hair primitives with transparency can be used to implement a variation of line based particle rendering. Here's another primitive pic:


Discuss on LAmrUG forum


 © 2003-2006 Los Angeles mental ray® User Group, All Rights Reserved.
mental images and mental ray are registered trademarks of mental images GmbH, in the United States
and other countries. Other product names may be trademarks of their respective owners.


About Us| Contact Us