Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.

Slides:



Advertisements
Similar presentations
Hofstra University1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass,
Advertisements

Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping.
TEXTURE MAPPING JEFF CHASTINE 1. TEXTURE MAPPING Applying an image (or a texture ) to geometry 2D images (rectangular) 3D images (volumetric – such as.
OpenGL Texture Mapping
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Today: - Make sure everyone is set up with an OpenGL environment - OpenGL basics:
Texture Mapping CPSC /24/03 Abhijeet Ghosh.
Hofstra University1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass,
OpenGL Texture Mapping
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Lecture 12 Texture Mapping uploading of the texture to the video memory the application of the texture onto geometry.
OpenGL Texture Mapping April 16, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Basic Stragegy Three steps to applying a texture.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Texture Mapping A way of adding surface details Two ways can achieve the goal:  Surface detail polygons: create extra polygons to model object details.
Course Overview, Introduction to CG Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 5, 2003.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Advanced Texturing Methods Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 8, 2003.
Texture Mapping. To add surface details… World of Warcraft, Blizzard Inc. More polygons (slow and hard to handle small details) Less polygons but with.
Computer Graphics Texture Mapping Eriq Muhammad Adams
Linear Interpolation, Brief Introduction to OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September.
CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003.
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Textures and shadows  Generation  Mipmap  Texture coordinates,
Lecture 8: Texture Mapping 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Texture Mapping Course: Computer Graphics Presented by Fan Chen
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
Mapping method Texture Mapping Environmental mapping (sphere mapping) (cube mapping)
An Interactive Introduction to OpenGL Programming Ed Angel
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
CS 4363/6353 TEXTURE MAPPING PART II. WHAT WE KNOW We can open image files for reading We can load them into texture buffers We can link that texture.
CS 445 / 645 Introduction to Computer Graphics Lecture 19 Texture Maps Lecture 19 Texture Maps.
CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Texture Mapping Fall, Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.
Texture Mapping. 2 Motivation A typical modern graphics card can handle 10s of millions of polygons a second. How many individual blades of grass are.
OpenGL Texture Mapping. 2 Objectives Introduce the OpenGL texture functions and options.
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
More on Advanced Interfaces, Image Basics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, November 21, 2003.
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
More on Environment Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, December 10, 2003.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
2 COEN Computer Graphics I Evening’s Goals n Discuss displaying and reading image primitives n Describe texture mapping n Discuss OpenGL modes and.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
OpenGL Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
第三课. Overview of this Section Concept of Texture Mapping ( 纹理映射 ) 2D Texture 3D Texture Environment Mapping Bump Mapping Others OpenGL Implementation.
Module 05 –Bump mapping Module 05 – Bump mapping Module 05 Advanced mapping techniques: Bump mapping.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Texture Mapping Fall, 2016.
Texture Mapping We can improve the realism of graphics models by mapping a texture pattern (image) onto the modeled object surface. We refer to this technique.
OpenGL Texture Mapping
OpenGL Texture Mapping
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass, wall paper. Use.
Display Lists & Text Glenn G. Chappell
3D Game Programming Texture Mapping
OpenGL Texture Mapping
OpenGL Texture Mapping
Programming Textures Lecture 15 Fri, Sep 28, 2007.
OpenGL Texture Mapping
Presentation transcript:

Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003

1 Dec 2003CS 3812 Review: Mapping Techniques [1/3] A number of rendering techniques come under the heading of “mapping”. Mapping generally refers to color generation at the fragment level, using some kind of look-up table, indexed by properties of the fragment. Note: An image can be a look-up table, right? Mapping techniques are a way of generating complex, detailed images cheaply. “Cheaply” has two meanings here. Not very many polygons. Without much work on the part of the modeler.

1 Dec 2003CS 3813 Review: Mapping Techniques [2/3] Texture Mapping We paint an image on a polygon. Each vertex gets “texture coordinates”. These are interpolated across each polygon. A fragment’s texture coordinates are used to look up its color in an image (a “texture”). More on texture mapping later. Environment Mapping This is a type of texture mapping in which texture coordinates are generated based on the normal vector. Our texture is a picture of the scene around the object. We compute texture coordinates so as to simulate mirror-like reflection.

1 Dec 2003CS 3814 Review: Mapping Techniques [3/3] Bump Mapping Here, our look-up table holds not colors but normals. After looking up a normal, we do the usual lighting computation at the fragment level. Result: a bumpy-looking surface. With a smooth-looking silhouette.  Since OpenGL does not do per-fragment lighting, it does not support bump mapping very well. On an OpenGL-based system, bump mapping can be done by: Using a shader language. Bypassing OpenGL and rendering an image ourselves.

1 Dec 2003CS 3815 Review: Texture Mapping [1/5] Again, a texture is an image that can be painted on a polygon. Uses of Texturing Allowing images to be placed in a 3-D world. Adding “cheap” detail to a scene. Rendering objects with a realistic appearance: Skin. Bricks on walls. Wood. Stone. Etc. … Special effects: Shadowing. A scene containing a movie projector. Simulating reflections (environment mapping).

1 Dec 2003CS 3816 Review: Texture Mapping [2/5] How Texturing Works The image and geometry pipelines work together. Textures are stored in the same way as normal images. Minor restriction: Width & height must be powers of 2. Each vertex is given two sorts of coordinates: Texture coordinates. Then, ordinary vertex coordinates. Texture coordinates tell where a vertex lies in the texture. During rasterization, fragment colors are taken from the texture image.

1 Dec 2003CS 3817 Review: Texture Mapping [3/5] FragmentsVertex Pixmap Fragment Pixmap Vertex Processing Rasterization Fragment Processing Frame Buffer Vertex Data Pixel Processing Pixel Data (1) Texture enters here …(2) … and stops here. (3) Geometry [vertex coordinates + texture coordinates] enters here. (5) The color of each fragment generated depends on its texture coordinates and the color in the texture at the corresponding spot. (6) Result: textured polygon. (4) Texture coordinates accompany a vertex, but are not affected by model/view, projection.

1 Dec 2003CS 3818 Review: Texture Mapping [4/5] Texture coordinates are specified inside glBegin - glEnd pairs. Specify texture coordinates with glTexCoord *. Then, specify ordinary vertex coordinates with glVertex *. Example: glBegin(GL_TRIANGLES); glTexCoord2d(0., 0.); glVertex(2., 5.); glTexCoord2d(1., 0.); glVertex(3., 7.); glTexCoord2d(0., 1.); glVertex(1., 10.); glEnd();

1 Dec 2003CS 3819 Review: Texture Mapping [5/5] Texture coordinates are not transformed by the model/view, projection, and viewport transformations. However, they do pass through the texture transformation. This transformation is handled just like model/view and projection. Matrix mode is GL_TEXTURE.

1 Dec 2003CS Details of Texture Mapping: Introduction & Notes Now we look at texturing in more detail. Resources: Sample code is on the web page ( simpletexture.cpp, texture.cpp ). You may also want to look at the red book, chapter 9. The designers of OpenGL revised texturing in the 1.1 release. We will discuss the revised interface. Thus, our sample code will not work under OpenGL 1.0. We will concentrate on 2-D texturing. OpenGL actually supports 1-D, 2-D, and 3-D textures. 3-D textures require OpenGL 1.2 or later. Or extensions to OpenGL D & 3-D are handled similarly to 2-D.

1 Dec 2003CS Details of Texture Mapping: Overview Topics Initializing textures (brief summary). Details of texture initialization: Using texture objects. Creation. Binding. Setting Texture-Related States. Function glTexParameter *. Function glTexEnv *. Telling OpenGL about a texture: glTexImage2D. Drawing with a texture.

1 Dec 2003CS Details of Texture Mapping: Initializing Textures To initialize textures (in the init function?): Put the image(s) into an array or arrays. Use glPixelStore * to set unpack alignment, if required. This is just like what you did with glDrawPixels, except that the array dimensions must be powers of 2. Create a texture object or objects. Use glGenTextures and glBindTexture. These work much like display lists. This is not actually needed if there is only one texture, but it simplifies things if & when you add a second texture. Indicate the properties of the texture object. Use glTexParameter * & glTexEnv * to set various states. Use glTexImage2D to turn the array data into a texture.

1 Dec 2003CS Details of Texture Mapping: Texture Objects — Creation Texture objects are not needed if there is only one texture. But use them anyway. Texture objects are created using glGenTextures. Parameters: Number of texture names to create. Array of GLuint ’s (or GLuint * ) to hold the names. Example Globals: const int num_textures = 7; // Number of textures GLuint texnames[num_textures]; In init function: glGenTextures(num_textures, texnames);

1 Dec 2003CS Details of Texture Mapping: Texture Objects — Binding To use a texture object, we bind it to a target. Target = GL_TEXTURE_2D when we use 2-D textures. Something like this: glBindTexture(GL_TEXTURE_2D, texnames[2]); After this, we refer to the texture by its target. All references to the target actually refer to the named texture object. So, if you have just one texture, then generate one name, bind it, and forget about it. If you have multiple textures: Generate all the names. For each texture, bind it, then initialize it. Just before using a texture (in display routine), bind it.

1 Dec 2003CS Details of Texture Mapping: States — glTexParameter * The most important command for setting texture-related states is glTexParameter *. We mainly use glTexParameteri. See simpletexture.cpp and texture.cpp for examples. The “wrap” parameters determine what happens when a texture coordinate is greater than 1 or less than 0. Coordinates are s and t. Use GL_REPEAT to repeat the image again: from 1 to 2, 2 to 3, etc. Using GL_CLAMP means coordinates greater than 1 are set to 1; coordinates less than 0 are set to 0. The “mag filter” and “min filter” parameters determine what happens when a texture lookup does not hit a texel exactly. Use GL_NEAREST to get the color of the nearest texel. Use GL_LINEAR to lirp between texel colors. Look in the doc’s for glTexParameter * for more.

1 Dec 2003CS Details of Texture Mapping: States — glTexEnv * Another function for setting texture states is glTexEnv *. It determines how the color in a texture image affects the color of a fragment. We will call it as follows: glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, parameter_value ); Options for parameter_value above: Option GL_REPLACE does the obvious thing: the fragment color is the color is what is read from the texture image. Option GL_MODULATE multiplies the texture image color by the color from the geometry pipeline to get the fragment color. Look in the doc’s for glTexEnv * for more.

1 Dec 2003CS Details of Texture Mapping: Using glTexImage2D [1/3] We tell OpenGL about the texture itself using glTexImage2D. This command deals with an image in an array, just like glDrawPixels and glReadPixels. So it needs the same 5 parameters to describe the image array. Width, height, format (RGB, RGBA, etc.), type ( GLubyte ?), pixels (pointer to array). Once we have called glTexImage2D, OpenGL is done with our array. So we can reuse it for another texture. There is also glTexImage1D and (in OpenGL 1.2 or later) glTexImage3D. These work much the same as the 2-D version.

1 Dec 2003CS Details of Texture Mapping: Using glTexImage2D [2/3] Function glTexImage2D has 9 parameters: Target: must be GL_TEXTURE_2D. I do not know the reason for this redundancy. Level: Use zero … … unless you are giving the image data in multiple resolutions (read about it in the Red Book). Components: What to do with the data ( GL_RGB or GL_RGBA ). Width: image width, as in glDrawPixels. Height: image height, as in glDrawPixels. Border: Use zero … … unless the image has a border (read about it in the Red Book). Format: as in glDrawPixels ( GL_RGB or GL_RGBA ). Type: as in glDrawPixels ( GL_UNSIGNED_BYTE, probably). Pixels: pointer to image data, as in glDrawPixels.

1 Dec 2003CS Details of Texture Mapping: Using glTexImage2D [3/3] Summary: Your call to glTexImage2D will look like this, unless you are feeling brave: glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, // GL_RGBA if alpha stored in array img_width, img_height, 0, GL_RGB, // GL_RGBA if alpha stored in array GL_UNSIGNED_BYTE, the_image); // <-- Name of your array here

1 Dec 2003CS Details of Texture Mapping: Drawing With a Texture To use a texture (in the display function): Enable the texture. Do glEnable(GL_TEXTURE_2D); If you have multiple textures, you may also need to call glBindTexture, to specify which texture to use. When you draw, specify texture coordinates. Do glTexCoord2 * before each glVertex *. The call to glTexCoord * must come before glVertex *. Reason: glVertex * triggers the sending of vertex data to the pipeline. Only states set before this call affect the data that is sent. If you are going to draw something without texturing (like text instructions?), disable the texture. Do glDisable(GL_TEXTURE_2D);