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.

Slides:



Advertisements
Similar presentations
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
Advertisements

CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 6.
CSPC 352: Computer Graphics
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1 Computer Graphics By : Mohammed abu Lamdy ITGD3107 University of Palestine Supervision: Assistant Professor Dr. Sana’a Wafa Al-Sayegh.
Lighting and Illumination Lighting is the major problem in computer graphics, for either realism or real-time compositions- harder than modeling Consider.
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
Week 9 - Wednesday.  What did we talk about last time?  Fresnel reflection  Snell's Law  Microgeometry effects  Implementing BRDFs  Image based.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shading I.
University of New Mexico
Computer Graphics - Class 10
IMGD 1001: Illumination by Mark Claypool
Lighting and Shading Wen-Chieh (Steve) Lin
3/23/2005 © Dr. Zachary Wartell 1 Illumination Models and Surface- Rendering Methods.
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
7M836 Animation & Rendering
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
Illumination and Shading
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Course Website: Computer Graphics 16: Illumination.
CHAPTER 9 Lighting © 2008 Cengage Learning EMEA. LEARNING OBJECTIVES In this chapter you will learn about: – –Light sources – –Point lights – –Spotlights.
LIGHTING Part One - Theory based on Chapter 6. Lights in the real world Lights bounce off surfaces and reflect colors, scattering light in many directions.
Shading Surface can either (both) 1.Emit light. E.g. light bult 2.Reflect light. E.g. Mirror.
CS 480/680 Computer Graphics Shading I Dr. Frederick C Harris, Jr.
Computer Graphics Inf4/MSc Computer Graphics Lecture 11 Texture Mapping.
SET09115 Intro Graphics Programming
CS 445 / 645: Introductory Computer Graphics
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
1 Review of COMPSCI 221  Chapters 1-11 in text  User Interfaces will be addressed as a take- home question.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shading (introduction to rendering). Rendering  We know how to specify the geometry but how is the color calculated.
COMPUTER GRAPHICS CS 482 – FALL 2014 AUGUST 27, 2014 FIXED-FUNCTION 3D GRAPHICS MESH SPECIFICATION LIGHTING SPECIFICATION REFLECTION SHADING HIERARCHICAL.
CS324e - Elements of Graphics and Visualization Checkerboard World.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
Shading 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
CSC418 Computer Graphics n Illumination n Lights n Lightinging models.
1 Virtual Reality Modeling Language (VRML97) ©Anthony Steed
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
Steve Sterley. Real World Lighting Physical objects tend to interact with light in three ways: Absorption (black body) Reflection (mirror) Transmission.
CSE 381 – Advanced Game Programming GLSL Lighting.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Illumination and Shading
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Course Introduction to virtual engineering Óbuda University John von Neumann Faculty of Informatics Institute of Applied Mathematics Lecture and laboratory.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Lighting and Texturing.
UV Mapping After a 3D object has been modeled it must be prepared for texturing. 3D surfaces can be “unwrapped” into a 2D representation with. This process.
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.
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
In the name of God Computer Graphics. Where We Stand So far we know how to: –Transform between spaces –Draw polygons Next –Deciding a pixel’s intensity.
OpenGL Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
Illumination Models. Introduction 1 Illumination model: Given a point on a surface, what is the perceived color and intensity? Known as Lighting Model,
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
Computer Graphics: Illumination
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
CHAPTER 9 Lighting © 2008 Cengage Learning EMEA.
Isaac Gang University of Mary Hardin-Baylor
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Computer Graphics Material Colours and Lighting
CS 480/680 Computer Graphics Shading.
Presentation transcript:

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

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

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

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

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

Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 6 Light Classes

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

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)

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)

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

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

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

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

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

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

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.

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.

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

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

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)

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)

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 Blue Plastic Copper Gold Red Alloy Black onyx

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

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

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

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

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)

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

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

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

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

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

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);

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

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)

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

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)

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

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

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

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);

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

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

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

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

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

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

Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 48 CubeTexture.java