M3G - 3D Object Materials

Materials

A light can cause different effects. A shiny silver ball reflects the light in a different way than a sheet of paper does. M3G models these material characteristics with the following attributes:

  • Ambient reflection: The light that is reflected by an ambient light source.
  • Diffuse reflection: The reflected light is scattered equally in all directions.
  • Emissive light: An object can send out light to imitate glowing objects.
  • Specular reflection: The light that reflects off objects with a shiny surface.

You can set a color for each material attribute. The shiny silver ball's diffused color would be silver and its specular component white. To get the final object color, the material's color mixes with the light's color. If you point a blue light toward the silver ball, it would turn bluish.

Listing 9 shows how to use materials:




Listing 9. Setting a material
// Create appearance and the material.
_cubeAppearance = new Appearance();
_colorTarget = COLOR_DEFAULT;
setMaterial(_cubeAppearance, _colorTarget);

/**
* Sets the material according to the given target.
*
* @param appearance appearance to be modified.
* @param colorTarget target color.
*/
protected void setMaterial(Appearance appearance, int colorTarget)
{
Material material = new Material();

switch (colorTarget)
{
case COLOR_DEFAULT:
break;

case COLOR_AMBIENT:
material.setColor(Material.AMBIENT, 0x00FF0000);
break;


case COLOR_DIFFUSE:
material.setColor(Material.DIFFUSE, 0x00FF0000);
break;

case COLOR_EMISSIVE:
material.setColor(Material.EMISSIVE, 0x00FF0000);
break;

case COLOR_SPECULAR:

material.setColor(Material.SPECULAR, 0x00FF0000);
material.setShininess(2);
break;

// no default
}

appearance.setMaterial(material);
}



setMaterial() creates a new Material object and sets the colors with setColor() using the respective color component identifier. The Material object is then assigned to an Appearance object, which is used in the call to Graphics3D.render(). Although not shown here, you can use Material.setVertexColorTrackingEnable() in order to use the vertex colors for ambient and diffuse reflection instead of using Material.setColor(). Both lights and materials are implemented in LightingMaterialsSample.java. Using keys, you can combine different lights with materials to experiment with the effects.

In Figure 9, the different material characteristics are displayed using an omnidirectional light. Each screenshot sets a single color component to red to demonstrate its effect in isolation.


Figure 9. Different color components: a) Ambient, b) Diffuse, c) Emissive, and d) Specular
Different color components: a) Ambient, b) Diffuse, c) Emissive, and d) Specular

The ambient reflection only reacts to ambient light; thus, using an omnidirectional light has no effect. The diffuse material component creates a matte surface, while the emissive component creates a glowing effect. The specular color component emphasizes the shininess. Again, you could improve the shading quality by using more triangles.

(picked from IBM developer site)

Comments

DataDiary.com said…
thanks for it and i was so much confuse how to install it...
nago said…
Hey, nice site you have here! Keep up the excellent work!


J2ME Application Development

Popular posts from this blog

JDBC comes to J2ME finally?

JSR-184 a.k.a. Micro3D a.k.a. Java Mobile 3D