provided by: 
Originally published at Internet.comJava Programming Notes # 1540 * Preface * Technical Discussion * The Program * The Number of Facets * The Shading Model * The Small Spheres * Emissive Color * Ambient Reflection and the AmbientLight Class * More Combinations of Light Source and Surface Reflection Properties * Diffuse Reflection and the DirectionalLight Class * The Shininess Property * Specular Reflection and the DirectionalLight Class * Shadows * Diffuse Reflection and the PointLight Class * Specular Reflection and the PointLight Class * Diffuse Reflection and the SpotLight Class * Specular Reflection and the PointLight Class * Run the Program * Summary * What's Next? * References * Complete Program Listing -----------------------------------
Preface
This is the first part of a multi-part lesson designed to help you understand the use of lighting and illumination in 3D scenes produced using the Java 3D API.
Optical illusions
Creating scenes that appear to be three-dimensional on a flat two-dimensional screen is all about creating optical illusions. There are many important aspects to creating these optical illusions in 3D programming, not the least of which is lighting and illumination.
A 3D simulator program
In this lesson, I will teach you about, and show examples of many of the important features of scene illumination in the Java 3D API. I will also provide the source code for a complete Java 3D lighting simulator program that you can compile and run to experiment with light in the Java 3D API. I will explain how that program works in subsequent parts of this multi-part lesson.
Viewing tip
You may find it useful to open another copy of this lesson in a separate browser window. That will make it easier for you to scroll back and forth among the different figures, tables, and listings while you are reading about them.
Supplementary material
I recommend that you also study the other lessons in my extensive collection of online Java tutorials. You will find those lessons published at Gamelan.com. However, as of the date of this writing, Gamelan doesn't maintain a consolidated index of my Java tutorial lessons, and sometimes they are difficult to locate there. You will find a consolidated index at www.DickBaldwin.com.
Technical Discussion
The Program
The program that I will present in this lesson can be used to experiment with most of the lighting and illumination features of the Java 3D API either individually or in combination.
In order to compile and run this program, you will need to download and install the Java 3D API. As of the date of this writing, it was available at: http://java.sun.com/products/java-media/3D/. The online documentation was available at: http://download.java.net/media/java3d/javadoc/1.4.0/.
In addition, you will need to download and install either Microsoft DirectX or OpenGL.
Our perception of 3D visual objects
From time to time, I will make references to Chapter 6 of a document published by Dennis J. Bouvier at the following URL. http://java.sun.com/developer/onlineTraining/java3d/. For example, here is a quotation from Bouvier:
"In the real world, the colors we perceive are a combination of the physical properties of the object, the characteristics of the light sources, the objects' relative positions to light sources, and the angle from which the object is viewed. Java 3D uses a lighting model to approximate the physics of the real world."
The mathematical 3D model
According to Bouvier, Section E.2 of the Java 3D API Specification presents the mathematical equations of the Java 3D lighting model. Still quoting Bouvier,
"The lighting model equation depends on three vectors: the surface normal (N), the light direction (L), and the direction to the viewer's eye (E) in addition to the Material properties of the object and the light characteristics."
This program makes it easy for the user to vary the surface normal (indirectly), the light direction, and the Material properties of the object. The program does not make it easy for the user to modify the direction to the viewer's eye. However, the primary experimental object is a large sphere which, because of its curvature, inherently results in a wide range of directions from the object's surface to the user's eye.
Light sources
Returning to Bouvier,
"The lighting model incorporates three kinds of real world lighting reflections: ambient, diffuse, and specular. Ambient reflection results from ambient light, constant low level light, in a scene. Diffuse reflection is the normal reflection of a light source from a visual object. Specular reflections are the highlight reflections of a light source from an object, which occur in certain situations."
This program makes it easy for the user to experiment with all three types of sources, plus another form of illumination referred to as emissive color.
Two user interfaces
This program produces two user interfaces. One interface is the display of a 3D scene containing five spheres as
Author: Richard G. Baldwin
Read article at Internet.com site