Prev: Useful Classes Next: The Material3D Class

8. Materials and MaterialSpecs

Writing procedural materials is quite similar to writing procedural textures. A Material is a Java class which subclasses artofillusion.Material. The materials you write will almost always subclass Material3D.

Just as Textures have a getTextureSpec() method which returns surface properties in a TextureSpec object, Materials have a getMaterialSpec() method which returns properties in a MaterialSpec object. Here is the definition of the MaterialSpec class:

public class MaterialSpec
{
  public RGBColor transparency, color, scattering;
  public double eccentricity;

  public MaterialSpec();
}
The color parameter is the intrinsic color of the material. As light passes through the material, it is gradually shifted toward color. The rate at which this happens is determined by transparency. If a component of transparency equals 0, the material is completely opaque to that color, while if it is 1, the material is completely transparent and that color component is unaffected by passing through the material.

scattering determines the amount of light which is scattered toward the viewpoint as it passes through the material. The amount of light scattered also depends on eccentricity, which is a number between -1 and 1. A value of 0 corresponds to isotropic scattering: light is equally scattered in all directions. Positive values mean that light is more strongly scattered in the backward direction, and negative values mean that light is more strongly scattered in the forward direction.

(Note that if you want your Material to scatter light, it must override isScattering() to return true. Otherwise, the scattering and eccentricity parameters are ignored, and no light is scattered by your Material.)

As with Textures, the interpretations of these parameters are slightly different from what you are used to from the standard Material classes. You will notice there is no density parameter. The standard classes calculate these values according to the following formulas:

transparency = pow(transparencyColor, density)
scattering = scatteringColor * density

Every Material has an index of refraction, which is set with the setIndexOfRefraction() method. If you want this to be an editable parameter, be sure to provide a user interface for it in your edit() method and save its value in your writeToFile() method. By default, all Materials have an index of refraction of 1.0.

Prev: Useful Classes Next: The Material3D Class