Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford.

Slides:



Advertisements
Similar presentations
Graphics Pipeline.
Advertisements

Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
Texture Mapping. Typical application: mapping images on geometry 3D geometry (quads mesh) + RGB texture 2D (color-map) =
Week 7 - Wednesday.  What did we talk about last time?  Transparency  Gamma correction  Started texturing.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Textures II Week 8, Wed.
CSC345: Advanced Graphics & Virtual Environments
OpenGL Texture Mapping
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
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 Inf4/MSc Computer Graphics Lecture 11 Texture Mapping.
Texture Mapping A way of adding surface details Two ways can achieve the goal:  Surface detail polygons: create extra polygons to model object details.
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
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
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics Texture Mapping
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
Fundamentals of Computer Graphics Part 9 Discrete Techniques prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared.
11/11/04© University of Wisconsin, CS559 Fall 2004 Last Time Shading Interpolation Texture mapping –Barycentric coordinates for triangles.
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Texture Mapping. Example Mappings Mapping Techniques Consider the problem of rendering a sphere in the examples The geometry is very simple - a sphere.
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
ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen
Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph - SIGGraph.
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.
Texture Mapping Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
1 Texture Mapping. 2 Texture Aliasing MIPmaps Environment Mapping Bump Mapping Displacement Mapping Shadow Maps Solid Textures Antialiasing.
Texture Mapping Software College, Shandong University Instructor: Zhou Yuanfeng
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics 2 Lecture 7: Texture Mapping Benjamin Mora 1 University of Wales Swansea Pr. Min Chen Dr. Benjamin Mora.
2 COEN Computer Graphics I Evening’s Goals n Discuss displaying and reading image primitives n Describe texture mapping n Discuss OpenGL modes and.
Texture Mapping. 2 3 Loading Textures void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
Computer Graphics Bing-Yu Chen National Taiwan University.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
第三课. Overview of this Section Concept of Texture Mapping ( 纹理映射 ) 2D Texture 3D Texture Environment Mapping Bump Mapping Others OpenGL Implementation.
Texture Mapping. For Further Reading Angel 7 th Ed: ­Chapter 7: 7.3 ~ 7.9 Beginning WebGL: ­Chapter 3 2.
1 Chapter 7 Texture Mapping. 2 The Limits of Geometric Modeling Although graphics cards can render over 10 million polygons per second, that number is.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Madhulika (18010), Assistant Professor, LPU.
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
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
OpenGL Texture Mapping
Introduction to Computer Graphics with WebGL
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Chapters VIII Image Texturing
Introduction to Texture Mapping
Mipmaps Lecture 16 Mon, Oct 1, 2007.
3D Game Programming Texture Mapping
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
OpenGL Texture Mapping
Advanced Computer Graphics: Texture
Mipmaps Lecture 13 Wed, Oct 12, 2005.
Programming Textures Lecture 15 Fri, Sep 28, 2007.
Texture Mapping Ed Angel Professor Emeritus of Computer Science
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

Introduction to Texture Mapping CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford

Texture Mapping Concepts A method to create complexity in an image without the overhead of building large geometric models.

Basic Idea Application of an image onto a model An image is mapped onto the 2D domain of a 3D model Correspondence between domain of surface and texture gives method to apply image

Texture Form Textures are almost always rectangular m x n array of pixels called texels (texture elements) Textures are frequently square and of sizes that are powers of two to support downsize filtering (mipmapping) It is not necessary to always use the entire texture

Texture Coordinates A texture is usually addressed by values between zero and one The “addresses” of points on the texture consist of two numbers (s, t) A vertex can be associated with a point on the texture by giving it one of these texture coordinates glTexCoord*(s,t); glVertex*(x,y,z); Texture coords part of state like colors and normals. s t [0,0] [1, 0] [0, 1] [s,t]-space  [u,v]-space of surface  [x,y,z]-space of surface …although it is really just an array of pixels

Pixels & Texture Coordinates s t [0,0] [1, 0] [0, 1] s, t =.33,.33 For example: a 32 x 32 pixel image Glubyte mychecker[32][32][3]; glEnable(GL_TEXTURE_2D); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 32, 32, 0, GL_RGB, GL_UNSIGNED_BYTE, mychecker);

Texture Coordinates to Polygons 1,01,1 0,01,0 Texture Coordinates s, t =.33,.33  Each vertex of each polygon in assigned a texture coordinate.  OGL finds the appropriate texture coordinate for points “between” vertices during rasterization. – same idea as smooth shading!

Example domains of the 3D model Parametric surfaces come with a 2D domain. Meshes: flatten parts to create a 2D domain

Textured

Modes of Operation Decal: only the texture color determines the color we see in the frame buffer: GL_DECAL Modulation: texture color multiplies the color computed for each face (default) Blend: Similar to modulation but add alpha-blending glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)

Programming with Texture Maps 1.Create texture and load with glTexImage() by either a. read a jpeg, bmp, …. file b. define texture within application c. copy image from color buffer 2.Define parameters as to how texture is applied glTexParameter*() Next slides describe the options here…. See Table 9.6 in OGL Red Book 3.Enable texture maps glEnable(GL_TEXTURE_2D) 4.Define texture coordinates for vertices glTexCoord*(s,t); glVertex*(x,y,z);

Texture Memory Texels go into texture memory; depends on implementation – special memory or frame buffer Transfer of texels from application program to texture memory can be significant if texture large Texture memory is limited resource –proxy commands to query availability New graphics cards have MBs of texture memory Texture objects help to optimize access to textures In recent years, texturing has moved from software to high performance graphics hardware

Texture Objects When using more than one texture … Stores texture data and makes it available Fastest way to apply/bind/reuse textures Set-up similar to display lists 1. Name the texture object 2. Bind (create) texture object to texture data/properties 3. Prioritize texture object (if maxing out texture memory) 4. Bind texture object making data currently available

Texture Mapping Issues What should happen when we zoom in close or zoom out far away? How do we generate texture coordinates ? What happens if we use texture coordinates less than zero or greater than one? Are texture maps only for putting color on objects?

Texture to Surface Mapping Texture map to surface takes place during rendering Similar to smooth shading method: Triangle rasterized Each pixel mapped back to the texture Use known values at vertices to interpolation over the texture Each pixel is associated with small region of surface and to a small area of texture. 3 possibilites for association: 1) one texel to one pixel (rare) 2) magnification 3) minification Magnification one texel to many pixels Minification many texels to one pixel  Filtering

Zoom In many pixels correspond to one texel  “blockiness” / jaggies / aliasing solution: apply averaging (magnification filter)

Zoom-In: Magnification Filter Pixel cooresponds to a small portion of one texel Results in many pixels getting same texel Without a filtering method, aliasing is common Magnification filter: smooths transition between pixels pixel Texture space

Zoom-In: Magnification Filter Options for smoothing: Simplest: GL_NEAREST Just use the closest texel’s color (default – jaggies common) Also called point sampling Better: GL_LINEAR Weighted average of the four nearest texels Also called bilinear sampling (interpolation) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); (s0, t0) c0c0c1c1 c3c3 (s2, t0) Bilinear interpolation b1 = (s – s0)/(s2 – s0) b2 = (t – t0)/(t2 – t0) c = (1-b2)*( (1-b1)*c0 + b1*c1) + b2*( (1-b1)*c2 + b1*c3)

Zoom Out: Minification Filter One pixel corresponds to many texels Common with perspective foreshortening (see example on next slide) glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); Options: GL_NEAREST GL_LINEAR GL_*_MIPMAP_*_ where * = NEAREST OR LINEAR  mipmapping

Mipmap Improvements Images from the flipCode tutorial in the Resources Perspective foreshortening and poor texture mapping causes checkerboard to deform Mipmaps improve the mapping, returning more form to the checkerboard

Better Min Filter: Mipmaps “mip” stands for multum in parvo, or “many things in a small place” Basic idea: Create many textures of decreasing size and use one of these subtextures when appropriate

Mipmap Representation I Create several copies Filter down in size Pre-filter textures = mipmaps Appropriate sized texture selected based on number of pixels occupied by geometry

Mipmap Representation II Optimize storage (Schematic of method)

Mipmap Generation Must provide all sizes of texture from input to 1x1 in powers of 2 gluBuild*DMipmaps() will help with that!

Mipmap Filters In order of increasing complexity: – GL_NEAREST_MIPMAP_NEAREST – GL_LINEAR_MIPMAP_NEAREST – GL_NEAREST_MIPMAP_LINEAR – GL_LINEAR_MIPMAP_LINEAR IntermipmapIntramipmap Remember: more complexity = slower rendering

Filtering in Summary Zoom-in calls for mag filter Zoom-out calls for min filter More advanced filters require more time/computation but produce better results Mipmapping is an advanced min filter Caution: requesting mipmapping without pre-defining mipmaps will turn off texturing; (see Filtering in OGL)

Wrapping Modes: Repeat or Clamp Can assign texture coords outside of [0,1] and have them either clamp or repeat the texture map Repeat Issue: Making the texture borders match-up clamped repeat

Borders and Sizing Linear filtering needs an extra row/column of texels at the border Solution: Add a border to your texture glTexParamter3fv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color) Some help copying texel values from original texture: glTexSubImage2D() Size of texture: must be 2^n in width and height gluScaleImage() can be used to convert image to acceptable dimension

Assigning Texture Coordinates Parametric surfaces make assignment easy However, distortion of texture will occur Can minimize distortions by preserving aspect ratio of texture and geometry texture geometry Two solutions: 1) repeat texture 2) use just a portion of the texture (to match the aspect ratio)

Auto Texture Coordinate Generation GLU Quadrics: use gluQuadricTexture() to enable auto generation of textures OGL determines texture coordinates based on the distance of a vertex from a plane Plane can be defined in object or eye coordinates object: texture remains fixed wrt object eye: texture is dynamic, for example contour lines OGL determines texture coordinates based on surface normal direction – environment mapping (see “More Texture Mapping” slides) glEnable(GL_TEXTURE_GEN_S) glTexGen*(…)

Problem with Perspective Shape distortions caused by perspective maps not handled by simple interpolation of textures More advanced method glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) Also: GL_FASTEST (Other Hints for antialiasing of lines and polygons.) More advanced method - slower

1D Textures Similar to 2D texture but height = 1 Can create pattern of colors for line segments or curves Contouring Can use for Cel shading from intel

3D Textures 3D texture elements are called voxels (volume elements) Embed an object in the voxels to determine color at vertices Commonly used in medical or geoscience applications Medical: CT or MRI layered 3D data Geoscience: rock strata or gas measurements Caution: Texture memory can run out fast! Example: Uni Hamburg’s Virtual Mummy

More Mapping Methods Height maps Normal maps / Bump maps Shadow maps Environment maps …. We’ll discuss these another day!

Resources I Chapter 9 of the text –Overview, pp –Assigning Texture Coords, pp –As much of the rest of the chapter as you can handle

Resources II Fun Reading –From the SIGGRAPH tutorial pages: e_mapping_1.htm e_mapping_1.htm Texture Mapping - Advanced OpenGL Texture Mapping Texture Mapping as a Fundamental Drawing Primative