JMU
Lighting and Materials in Java3D
An Introduction with Examples


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Parts of the Process
Normals
Materials
Materials (cont.)

An Example

javaexamples/java3d/lighting/LightingDriver.java (Fragment: material)
               // Create colors
       ambient  = new Color3f(0.329f, 0.223f, 0.027f);
       emissive = new Color3f(0.000f, 0.000f, 0.000f);       
       diffuse  = new Color3f(0.780f, 0.569f, 0.113f);
       specular = new Color3f(0.992f, 0.941f, 0.808f);
       
       // Create a Material
       material = new Material(ambient, emissive, diffuse, specular, 28.0f);
       
       // Create an Appearance
       appearance = new Appearance();
       appearance.setMaterial(material);
        
Lights
Lights (cont.)

An Example

javaexamples/java3d/lighting/LightingDriver.java (Fragment: lights)
               // Construct the AmbientLight
       lightA = new AmbientLight();
       lightA.setInfluencingBounds(new BoundingSphere());

       // Add the AmbientLight to the scene
       scene.addChild(lightA);

       // Construct the DirectionalLight
       lightD = new DirectionalLight();
       lightD.setInfluencingBounds(new BoundingSphere());

       // Add the DirectionalLight to the scene
       scene.addChild(lightD);