INTRODUCTION TO MATERIALS

A geometry is perceptible because it either emits light or reflects light from its surfaces. This light manifests itself as color to the human eye. When designing a model there are two factors to take into account when considering color:

Material Properties

All materials in WTK consist of the following properties:

PROPERTY MEANING
Ambient The color reflected from a surface in full light
Diffuse The color reflected from a surface in shadow
Specular The color reflected from a material in specular white light
Shininess The narrowness of focus of a specular highlight
Emissive The color of light produced by a surface
Opacity The extent to which the color value of a pixel is blended with the color behind it.

Using existing materials

You can obtain materials by reading in files from a modeler which specifies material properties in its export file format.

These file formats include:

Wavefront .OBJ

3d Studio .3DS

VRML .WRL

 

Introduction to material tables

Material values used with a geometry are contained in its material table. A material table is a collection of "robust’ colors. These colors are termed robust because they include more reflectance information than just ambient-diffuse.

Material Tables are indexed starting at 0 being the first entry. Each polygon or vertex contains an index into the material table that tells it which material to use. More than one geometry may point to the same material table, and a geometry may point to different material tables depending on the effect you need. Defining materials is a difficult process. This course comes with a material table file wtmatlib.mat and a header file wtmatlib.h that defines 95 different materials that you can use. This file is free for you to use and add to as you please. Well cover the functions that are applicable to implement using a material table library.

Loading a material table library

a material table file has a .mat extension. By default each entity you create has its own material table defined for it. But you can tell a geometry to use a different material table file and the entries in that file. The following is an sample of a material table library

The following is a sample from a material table called default.mat

mat

version 3.00

valid ambient diffuse specular shininess emission alpha

matdef White // id 0

ambient 1.000000 1.000000 1.000000

diffuse 1.000000 1.000000 1.000000

specular 0.000000 0.000000 0.000000

shininess 0.000000

emission 0.000000 0.000000 0.000000

alpha 1.000000

matdef WhiteLinen // id 1

ambient 0.980392 0.941176 0.901961

diffuse 0.980392 0.941176 0.901961

specular 0.000000 0.000000 0.000000

shininess 0.000000

emission 0.000000 0.000000 0.000000

alpha 1.000000

matdef WhiteIvory // id 2

ambient 1.000000 1.000000 0.941176

diffuse 1.000000 1.000000 0.941176

specular 0.000000 0.000000 0.000000

shininess 0.000000

emission 0.000000 0.000000 0.000000

alpha 1.000000

 

By allowing the user to index into a material table they can build a material library that can be used over and over in different simulations. Simply load the file and tell the individual geometries to use that material table.

Notice in the file each material listed has an id. This is the number used to index into the material table. Each material has a name i.e. WhiteIvory and has entries for all the properties of a material.

 

WTmtable_load

Reads a material table file from the specified filename. If a file with the name is not found in the current working directory, the extension .mat is added to the filename and the directory is searched again. If the specified file is not found this function returns NULL.

SYNTAX:

WTmtable *WTmtable_load(char *filename);

ARGUMENTS:

filename -- the name of the material table file to load

RETURN TYPE:

A pointer to a new material table (WTmtable).

Once the material table is loaded. You tell your geometries to use that material table.

 

WTgeometry_setmtable

Causes the specified geometry to reference the specified material table. It overrides any previous settings. A geometry may only reference one material table any one time.

SYNTAX:

void WTgeometry_setmtable(WTgeometry *geom, WTmtable *mtable);

ARGUMENTS:

geom -- The geometry in question
mtable
-- The material table to use.

RETURN TYPE:

void

In order to use the entries in the material table you tell the geometry and/or polygons and/or vertices to use an index into that material table.

 

WTgoemetry_setmatid

Used to change the material table index of all the polygons in the specified geometry.

SYNTAX:

FLAG WTgeometry_setmatid(WTgeometry *geom, int index);

ARGUMENTS:

geom -- The geometry in question
index --
The index into the material table

RETURN TYPE:

flag indicating the success or failure of the function

Assignment 16

project definition:

Editing a material table

WTK allows the user to create new material tables, add additional entries to existing material tables, and edit existing materials in a table.

 

WTmtable_addentry

Adds a new entry to an existing material table and returns the index number to the new material entry. The new entry will have defined fields set to these default values:

Ambient 0.0, 0.0, 0.0

Diffuse 0.0, 0.0, 0.0

Emissive 0.0, 0.0, 0.0

Specular 0.0, 0.0, 0.0

Shininess 0.0

Opacity 1.0

Name NULL

 

SYNTAX:

int WTmtable_newentry(WTmtable *mtable);

ARGUMENTS:

mtable -- A pointer to an existing material table

RETURN TYPE:

The index number of the new entry

Once a new entry is created its values can be set using the WTmtable_setvalue function

 

WTmtable_setvalue

Used to alter the characteristics of an entry in a material table.

SYNTAX:

FLAG WTmtable_setvalue(WTmtable *mtable, int materialindex, float *value, inr propertybit);

ARGUMENTS:

mtable -- The material table that contains the entry to be edited
materialindedx -- The index number into the material table for the entry to be edited.
Value
-- For Ambient, Specular, AmbientDiffuse, Diffuse, and Emissive this is an array of three floats, For Shininess
and Opacity it is an array of one float (You may use an array of 3 floats but only array[0] will be read.
Propertybit
-- Can be one of the following values:

WTMAT_AMBIENTDIFFUSE

WTMAT_AMBIENT

WTMAT_DIFFUSE

WTMAT_SPECULAR

WTMAT_SHINENESS

WTMAT_EMISSION

WTMAT_OPACITY

RETURN TYPE:

FALSE if the propertybit is not defined for the given material table.

NOTE: Changing a value in a material table can have an effect of multiple polygons in the simulation since polygons from different geometries can share a material table entry.