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

Geofeather Example

c filemi declaration filesimple mi scene example
geofeather.cgeofeather.mifeather.mi

In this geometry shader example, we make a feather out of hair primitives. The geometry shader uses a placeholder callback function. So, in the initial geometry shader, named geofeather, note that only the bounding box and flags are set. Because the geometry is of the hair geometry type, we must add some extra information, since a geoshader placeholder callback assumes using polygons or nurbs by default. The code example for this is:

obj = (miObject *)mi_scene_edit(tag);
obj->geo.placeholder_list.type = miOBJECT_HAIR;
mi_scene_edit_end(tag);

The callback function in this example is named geofeather_cb, and it is here that the actual hair primitives are constructed. This example is rather brute force. The bluish feather has a single hair spine, and then a row of barbs on the right and the left. Envision the feather by looking down Z, with Y up and X right. The barbs have similar coordinates except for X and negative X. The increment for each barb number shows up in the Y term. There is an nbarbs variable to tinker with the number of barbs going up the spine. Each hair has:

  • a radius
  • per-vertex position
  • per-vertex full rgba color, where a is opacity
  • per-vertex motion vector, which is currently ignored, and duplicates the position

To take advantage of the per-vertex opacity, we have included a feather texture material named feathertex at the bottom of the geofeather.c file. The key line of code is the one that reconstructs the hair vertex texture scalars into colors with an alpha channel. This is it:

miColor *haircol = (miColor *)&state->tex_list[0];

In addition, this feather texture material serves as both the material and shadow shader. Note the highly transparent nature and slightly colored shadows in the single feather rendered over black and white stripes.

In order to use these functions, the mi declaration file is fairly simple. Notice that the feathertex is explicitly listed for both the material and the shadow shader. Also, the nbarbs parameter is left out in order to default, while the example parameter is superfluous. [I'll change this. -bjg]

Now the mi file using the geofeather only needs instances, for example:

instance "Simple-Feather-Object 71_inst"
   geometry "geofeather" ()
   material [ "feather_mtl_mixed" ]
   transform 0.9817162 0.19035013 -1.4522089e-8 0.0
   -0.18497303 0.9539841 0.23600684 0.0
   0.04492394 -0.23169176 0.9717514 0.0
   -2.3043582 -8.743718 1.1867542 1.0
end instance

instance "Simple-Feather-Object 72_inst"
   geometry "geofeather" ()
   material [ "feather_mtl_mixed" ]
   transform 0.98171616 0.19035089 -3.3427167e-8 0.0
   -0.18497375 0.953984 0.2360071 0.0
   0.044924174 -0.23169196 0.9717514 0.0
   -2.935172 -8.74372 1.853204 1.0
end instance


which came from the mi file which made this picture


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