Download presentation
Presentation is loading. Please wait.
1
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Lighting and Texturing F To understand lighting models F To identify point lights, directional lights and spotlights F To identify material properties F To understand Java 3D coloring modes F To create lit scenes with lights, surface normals and materials F To construct and apply fog nodes for atmospheric attenuation and depth cueing F To apply 2D texture mapping and texture cube mapping F To understand texture coordinate generation
2
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 2 Realistic Rendering F Creating photorealistic appearance can be computationally intensive F Improve appearance with –more sophisticated models for lighting and shading –atmospheric attenuation (fog) –texture mapping u create surface detail without expensive modeling
3
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 3 Lighting F Real images are formed by light which is emitted, reflected, refracted and scattered by objects in its path F The process is complex –lights have different characteristics –objects interact with the light differently F Simplified illumination models achieve reasonably realistic results
4
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 4 Types of Lights F Ambient light –uniform in all directions and locations F Directional light –models a distant light source whose rays are all parallel
5
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 5 Types of Lights F Point light –light located at a particular loacion which emits in all directions –Intensity decreases with distance F Spot light –Like a point source except the direction of the emission is restricted
6
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 6 Light Classes
7
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 7 Properties of Lights F Lights can have a color associated with them F DirectionalLight needs a Vector to specify the direction F PointLight needs a position and an attenuation coefficient (0-1) F SpotLight also needs a spread angle and have attenuation factor across the cone
8
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 8 Light Methods F Turn lights on and off with void setEnable( boolean state) F Lights need to have bounds void setInfluencingBounds( Bounds bounds) void setInfluencingBoundingLeaf( BoundingLeaf bounds)
9
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 9 Attenuation F Attenuation of point and spot lights defined by quadratic equation A(d) = 1/(a 0 + a 1 d +a 2 d 2 ) –Use a Point3f to specify the coefficients F Attenuation due to angle between light ray and center of cone of spot light is exponential –A( ) = cos n void setConcentration( float concentration)
10
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 10 TestLights F Five lights which can be turned on and off –Red ambient light –Green directional light with direction (0, 1, 0) –White point light at (-0.7, 0.7, 0) with no attenuation –Blue spot light at (0.7, 0.7, 0.7) pointing in (- 0.7, -0.7, -0.7) direction with /6 spread angle –Orange spot light at (0.7, 0.7, -0.7) pointing at (-0.7, -0.7, -0.7) with /12 spread angle and concentration of 128
11
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 11 Illumination F How does light interact with the objects in a scene F Truly accurate model would be very complicated –non-local effects –ray tracing, radiosity F In practice use a computationally efficient model –Phong model
12
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 12 Geometry of Reflection F For perfectly reflective surface –angle of incidence = angle of reflection –no loss of intensity F In reality surfaces aren't perfect –light gets scattered –light can be absorbed
13
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 13 Illumination Models F Model reflection as coming from three sources F Specular reflection –true reflection F Ambient reflection –independent of direction –independent of surface normal F Diffuse reflection –reflection from imperfect surfaces –intensity depends on incidence angle but not viewing angle –makes up most of what we see
14
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 14 Phong Illumination Model F Commonly used illumination model F Intensity computed from equation I = I a k a + I p k d cos + I p k s cos n –k a, k d, k s are coefficients for ambient, diffuse and specular reflection for a particular material –n is the shininess coefficient, also a property of the material F Total intensity includes contributions from each light source
15
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 15 Illumination in Java3D F Phong model is supported F Objects which are lit are rendered using this model F Appearance of objects depends on both the lights and the material properties F Rules for coloring objects are set up so that can have some objects lit and some not
16
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 16 Java 3D Coloring Rules F If the vertex colors are specified in the geometry of the object, the vertex colors are used to define the object coloring. F If a Material node component is defined for the object, the object is lit. The coloring of the object is defined by the lighting model. F If the ColoringAttributes is defined for the appearance of the object, its color is used for the coloring of the object. F Otherwise, the object is colored white.
17
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 17 To Enable Lighting F Place lights in the scene graph. F Provide surface normals for the geometry and do not set vertex colors. F Set material for the appearance.
18
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 18 Appearance F Node component which has components that control various aspects of the appearance of an object. –ColoringAttributes, RenderingAttributes, TransparencyAttributes –PointAttributes, LineAttributes, PolygonAttributes –Material –TextureAttributes, Texture, TexCoordGeneration, TextureUnitState
19
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 19 Material F If the Material of an Appearance is set, it enables lighting for the object by default F Contains components to control the color contributed by different kinds of lighting –ambient, diffuse, specular –can also contain an emissive color component F Shininess coefficient affects specular reflection F Color target for per-vertex colors
20
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 20 Material Constructors F Default –lighting is enabled –ambient color (.2,.2,.2) –emmisive color (0,0,0) –diffuse color = specular color (1,1,1) –shininess 64 –color target DIFFUSE F Complete constructor has 5 parameters –Color3f ambient color –Color3f emissive color –Color3f diffuse color –Color3f specular color –float shininess (1-128)
21
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 21 Material Methods F Enable/disable lighting void setLightingEnabled( boolean) F Set methods for each color void set…Color ( Color3f) void set…Color ( float r, float g, float b) F Set method for shininess void setShininess ( float n)
22
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 22 Some Example Materials SurfaceDiffuse = Ambient SpecularShininess Aluminum.37.37.37.89.89.8917 Blue Plastic.2.2.7.85.85.8522 Copper.3.1 0.75.3 010 Gold.49.34 0.89.79 017 Red Alloy.34 0.34.84 0 015 Black onyx0 0 0.72.72.7223
23
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 23 Lighting.java F Displays eight spheres illuminated by a point light F Each sphere has different material properties –all have same diffuse reflection coefficient –shininess exponent goes from 1 to 41
24
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 24 Atmospheric Attenuation F In real life –Close objects appear to be sharp and clear –Far away objects are fuzzy F This effect is most pronounced on a foggy day F In computer graphics, simulate these effects using depth cueing
25
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 25 Depth Cueing F Atmospheric attenuation effects can be simulated with depth cueing F Blend the objects with background color (or with arbitrary fog color) C = f C 0 + (1 - f) C f F Blending is an increasing function of the distance –linear –exponential –gaussian
26
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 26 Fog Classes F Fog is an abstract class –Leaf node F LinearFog –back and front are limits of fog effect F ExponentialFog –density parameter controls rate of decrease of fog function
27
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 27 Constructors LinearFog() LinearFog( Color3f) LinearFog( Color3f, double, double) ExponentialFog() ExponentialFog( Color3f) ExponentialFog( Color3f, float)
28
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 28 TestFog.java F Displays array of Dodecahedrons F Uses LinearFog –front = 2 –back = 4
29
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 29 Texture Mapping F Real surfaces often have a large amount of detail F Use a digital image to provide complex detail with minimal computational cost F Procedural textures use a function to calculate the color at any given point
30
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 30 Texture Mapping F Map an image to the surface of an object –Texel = point in image –Pixel = point on object F Image has its own coordinate system F Specify the mapping by giving each vertex of the surface the image coordinate of the corresponding texel –Texel coordinates for other pixels are interpolated
31
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 31 Texture Mapping F Magnification - pixel corresponds to part of a texel F Minification - pixel corresponds to several texels
32
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 32 Magnification and Minification F Mapping between pixels and texels is not one-to-one F Need rules (called filters) to specify how to get texture values –select nearest texel –interpolate linearly between neighboring texels
33
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 33 Texture Mapping in Java3D F Texture mapping needs –Texture coordinates for vertices of the geometry. Use TEXTURE_COORDINATE_2 flag to specify that there are 2 texture coordinates texture coordinates –Texture object in the appearance bundle. Appearance ap = new Appearance(); ap.setTexture( texture);
34
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 34 Texture Classes F Texture is an abstract subclass of Node F There are three classes for texture coordinates F TexCoord2f F TexCoord3f F TexCoord4f
35
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 35 Texture2D F Texture2D is subclass of NodeComponent F Contains a reference to an ImageComponent2D public void setImage( int index, ImageComponent2D)
36
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 36 ImageComponent2D F Can use either a BufferedImage or a RendredImage public void set( BufferedImage bi) public void set( RenderedImage ri) F See examples from Chapter for to see how to create a BufferedImage
37
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 37 TextureLoader F Utility class for loading texture images TextureLoader loader = new TextureLoader( filename, this); F Can retrieve a Texture Texture texture = loader.getTexture(); F Or retrieve an image ImageComponent2D img = loader.getImage(); Texture2D tex2d = new Texture2D(); tex2d.setImage( 0, img)
38
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 38 TextureMapping.java F Shows a texture-mapped globe F Sphere is created with texture coordinates by specifying in constructor –Primitive.GENERATE_TEXTURE_COORDS F Magnification and minification filters set to linear interpolation
39
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 39 Texture Coordinates F Texture coordinates define locations in an image –Texture coordinate is 2D vector (u,v) where u and v go from 0 to 1 F TexCoord2f class defines 2D texture coordinates
40
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 40 CubeTexture.java F Map the image below to the faces of a cube
41
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 41 Texture Mapping and Lighting F Lighting and texture mapping may be combined (see Cup.java) F TextureAttributes class controls options of texture mapping –set to combine colors from texture and lights TextureAttributes texatt = new TextureAttributes(); texatt.setTextureMode(TextureAttributes.COMBINE); appearance.setTextureAttributes(texatt);
42
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 42 TextureCoordinate Generation F Texture coordinates do not have to be specified in the Geometry –They can be generated automatically F TexCoordGeneration class is a NodeComponent which contains parameters for automatic texture coordinate generation
43
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 43 Types of Textures F With a 1D array of color values, you can use a single coordinate to create stripes and gradients F 2D coordinates allow you to map an image F 3D coordinates allow you to use Volume textures
44
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 44 Texture Coordinates F There are three types texture coordinate classes –TexCoord2f - texture is an image so only need 2 coordinates ( –TexCoord3f - for some kinds of textures (wood grain e.g.) the texture needs to be 3-dimensional so three coordinates (x,y,z) are needed –TexCoord4f - uses 4 coordinates F The TexCoord classes extend the corresponding Tuple classes
45
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 45 Texture Formats F Texture format specifies the number of components for each Texture coordinate –TEXTURE_COORDINATE_2 –TEXTURE_COORDINATE_3 –TEXTURE_COORDINATE_4
46
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 46 Texture Generation Mode F Describes how the coordinates are generated –OBJECT_LINEAR - use object coordinates –EYE_LINEAR - use eye coordinates –SPHERE_MAP - simulate spherical reflections based on eye coordinates –For TextureCube mapping also have u NORMAL_MAP u REFLECTION_MAP
47
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 47 TextureCubeMap F A Texture that uses a set of 6 images representing the six faces of a cube F Each image mapped to a particular side of the object F Constants representing different faces of cube –NEGATIVE_X –NEGATIVE_Y –NEGATIVE_Z –POSITIVE_X –POSITIVE_Y –POSITIVE_Z
48
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 48 CubeTexture.java
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.