CS 445 / 645 Introduction to Computer Graphics Lecture 19 Texture Maps Lecture 19 Texture Maps.

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.
Komputer Grafik 2 (AK045206) Pemetaan Tekstur 1/35 Pemetaan Tekstur.
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
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Textures II Week 8, Wed.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Textures I Week 8, Mon.
Texture Mapping CPSC /24/03 Abhijeet Ghosh.
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.
CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps.
Texture Mapping A way of adding surface details Two ways can achieve the goal:  Surface detail polygons: create extra polygons to model object details.
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
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. Example Mappings Mapping Techniques Consider the problem of rendering a sphere in the examples The geometry is very simple - a sphere.
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
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 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.
CS 551 / CS 645 Texture Maps. Assignment 2 Let’s talk about ‘working together’ –No sharing code unless specifically allowed (and documented in README)
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.
Texture Mapping in OpenGL. Texture Mapping Imaging we are “pasting” a picture onto a model  Which part of the picture will be pasted onto which part.
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CHAPTER 8 Color and Texture Mapping © 2008 Cengage Learning EMEA.
CG Summary: OpenGL Shading andTextures Angel, Chapters 5, 7; “Red Book” slides from AW, red book, etc. CSCI 6360/4360.
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
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,
CS 445 / 645 Introduction to Computer Graphics Lecture 19 Texture Maps Lecture 19 Texture Maps.
Texture Mapping CAP4730: Computational Structures in Computer Graphics.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
CS 325 Introduction to Computer Graphics 04 / 12 / 2010 Instructor: Michael Eckmann.
OpenGL Graphics Textures. Quiz You didn't see that coming!
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.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
Textures – Basic Principles Lecture 29 Fri, Nov 14, 2003.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2010 Tamara Munzner Textures I Week 9, Fri.
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.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Texture Mapping Fall, 2016.
OpenGL Texture Mapping
texturing a parametric surface
OpenGL Texture Mapping
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Introduction to Computer Graphics with WebGL
© University of Wisconsin, CS559 Fall 2004
Introduction to Texture Mapping
Geb Thomas Adapted from the OpenGL Programming Guide
3D Game Programming Texture Mapping
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
OpenGL Texture Mapping
Programming Textures Lecture 15 Fri, Sep 28, 2007.
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

CS 445 / 645 Introduction to Computer Graphics Lecture 19 Texture Maps Lecture 19 Texture Maps

Texture Mapping Limited ability to generate complex surfaces with geometry Images can convey the illusion of geometry Images painted onto polygons is called texture mapping Limited ability to generate complex surfaces with geometry Images can convey the illusion of geometry Images painted onto polygons is called texture mapping

Texture Maps Chapter 9 of Open GL Programming Guide (Red Book) Images applied to polygons to enhance the visual effect of a scene Rectangular arrays of dataRectangular arrays of data –Color, luminance, alpha –Components of array called texels  Or in 3D, volumetric voxels Chapter 9 of Open GL Programming Guide (Red Book) Images applied to polygons to enhance the visual effect of a scene Rectangular arrays of dataRectangular arrays of data –Color, luminance, alpha –Components of array called texels  Or in 3D, volumetric voxels

Texture Mapping Texture map is an image, two-dimensional array of color values (texels) Texels are specified by texture’s (u,v) space At each screen pixel, texel can be used to substitute a polygon’s surface property (color) We must map (u,v) space to polygon’s (s, t) space Texture map is an image, two-dimensional array of color values (texels) Texels are specified by texture’s (u,v) space At each screen pixel, texel can be used to substitute a polygon’s surface property (color) We must map (u,v) space to polygon’s (s, t) space U V S T

Texture Mapping (u,v) to (s,t) mapping can be explicitly set at vertices by storing texture coordinates with each vertex How do we compute (u,v) to (s,t) mapping for points in between Watch for aliasingWatch for aliasing Watch for many to one mappingsWatch for many to one mappings Watch for perspective foreshortening effects and linear interpolationWatch for perspective foreshortening effects and linear interpolation (u,v) to (s,t) mapping can be explicitly set at vertices by storing texture coordinates with each vertex How do we compute (u,v) to (s,t) mapping for points in between Watch for aliasingWatch for aliasing Watch for many to one mappingsWatch for many to one mappings Watch for perspective foreshortening effects and linear interpolationWatch for perspective foreshortening effects and linear interpolation

Example Texture Map Applied to tilted polygon

Example Texture Map glVertex3d (s, s, s) glTexCoord2d(1,1); glVertex3d (-s, -s, -s) glTexCoord2d(0, 0);

Example Texture Map glVertex3d (s, s, s) glTexCoord2d(5, 5); glVertex3d (s, s, s) glTexCoord2d(1, 1); Repeating textures vs. Clamped textures

Texture Coordinates Every polygon can have object coordinates and texture coordinates Object coordinates describe where polygon vertices are on the screenObject coordinates describe where polygon vertices are on the screen Texture coordinates describe texel coordinates of each vertex (usually 0 -> 1)Texture coordinates describe texel coordinates of each vertex (usually 0 -> 1) Texture coordinates are interpolated along vertex-vertex edgesTexture coordinates are interpolated along vertex-vertex edges glTexCoord{1234}{sifd}(TYPE coords) Every polygon can have object coordinates and texture coordinates Object coordinates describe where polygon vertices are on the screenObject coordinates describe where polygon vertices are on the screen Texture coordinates describe texel coordinates of each vertex (usually 0 -> 1)Texture coordinates describe texel coordinates of each vertex (usually 0 -> 1) Texture coordinates are interpolated along vertex-vertex edgesTexture coordinates are interpolated along vertex-vertex edges glTexCoord{1234}{sifd}(TYPE coords) Why 1  4 coords? s, t, r, and q (for homogeneous coordinates, an advanced topic)

Textures Texture Object An OpenGL data type that keeps textures resident in memory and provides identifiers to easily access themAn OpenGL data type that keeps textures resident in memory and provides identifiers to easily access them Provides efficiency gains over having to repeatedly load and reload a textureProvides efficiency gains over having to repeatedly load and reload a texture You can prioritize textures to keep in memoryYou can prioritize textures to keep in memory OpenGL uses least recently used (LRU) if no priority is assignedOpenGL uses least recently used (LRU) if no priority is assigned Texture Object An OpenGL data type that keeps textures resident in memory and provides identifiers to easily access themAn OpenGL data type that keeps textures resident in memory and provides identifiers to easily access them Provides efficiency gains over having to repeatedly load and reload a textureProvides efficiency gains over having to repeatedly load and reload a texture You can prioritize textures to keep in memoryYou can prioritize textures to keep in memory OpenGL uses least recently used (LRU) if no priority is assignedOpenGL uses least recently used (LRU) if no priority is assigned

Example use of Texture Read.bmp from file Use Image data typeUse Image data type –getc() and fseek() to read image x & y size –fread() fills the Image  data memory with actual red/green/blue values from.bmp NoteNote –malloc() Image->data to appropriate size –.bmp stores color in bgr order and we convert to rgb order Read.bmp from file Use Image data typeUse Image data type –getc() and fseek() to read image x & y size –fread() fills the Image  data memory with actual red/green/blue values from.bmp NoteNote –malloc() Image->data to appropriate size –.bmp stores color in bgr order and we convert to rgb order

Step 2 – create Texture Objects glGenTextures(1, &texture[texture_num]); First argument tells GL how many Texture Objects to createFirst argument tells GL how many Texture Objects to create Second argument is a pointer to the place where OpenGL will store the names (unsigned integers) of the Texture Objects it createsSecond argument is a pointer to the place where OpenGL will store the names (unsigned integers) of the Texture Objects it creates –texture[ ] is of type GLuint glGenTextures(1, &texture[texture_num]); First argument tells GL how many Texture Objects to createFirst argument tells GL how many Texture Objects to create Second argument is a pointer to the place where OpenGL will store the names (unsigned integers) of the Texture Objects it createsSecond argument is a pointer to the place where OpenGL will store the names (unsigned integers) of the Texture Objects it creates –texture[ ] is of type GLuint

Step 3 – Specify which texture object is about to be defined Tell OpenGL that you are going to define the specifics of the Texture Object it created glBindTexture(GL_TEXTURE_2D, texture[texture_num]);glBindTexture(GL_TEXTURE_2D, texture[texture_num]); –Textures can be 1D and 3D as well Tell OpenGL that you are going to define the specifics of the Texture Object it created glBindTexture(GL_TEXTURE_2D, texture[texture_num]);glBindTexture(GL_TEXTURE_2D, texture[texture_num]); –Textures can be 1D and 3D as well

Step 4 – Begin defining texture glTexParameter() Sets various parameters that control how a texture is treated as it’s applied to a fragment or stored in a texture objectSets various parameters that control how a texture is treated as it’s applied to a fragment or stored in a texture object // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);// scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image smaller than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smaller than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexParameter() Sets various parameters that control how a texture is treated as it’s applied to a fragment or stored in a texture objectSets various parameters that control how a texture is treated as it’s applied to a fragment or stored in a texture object // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);// scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image smaller than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smaller than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

Step 5 – Assign image data glTexImage2D();glTexImage2D(); GL_TEXTURE_2D (2D Texture) 0 (level of detail 0) 3 (3 components, RGB) image1->sizeX(size) image1->sizeY(size) 0 (no border pixel) GL_RGB (RGB color order) GL_UNSIGNED_BYTE (unsigned byte data) image1->data (pointer to the data))

glTexImage2D – Arg 1 GLenum target GL_TEXTURE_{1|2|3}DGL_TEXTURE_{1|2|3}D GL_PROXY_TEXTURE_2DGL_PROXY_TEXTURE_2D –Provides queries for texture resources –Proceed with hypothetical texture use (GL won’t apply the texture) –After query, call GLGetTexLevelParamter to verify presence of required system components –Doesn’t check possibility of multiple texture interference GLenum target GL_TEXTURE_{1|2|3}DGL_TEXTURE_{1|2|3}D GL_PROXY_TEXTURE_2DGL_PROXY_TEXTURE_2D –Provides queries for texture resources –Proceed with hypothetical texture use (GL won’t apply the texture) –After query, call GLGetTexLevelParamter to verify presence of required system components –Doesn’t check possibility of multiple texture interference

glTexImage2D – Arg 2 GLint level Used for Level of Detail (LOD)Used for Level of Detail (LOD) LOD stores multiple versions of texture that can be used at runtime (set of sizes)LOD stores multiple versions of texture that can be used at runtime (set of sizes) Runtime algorithms select appropriate version of textureRuntime algorithms select appropriate version of texture –Pixel size of polygon used to select best texture –Eliminates need for error-prone filtering algorithms GLint level Used for Level of Detail (LOD)Used for Level of Detail (LOD) LOD stores multiple versions of texture that can be used at runtime (set of sizes)LOD stores multiple versions of texture that can be used at runtime (set of sizes) Runtime algorithms select appropriate version of textureRuntime algorithms select appropriate version of texture –Pixel size of polygon used to select best texture –Eliminates need for error-prone filtering algorithms

glTexImage2D – Arg 3 GLint internalFormat GL defines 38 symbolic constants that describe which of R, G, B, and A are used in internal representation of texelsGL defines 38 symbolic constants that describe which of R, G, B, and A are used in internal representation of texels Provides control over things texture can doProvides control over things texture can do –High bit depth alpha blending –High bit depth intensity mapping –General purpose RGB GL doesn’t guarantee all options are available on given hardwareGL doesn’t guarantee all options are available on given hardware GLint internalFormat GL defines 38 symbolic constants that describe which of R, G, B, and A are used in internal representation of texelsGL defines 38 symbolic constants that describe which of R, G, B, and A are used in internal representation of texels Provides control over things texture can doProvides control over things texture can do –High bit depth alpha blending –High bit depth intensity mapping –General purpose RGB GL doesn’t guarantee all options are available on given hardwareGL doesn’t guarantee all options are available on given hardware

glTexImage2D – Args 4-6 GLsizei width GLsizei height Dimensions of texture imageDimensions of texture image –Must be 2 m + 2b (b=0 or 1 depending on border) –min, 64 x 64 GLint border Width of border (1 or 0)Width of border (1 or 0) –Border allows linear blending between overlapping textures –Useful when manually tiling textures GLsizei width GLsizei height Dimensions of texture imageDimensions of texture image –Must be 2 m + 2b (b=0 or 1 depending on border) –min, 64 x 64 GLint border Width of border (1 or 0)Width of border (1 or 0) –Border allows linear blending between overlapping textures –Useful when manually tiling textures

glTexImage2D – Args 7 & 8 GLenum format Describe how texture data is stored in input arrayDescribe how texture data is stored in input array –GL_RGB, GL_RGBA, GL_BLUE… GLenum type Data size of array componentsData size of array components –GL_SHORT, GL_BYTE, GL_INT… GLenum format Describe how texture data is stored in input arrayDescribe how texture data is stored in input array –GL_RGB, GL_RGBA, GL_BLUE… GLenum type Data size of array componentsData size of array components –GL_SHORT, GL_BYTE, GL_INT…

glTexImage2D – Arg 9 Const GLvoid *texels Pointer to data describing texture mapPointer to data describing texture map Const GLvoid *texels Pointer to data describing texture mapPointer to data describing texture map

Step 6 – Apply texture Before defining geometry glEnable(GL_TEXTURE_2D);glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[0]);glBindTexture(GL_TEXTURE_2D, texture[0]); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); Before defining geometry glEnable(GL_TEXTURE_2D);glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[0]);glBindTexture(GL_TEXTURE_2D, texture[0]); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glTexEnv() GL_TEXTURE_ENV_MODE GL_DECAL (alpha blends texture with poly color) GL_REPLACE (straight up replacement) GL_MODULATE (texture application is a function of poly lighting) GL_BLEND (texture controls blending with another color) If GL_BLEND selected, second call to glTexEnv() must specify GL_TEXTURE_ENV_COLOR 4-float array for R,G,B,A blend First argument to function is always GL_TEXTURE_ENV