1 9 lighting a scene v there are four types of lighting: –ambient light –directional light...
TRANSCRIPT
1
99 Lighting a Scene Lighting a Scene
There are four types of lighting:There are four types of lighting:– ambient lightambient light– directional lightdirectional light– point lightpoint light– spotlightspotlight
Any number of these can be added to a scene.Any number of these can be added to a scene. A shape must be set up to reflect light (see later).A shape must be set up to reflect light (see later).
2
LightsLights
Java 3D Lighting ModelJava 3D Lighting Model InfluenceInfluence Different Light TypesDifferent Light Types Mixing LightsMixing Lights Material ObjectsMaterial Objects Other Coloring PossibilitiesOther Coloring Possibilities ShadowsShadows
3
LightsLights
ObjectivesObjectives
Understand the Java 3D lighting system. Understand the Java 3D lighting system. Know about the different ways to give a Know about the different ways to give a
color to an object.color to an object. Recall the theory about additive light Recall the theory about additive light
mixing.mixing.
Tutorial Page 6-2
4
LightsLights
Java 3D Lighting ModelJava 3D Lighting Model
There are three different reflections:There are three different reflections:– Ambient (caused by ambient light)Ambient (caused by ambient light)– Diffuse („normal“ reflection)Diffuse („normal“ reflection)– Specular (highlight reflections of polished Specular (highlight reflections of polished
material)material) No inter-object reflections in Java 3D. No inter-object reflections in Java 3D. Light sources are not visible itself.Light sources are not visible itself.
Tutorial Page 6-2
5
LightsLights
InfluenceInfluence
There is no warning for leaving light out of There is no warning for leaving light out of a scene.a scene.
There is no warning for not setting a light There is no warning for not setting a light source its influencing bounds.source its influencing bounds.
Some light types have a attenuation setting. Some light types have a attenuation setting.
Tutorial Page 6-8 6-9
6
LightsLights
Different Light TypesDifferent Light Types
Ambient lightAmbient lightAs if the sky was cloudy.As if the sky was cloudy.
Directional lightDirectional lightFor the virtual „sun“.For the virtual „sun“.
Point lightPoint lightFor virtual lamps.For virtual lamps.
Spot lightSpot lightVirtual spot lamps.Virtual spot lamps.
Tutorial Page 6-11 ff
7
LightsLights
Mixing LightMixing Light
Why does an object appear in a certain Why does an object appear in a certain color?color?
White sphere, red and blue light -> result? White sphere, red and blue light -> result?
Tutorial Page 6-17
8
LightsLights
Material ObjectMaterial Object
Color settings of the material object Color settings of the material object represent „reflection coefficients“.represent „reflection coefficients“.
Shininess is an interesting value.Shininess is an interesting value.
Tutorial Page 6-21
9
LightsLights
Other Coloring PossibilitiesOther Coloring Possibilities
No lights needed, but no „shiny“ effects:No lights needed, but no „shiny“ effects:– ColoringAttributesColoringAttributes– Per-vertex color (KickCan example: class Per-vertex color (KickCan example: class
Floor).Floor).
Tutorial Page 6-23
10
LightsLights
ShadowsShadows
There are no built-in shadows in Java 3D. There are no built-in shadows in Java 3D. Shadows in the tutorial are created using Shadows in the tutorial are created using
hand-made classes and polygones.hand-made classes and polygones.
11
LightsLights
12
Lighting ModelLighting Model
Capture from the OpenGLCapture from the OpenGL
13
Lighting Model(scope)Lighting Model(scope)
14
SceneGraph(Light)SceneGraph(Light)
S
BG
TG
TG
TG
S
S
S
TG
Locale
VitualUniverse object
view
sphere
environment BGL
scopeTG
15
Shading ModelShading Model
Flat Shading Gouraud Shading
16
MaterialMaterial
Same as OpenGLSame as OpenGL AmbientColorAmbientColor DiffuseColorDiffuseColor SpecularColorSpecularColor EmissiveColorEmissiveColor ShininessShininess
17
9.1. Ambient Light9.1. Ambient Light
Ambient light has the same intensity in all locations and directions– used as a kind of 'background' lighting
in many scenes
18
. Directional Light. Directional Light
Provides light shining in one direction– often used to approximate the sun
19
. Point Light. Point Light Light emitted from a pointLight emitted from a point
– the intensity changes with distancethe intensity changes with distance
– often used to approximate light bulbs, often used to approximate light bulbs, candles, etc.candles, etc.
20
SpotLightSpotLight
Adds direction and concentration to the Adds direction and concentration to the PointLight
21
lightScene() in WrapChecker3DlightScene() in WrapChecker3D private void lightScene() /* One ambient light, 2 directional lights */ { Color3f white = new Color3f(1.0f, 1.0f, 1.0f); // Red, Green, Blue values in 0-1 range
// Set up the ambient light AmbientLight ambientLightNode =
new AmbientLight(white); ambientLightNode.setInfluencingBounds(bounds);
sceneBG.addChild(ambientLightNode);:
Lights must be givenbounds in which tooperate.
22
// Set up the directional lights Vector3f light1Direction =
new Vector3f(-1.0f, -1.0f, -1.0f); // (x,y,z) left, down, backwards
Vector3f light2Direction = new Vector3f(1.0f, -1.0f, 1.0f);
// (x,y,z) right, down, forwards:
x-axis
z-axis
y-axisviewer
+
+
+
-
-
-
23
DirectionalLight light1 = new DirectionalLight(white, light1Direction); light1.setInfluencingBounds(bounds); sceneBG.addChild(light1);
DirectionalLight light2 = new DirectionalLight(white, light2Direction); light2.setInfluencingBounds(bounds); sceneBG.addChild(light2);
} // end of lightScene()
24
Making a BackgroundMaking a Background
private void addBackground() // A blue sky { Background back = new Background(); back.setApplicationBounds( bounds ); back.setColor(0.17f, 0.65f, 0.92f); // sky colour sceneBG.addChild( back ); } // end of addBackground()
A background can be a constant colour (as here), an image, or a geometry.
25
3D Shapes3D Shapes A 3D shape is defined as a A 3D shape is defined as a Shape3D object. object.
Each Each Shape3D object has object has two node components:two node components:– Geometry
made up of coordinates made up of coordinates (vertices)(vertices)
– Appearance e.g. colour, texture, e.g. colour, texture,
transparency,transparency,materialmaterial
continued
26
There are several predefined shape classes iThere are several predefined shape classes in n com.sun.j3d.utils.geometry::– Box, , Sphere, , Cone, , Cylinder
we use we use Sphere in in Checkers3D
Usually these classes are insufficient, and a Usually these classes are insufficient, and a shape's geometry must be built by connectinshape's geometry must be built by connecting vertices. g vertices.
27
Shape RepresentationShape Representation
Shape?Shape?– GeometryGeometry
How to represent geometry?How to represent geometry? Polygon-based representationPolygon-based representation
– AppearanceAppearance What is the appearance?What is the appearance?
Shape3D classShape3D class
28
Building GeometryBuilding Geometry
The The GeometryArray class is the parent for class is the parent for several useful geometry subclassesseveral useful geometry subclasses
29
GeometryGeometryGeometryArray
GeometryStripArray
IndexedGeometryArray
30
Shape ColourShape Colour
You can specify a shape's colour in three ways: – in the shape's material
used when the scene is illuminated (as here)
– in the shape's colouring attributes used when the shape is unreflecting
– in the vertices of the shape's geometry also for unreflecting shapes
31
Illuminating a ShapeIlluminating a Shape
A shape will reflect light when:– the scene has lights
set up in lightScene()
– the shape has material information see the next few slides
– the shape has a geometry containing normals done automatically in predefined shapes
(Sphere, Box, etc.)
32
Types of Shape ReflectionTypes of Shape Reflection
specularreflection(white)
diffusereflection(blue)
ambientreflection(blue here, but often set to black)
no shadow
no reflectionfor the floor
33
MaterialMaterial
The The Material is part of a shape's is part of a shape's Appearance node component.node component.
The The Material object specifies ambient, diffu object specifies ambient, diffuse, specular, and emissive colors and a shinise, specular, and emissive colors and a shininess valueness value– emissive colour is a kind of glowing effect, but emissive colour is a kind of glowing effect, but
it does not illuminate other shapesit does not illuminate other shapes
34
Creating a MaterialCreating a Material private void floatingSphere() // A shiny blue sphere located at (0,4,0) { // Create the blue appearance node Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f blue = new Color3f(0.3f, 0.3f, 0.8f); Color3f specular = new Color3f(0.9f, 0.9f, 0.9f);
Material blueMat = new Material(blue, black, blue, specular,25.0f); // ambient,emissive,diffuse,specular,shininess blueMat.setLightingEnable( true );
Appearance blueApp = new Appearance(); blueApp.setMaterial(blueMat); : // position the sphere: see later }
35
A shape is transformed using a A shape is transformed using a TranformGroup object.object.
The three basic transformations:The three basic transformations:– translationtranslation: move the shape to a new location: move the shape to a new location– rotationrotation: rotate the shape around the X, Y, Z axes: rotate the shape around the X, Y, Z axes– scalingscaling: resize the shape : resize the shape
A A TransformGroup object is initialised using object is initialised using Tranform3D objects. objects.
TransfomationsTransfomations
36
TranslationTranslation Build a shapeBuild a shape
Shape3D myShape = new Shape3D(myGeo, myApp);
TranslationTranslationTransform3D t3d = new Transform3D();t3d.set( new Vector3d(2.0, 1.0, -2.0) );
Create a transform group, set transform, add Create a transform group, set transform, add
the shapethe shapeTransformGroup tg = new TransformGroup(t3d);tg.addChild(myShape);
37
RotationRotation Build shapeBuild shape
Shape3D myShape = new Shape3D(myGeo, myApp);
Rotation (around z-axis)Rotation (around z-axis)Transform3D t3d = new Transform3D();t3d.rotZ(0.785); // rotate by 45 degrees
Create a transform group, set transform, add Create a transform group, set transform, add the shapethe shapeTransformGroup tg = new TransformGroup(t3d);tg.addChild(myShape);
38
RotationRotation
public BranchGroup SceneGraph(){
BranchGroup bg = new BranchGroup();
ColorCube c = new ColorCube(0.4f);
Transform3D t1 = new Transform3D();
t1.rotX(Math.PI/3.0d);
TransformGroup tg = new TransformGroup(t1);
tg.addChild(c);
bg.addChild(tg);
bg.compile();
return bg;
}
We need to change just:
Output
Scene Graph
39
What about the java3d What about the java3d coordinate system?coordinate system?
2n Meters Units 87.29 Universe (20 billion light years) 69.68 Galaxy (100,000 light years) 53.07 Light year 43.43 Solar system diameter 23.60 Earth diameter 10.65 Mile 9.97 Kilometer 0.00 Meter -19.93 Micron -33.22 Angstrom -115.57 Planck length
The coordinate system is sufficient to describe a universe in excess of several hundred billion light years across, yet still define objects smaller than a proton! [check this]
It is a right handed system, in meters.
40
ScalingScaling Build shapeBuild shape
Shape3D myShape = new Shape3D(myGeo, myApp);
Scaling by 1.75 in X, Y, and ZScaling by 1.75 in X, Y, and ZTransform3D t3d = new Transform3D();t3d.set(1.75);
Create transform group, set transform, add the Create transform group, set transform, add the
shapeshapeTransformGroup tg = new TransformGroup();tg.setTransform(t3d); // another waytg.addChild(myShape);
41
Composite TransformationsComposite Transformations
Combine translations, rotations, and Combine translations, rotations, and
scaling.scaling.
Methods: Methods: void setTranslation( Vector3d vectorTranslation );
void setRotation( AxisAngle4d axisangleAxis );void setRotation( Matrix3d matrixRotation );void setScale( double scaleFactor );
42
Positioning the SpherePositioning the Sphere
private void floatingSphere() // blue sphere located at (0,4,0) { : // set up the blue material
// position the sphere Transform3D t3d = new Transform3D(); t3d.set( new Vector3f(0,4,0)); TransformGroup tg = new TransformGroup(t3d); tg.addChild( new Sphere(2.0f, blueApp) ); // set its radius and appearance sceneBG.addChild(tg); } // end of floatingSphere()