The Annotated VRML 97 Reference

1 Intro     Concepts     3 Nodes     4 Fields/Events    Conformance
A Grammar     B Java     C JavaScript     D Examples     E Related Info    References
Quick Java         Quick JavaScript         Quick Nodes   
 

  About the Book
  
Help
  Copyright © 1997-99
  Purchase the book from Amazon.com

Chapter 3:
Node Reference


Intro
Anchor
Appearance
AudioClip
Background
Billboard
Box
Collision
Color
ColorInterpolator
Cone
Coordinate
CoordinateInterpolator
Cylinder
CylinderSensor
DirectionalLight
ElevationGrid
Extrusion
Fog
FontStyle
Group
ImageTexture
IndexedFaceSet
IndexedLineSet
Inline
LOD
Material
MovieTexture
NavigationInfo
Normal
NormalInterpolator
OrientationInterpolator
PixelTexture
PlaneSensor
PointLight
PointSet
PositionInterpolator
ProximitySensor
ScalarInterpolator
Script
Shape
Sound
Sphere
SphereSensor
SpotLight
Switch
Text
TextureCoordinate
TextureTransform
TimeSensor
TouchSensor
Transform
Viewpoint
VisibilitySensor
WorldInfo

+3.27 Material

Material { 
  exposedField SFFloat ambientIntensity  0.2         # [0,1]
  exposedField SFColor diffuseColor      0.8 0.8 0.8 # [0,1]
  exposedField SFColor emissiveColor     0 0 0       # [0,1]
  exposedField SFFloat shininess         0.2         # [0,1]
  exposedField SFColor specularColor     0 0 0       # [0,1]
  exposedField SFFloat transparency      0           # [0,1]
}

The Material node specifies surface material properties for associated geometry nodes and is used by the VRML lighting equations during rendering. Section "2.14 Lighting model" contains a detailed description of the VRML lighting model equations.

All of the fields in the Material node range from 0.0 to 1.0.

The fields in the Material node determine how light reflects off an object to create colour:

  1. The ambientIntensity field specifies how much ambient light from light sources this surface shall reflect. Ambient light is omnidirectional and depends only on the number of light sources, not their positions with respect to the surface. Ambient colour is calculated as ambientIntensity × diffuseColor.
  2. The diffuseColor field reflects all VRML light sources depending on the angle of the surface with respect to the light source. The more directly the surface faces the light, the more diffuse light reflects.
  3. The emissiveColor field models "glowing" objects. This can be useful for displaying pre-lit models (where the light energy of the room is computed explicitly), or for displaying scientific data.
  4. The specularColor and shininess fields determine the specular highlights (i.e., the shiny spots on an apple). When the angle from the light to the surface is close to the angle from the surface to the viewer, the specularColor is added to the diffuse and ambient colour calculations. Lower shininess values produce soft glows, while higher values result in sharper, smaller highlights.
  5. The transparency field specifies how "clear" an object is, with 1.0 being completely transparent, and 0.0 completely opaque.
TECHNICAL NOTE: If diffuseColor, specularColor, and ambientIntensity are zero, browsers can recognize this as a hint to turn off lighting calculations and simply render the geometry in the emissiveColor.

TIP: It is rare for an object to use all of the Material node's parameters at the same time. Just specifying an overall diffuseColor is easy and gives good results. Adding specular highlights by specifying a white specularColor and adjusting the shininess field will suffice for most objects. Alternatively, you can specify a black diffuseColor and simply use emissiveColor to get full-intensity, glowing objects. If an object is purely emissive (specularColor and diffuseColor are both black), then implementations do not need to perform lighting calculations for the object at all.

Partially transparent objects can be used to create a lot of great effects. For example, very nice smoke and fire effects can be created using semitransparent, animated triangles. Unfortunately, not all systems support partial transparency, so if you want your world to be viewed by the largest number of people you should stay away from transparency values other than 0.0 (completely opaque) and 1.0 (completely transparent).

Perhaps the greatest frustration for content creators with VRML 1.0 was creating scenes that would look good on all of the various VRML browsers. Varying capabilities of the underlying rendering libraries and different interpretations of the incomplete specification resulted in vastly different appearances for identical scenes. These problems are addressed in VRML 2.0 in several different ways.

First, ideal lighting equations are given, and the interaction between lights, materials, and textures are well defined (see Section 2.14, Lighting Model). The VRML 1.0 specification was vague about what the ideal, correct scene would look like once rendered; VRML 2.0 is very precise. Implementations will still be forced to approximate the ideal due to hardware and software limitations, but at least now all implementations will be aiming at the same target, and results can be judged against the ideal.

VRML 1.0 allowed multiple materials to be specified in a Material node and allowed the materials to be applied to each face or vertex of shapes. VRML 2.0 allows only a single Material node, but also allows specification of multiple diffuse colors for each vertex or face, restricting the feature to a simple, common case.

The ambientColor field of VRML 1.0 is replaced by the VRML 2.0 ambientIntensity field. Specifying what fraction of the diffuse color should be visible due to ambient light is simpler and better matches the capabilities of most interactive renderers. Specifying the ambient reflected color as a fraction of the reflected diffuse color also works much better with texture colors and per-face/per-vertex colors, which are both treated as diffuse colors. It would be very strange to see texture in the lighted parts of a textured object but see nothing but the ambient color in the unlit parts of the object.

However, even with these changes, color fidelity will continue to be a problem for content creators. Three-dimensional rendering libraries and hardware are a new feature for inexpensive computers and there will continue to be fairly large variations between different implementations. Differences in display hardware--monitors and video cards--can result in different colors being displayed on different machines even if the VRML browser makes exactly the same lighting calculations and puts exactly the same value in the frame buffer. As standards for color reproduction on computer displays develop and as 3D graphics hardware and software on inexpensive machines mature, the situation will gradually improve. However, it is likely to be several years before it will be practical to decide what color you will paint your house by applying virtual paint to a virtual house and judging the color as it appears on your computer screen.


TIP: Many of the rendering libraries do not support the features offered by the VRML Material node. It is recommended that authors perform tests on the browser before investing time into the various features in Material. It is generally safe to assume that diffuseColor will produce the basic object color during rendering. Beyond that, experimentation with the various browsers is required.

EXAMPLE (click to run) : The following example illustrates the use of the Material node by varying different fields in each row (see Figure 3-36). The last Sphere in each row has identical values as the third Sphere, with the exception of increased emissiveColor. The first row increases the diffuseColor from left to right. The second row increases shininess from left to right. The third row increases transparency from left to right:
#VRML V2.0 utf8
Group { children [
  Transform {
    translation -3 2.5 0  children Shape { geometry DEF S Sphere {}
      appearance Appearance {
        material Material { diffuseColor 0.2 0.2 0.2 }
  }}}
  Transform {
    translation 0 2.5 0  children Shape { geometry USE S
      appearance Appearance {
        material Material { diffuseColor .5 .5 .5 }
  }}}
  Transform {
    translation 3 2.5 0  children Shape { geometry USE S
      appearance Appearance {
        material Material { diffuseColor 1 1 1 }
  }}}
  Transform {
    translation 6 2.5 0  children Shape { geometry USE S
      appearance Appearance {
        material Material {
          diffuseColor 1 1 1
          emissiveColor .5 .5 .5
        }
  }}}
  Transform {
    translation -3 0 0 children Shape { geometry USE S
      appearance Appearance {
        material Material {
          specularColor 1 1 1
          shininess 0.01
        }
  }}}
  Transform {
    translation 0 0 0
    children Shape { geometry USE S
      appearance Appearance {
        material Material {
          specularColor 1 1 1
          shininess 0.5
        }
  }}}
  Transform {
    translation 3 0 0
    children Shape { geometry USE S
      appearance Appearance {
        material Material {
          specularColor 1 1 1
          shininess 0.98
                }
  }}}
Transform {
    translation 6 0 0
    children Shape { geometry USE S
      appearance Appearance {
        material Material {
          specularColor 1 1 1
          shininess 0.98
          emissiveColor 0.5 0.5 0.5
        }
  }}}
  Transform {
    translation -3 -2.5 0
    children Shape { geometry USE S
      appearance Appearance {
        material Material {
          specularColor 1 1 1
          shininess 0.5
          transparency 0.2
        }
  }}}
  Transform {
    translation 0 -2.5 0
    children Shape { geometry USE S
      appearance Appearance {
        material Material {
          specularColor 1 1 1
          shininess 0.5
          transparency 0.5
          }
  }}}
  Transform {
    translation 3 -2.5 0
    children Shape { geometry USE S
      appearance Appearance {
        material Material {
          specularColor 1 1 1
          shininess 0.5
          transparency 0.8
        }
  }}}
  Transform {
    translation 6 -2.5 0
    children Shape { geometry USE S
      appearance Appearance {
        material Material {
          specularColor 1 1 1
          shininess 0.5
          transparency 0.8
          emissiveColor 0.5 0.5 0.5
        }
  }}}
  Shape {
    geometry IndexedFaceSet {
      coord Coordinate {
        point [ -4 -4 -2, 7 -4 -2, 7 -3 -2, -4 -3 -2 ] }
        coordIndex [ 0 1 2 3 ]
    }
    appearance Appearance {
      texture ImageTexture { url "celtic.gif" } }
  }
  Background { skyColor 1 1 1 }
  DirectionalLight { direction -.65 0 -.85 }
  NavigationInfo { type "EXAMINE" headlight FALSE }
]}

Material node example

Figure 3-36: Material Node Example