9 lighting a scene n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
9 Lighting a Scene PowerPoint Presentation
Download Presentation
9 Lighting a Scene

Loading in 2 Seconds...

play fullscreen
1 / 42

9 Lighting a Scene - PowerPoint PPT Presentation


  • 79 Views
  • Uploaded on

9 Lighting a Scene. There are four types of lighting: ambient light directional light point light spotlight Any number of these can be added to a scene. A shape must be set up to reflect light (see later). Lights. Java 3D Lighting Model Influence Different Light Types Mixing Lights

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about '9 Lighting a Scene' - matsu


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
9 lighting a scene
9 Lighting a Scene
  • There are four types of lighting:
    • ambient light
    • directional light
    • point light
    • spotlight
  • Any number of these can be added to a scene.
  • A shape must be set up to reflect light (see later).
lights
Lights
  • Java 3D Lighting Model
  • Influence
  • Different Light Types
  • Mixing Lights
  • Material Objects
  • Other Coloring Possibilities
  • Shadows
lights objectives

Tutorial Page 6-2

LightsObjectives
  • Understand the Java 3D lighting system.
  • Know about the different ways to give a color to an object.
  • Recall the theory about additive light mixing.
lights java 3d lighting model

Tutorial Page 6-2

LightsJava 3D Lighting Model
  • There are three different reflections:
    • Ambient (caused by ambient light)
    • Diffuse („normal“ reflection)
    • Specular (highlight reflections of polished material)
  • No inter-object reflections in Java 3D.
  • Light sources are not visible itself.
lights influence

Tutorial Page 6-8 6-9

LightsInfluence
  • There is no warning for leaving light out of a scene.
  • There is no warning for not setting a light source its influencing bounds.
  • Some light types have a attenuation setting.
lights different light types

Tutorial Page 6-11 ff

LightsDifferent Light Types
  • Ambient lightAs if the sky was cloudy.
  • Directional lightFor the virtual „sun“.
  • Point lightFor virtual lamps.
  • Spot lightVirtual spot lamps.
lights mixing light

Tutorial Page 6-17

LightsMixing Light
  • Why does an object appear in a certain color?
  • White sphere, red and blue light -> result?
lights material object

Tutorial Page 6-21

LightsMaterial Object
  • Color settings of the material object represent „reflection coefficients“.
  • Shininess is an interesting value.
lights other coloring possibilities

Tutorial Page 6-23

LightsOther Coloring Possibilities
  • No lights needed, but no „shiny“ effects:
    • ColoringAttributes
    • Per-vertex color (KickCan example: class Floor).
lights shadows
LightsShadows
  • There are no built-in shadows in Java 3D.
  • Shadows in the tutorial are created using hand-made classes and polygones.
lighting model
Lighting Model
  • Capture from the OpenGL
scenegraph light
SceneGraph(Light)

VitualUniverse object

Locale

BG

environment

BG

L

TG

scope

sphere

TG

TG

view

TG

S

S

TG

S

S

shading model
Shading Model

Flat Shading

Gouraud Shading

material
Material
  • Same as OpenGL
  • AmbientColor
  • DiffuseColor
  • SpecularColor
  • EmissiveColor
  • Shininess
9 1 ambient light
9.1. Ambient Light
  • Ambient light has the same intensity in all locations and directions
    • used as a kind of 'background' lighting in many scenes
directional light
. Directional Light
  • Provides light shining in one direction
    • often used to approximate the sun
point light
. Point Light
  • Light emitted from a point
    • the intensity changes with distance
    • often used to approximate light bulbs, candles, etc.
spotlight
SpotLight
  • Adds direction and concentration to the PointLight
lightscene in wrapchecker3d
lightScene() 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 lightAmbientLight ambientLightNode = new AmbientLight(white); ambientLightNode.setInfluencingBounds(bounds); sceneBG.addChild(ambientLightNode); :

Lights must be given

bounds in which to

operate.

slide22
// 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 :

+

z-axis

-

x-axis

-

+

+

-

viewer

y-axis

slide23
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()
making a background
Making 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.

3d shapes
3D Shapes
  • A 3D shape is defined as a Shape3D object.
  • Each Shape3D object has two node components:
    • Geometry
      • made up of coordinates (vertices)
    • Appearance
      • e.g. colour, texture, transparency,material

continued

slide26
There are several predefined shape classes in com.sun.j3d.utils.geometry:
    • Box, Sphere, Cone, Cylinder
      • we use Sphere in Checkers3D
  • Usually these classes are insufficient, and a shape's geometry must be built by connecting vertices.
shape representation
Shape Representation
  • Shape?
    • Geometry
      • How to represent geometry?
      • Polygon-based representation
    • Appearance
      • What is the appearance?
  • Shape3D class
building geometry
Building Geometry
  • The GeometryArray class is the parent for several useful geometry subclasses
geometry
Geometry

GeometryArray

GeometryStripArray

IndexedGeometryArray

shape colour
Shape 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
illuminating a shape
Illuminating 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.)
types of shape reflection
Types of Shape Reflection

specular

reflection

(white)

ambient

reflection

(blue here,

but often set

to black)

diffuse

reflection

(blue)

no shadow

no reflection

for the floor

material1
Material
  • The Material is part of a shape's Appearance node component.
  • The Material object specifies ambient, diffuse, specular, and emissive colors and a shininess value
    • emissive colour is a kind of glowing effect, but it does not illuminate other shapes
creating a material
Creating 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,shininessblueMat.setLightingEnable( true ); Appearance blueApp = new Appearance(); blueApp.setMaterial(blueMat); : // position the sphere: see later }

transfomations
Transfomations
  • A shape is transformed using a TranformGroup object.
  • The three basic transformations:
    • translation: move the shape to a new location
    • rotation: rotate the shape around the X, Y, Z axes
    • scaling: resize the shape
  • A TransformGroup object is initialised using Tranform3D objects.
translation
Translation
  • Build a shape

Shape3D myShape = new Shape3D(myGeo, myApp);

  • Translation

Transform3D t3d = new Transform3D();

t3d.set( new Vector3d(2.0, 1.0, -2.0) );

  • Create a transform group, set transform, add the shape

TransformGroup tg = new TransformGroup(t3d);

tg.addChild(myShape);

rotation
Rotation
  • Build shape

Shape3D myShape = new Shape3D(myGeo, myApp);

  • Rotation (around z-axis)

Transform3D t3d = new Transform3D();

t3d.rotZ(0.785); // rotate by 45 degrees

  • Create a transform group, set transform, add the shape

TransformGroup tg = new TransformGroup(t3d);

tg.addChild(myShape);

rotation1
Rotation

Scene Graph

We need to change just:

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;

}

Output

what about the java3d 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

What about the java3d coordinate system?

It is a right handed system,in meters.

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]

scaling
Scaling
  • Build shape

Shape3D myShape = new Shape3D(myGeo, myApp);

  • Scaling by 1.75 in X, Y, and Z

Transform3D t3d = new Transform3D();

t3d.set(1.75);

  • Create transform group, set transform, add the shape

TransformGroup tg = new TransformGroup();

tg.setTransform(t3d); // another way

tg.addChild(myShape);

composite transformations
Composite Transformations
  • Combine translations, rotations, and scaling.Methods:

void setTranslation( Vector3d vectorTranslation );

void setRotation( AxisAngle4d axisangleAxis );

void setRotation( Matrix3d matrixRotation );

void setScale( double scaleFactor );

positioning the sphere
Positioning 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()