Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 9 Lighting a Scene v There are four types of lighting: –ambient light –directional light –point light –spotlight v Any number of these can be added to.

Similar presentations


Presentation on theme: "1 9 Lighting a Scene v There are four types of lighting: –ambient light –directional light –point light –spotlight v Any number of these can be added to."— Presentation transcript:

1 1 9 Lighting a Scene v There are four types of lighting: –ambient light –directional light –point light –spotlight v Any number of these can be added to a scene. v A shape must be set up to reflect light (see later).

2 2 Lights v Java 3D Lighting Model v Influence v Different Light Types v Mixing Lights v Material Objects v Other Coloring Possibilities v Shadows

3 3 Lights Objectives v Understand the Java 3D lighting system. v Know about the different ways to give a color to an object. v Recall the theory about additive light mixing. Tutorial Page 6-2

4 4 Lights Java 3D Lighting Model v There are three different reflections: –Ambient (caused by ambient light) –Diffuse („normal“ reflection) –Specular (highlight reflections of polished material) v No inter-object reflections in Java 3D. v Light sources are not visible itself. Tutorial Page 6-2

5 5 Lights Influence v There is no warning for leaving light out of a scene. v There is no warning for not setting a light source its influencing bounds. v Some light types have a attenuation setting. Tutorial Page 6-8 6-9

6 6 Lights Different Light Types v Ambient light As if the sky was cloudy. v Directional light For the virtual „sun“. v Point light For virtual lamps. v Spot light Virtual spot lamps. Tutorial Page 6-11 ff

7 7 Lights Mixing Light v Why does an object appear in a certain color? v White sphere, red and blue light -> result? Tutorial Page 6-17

8 8 Lights Material Object v Color settings of the material object represent „reflection coefficients“. v Shininess is an interesting value. Tutorial Page 6-21

9 9 Lights Other Coloring Possibilities v No lights needed, but no „shiny“ effects: –ColoringAttributes –Per-vertex color (KickCan example: class Floor). Tutorial Page 6-23

10 10 Lights Shadows v There are no built-in shadows in Java 3D. v Shadows in the tutorial are created using hand-made classes and polygones.

11 11 Lights

12 12 Lighting Model v Capture from the OpenGL

13 13 Lighting Model(scope)

14 14 SceneGraph(Light) S BG TG S S S Locale VitualUniverse object view sphere environment BG L scope TG

15 15 Shading Model Flat ShadingGouraud Shading

16 16 Material v Same as OpenGL v AmbientColor v DiffuseColor v SpecularColor v EmissiveColor v Shininess

17 17 9.1. Ambient Light v v Ambient light has the same intensity in all locations and directions – –used as a kind of 'background' lighting in many scenes

18 18. Directional Light v v Provides light shining in one direction – –often used to approximate the sun

19 19. Point Light v Light emitted from a point –the intensity changes with distance –often used to approximate light bulbs, candles, etc.

20 20 SpotLight  Adds direction and concentration to the  Adds direction and concentration to the PointLight

21 21 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 light AmbientLight ambientLightNode = new AmbientLight(white); ambientLightNode.setInfluencingBounds(bounds); sceneBG.addChild(ambientLightNode); : Lights must be given bounds in which to operate.

22 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-axis viewer + + + - - -

23 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 24 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.

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

26 26  There are several predefined shape classes in :  There are several predefined shape classes in com.sun.j3d.utils.geometry : –,,, –Box, Sphere, Cone, Cylinder  we use in  we use Sphere in Checkers3D v Usually these classes are insufficient, and a shape's geometry must be built by connecting vertices.

27 27 Shape Representation v Shape? –Geometry u How to represent geometry? u Polygon-based representation –Appearance u What is the appearance? v Shape3D class

28 28 Building Geometry  The class is the parent for several useful geometry subclasses  The GeometryArray class is the parent for several useful geometry subclasses

29 29 Geometry GeometryArray GeometryStripArray IndexedGeometryArray

30 30 Shape Colour v v You can specify a shape's colour in three ways: – –in the shape's material u u used when the scene is illuminated (as here) – –in the shape's colouring attributes u u used when the shape is unreflecting – –in the vertices of the shape's geometry u u also for unreflecting shapes

31 31 Illuminating a Shape v v A shape will reflect light when: – –the scene has lights u u set up in lightScene() – –the shape has material information u u see the next few slides – –the shape has a geometry containing normals u u done automatically in predefined shapes (Sphere, Box, etc.)

32 32 Types of Shape Reflection specular reflection (white) diffuse reflection (blue) ambient reflection (blue here, but often set to black) no shadow no reflection for the floor

33 33 Material  The is part of a shape's node component.  The Material is part of a shape's Appearance node component.  The object specifies ambient, diffuse, specular, and emissive colors and a shininess value  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

34 34 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,shininess blueMat.setLightingEnable( true ); Appearance blueApp = new Appearance(); blueApp.setMaterial(blueMat); : // position the sphere: see later }

35 35  A shape is transformed using a object.  A shape is transformed using a TranformGroup object. v 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 object is initialised using objects.  A TransformGroup object is initialised using Tranform3D objects. Transfomations

36 36 Translation v Build a shape Shape3D myShape = new Shape3D(myGeo, myApp); v Translation Transform3D t3d = new Transform3D(); t3d.set( new Vector3d(2.0, 1.0, -2.0) ); v Create a transform group, set transform, add the shape TransformGroup tg = new TransformGroup(t3d); tg.addChild(myShape);

37 37 Rotation v Build shape Shape3D myShape = new Shape3D(myGeo, myApp); v Rotation (around z-axis) Transform3D t3d = new Transform3D(); t3d.rotZ(0.785); // rotate by 45 degrees v Create a transform group, set transform, add the shape TransformGroup tg = new TransformGroup(t3d); tg.addChild(myShape);

38 38Rotation 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 39 What about the java3d coordinate system? 2 n MetersUnits 87.29Universe (20 billion light years) 69.68Galaxy (100,000 light years) 53.07Light year 43.43Solar system diameter 23.60Earth diameter 10.65Mile 9.97Kilometer 0.00Meter -19.93Micron -33.22Angstrom -115.57Planck 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]this It is a right handed system, in meters.

40 40 Scaling v Build shape Shape3D myShape = new Shape3D(myGeo, myApp); v Scaling by 1.75 in X, Y, and Z Transform3D t3d = new Transform3D(); t3d.set(1.75); v Create transform group, set transform, add the shape TransformGroup tg = new TransformGroup(); tg.setTransform(t3d); // another way tg.addChild(myShape);

41 41 Composite Transformations v Combine translations, rotations, and scaling. Methods: void setTranslation( Vector3d vectorTranslation ); void setRotation( AxisAngle4d axisangleAxis ); void setRotation( Matrix3d matrixRotation ); void setScale( double scaleFactor );

42 42 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()


Download ppt "1 9 Lighting a Scene v There are four types of lighting: –ambient light –directional light –point light –spotlight v Any number of these can be added to."

Similar presentations


Ads by Google