cs 445 / 645 introduction to computer graphics lecture 17 texture maps lecture 17 texture maps

38
CS 445 / 645 Introduction to Computer Graphics Lecture 17 Lecture 17 Texture Maps Texture Maps

Upload: ross-mccarthy

Post on 23-Dec-2015

224 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

CS 445 / 645Introduction to Computer Graphics

Lecture 17Lecture 17

Texture MapsTexture Maps

Lecture 17Lecture 17

Texture MapsTexture Maps

Page 2: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Texture Mapping

Limited ability to generate complex surfaces with Limited ability to generate complex surfaces with geometrygeometry

Images can convey the illusion of geometryImages can convey the illusion of geometry

Images painted onto Images painted onto polygons is called texture polygons is called texture mappingmapping

Limited ability to generate complex surfaces with Limited ability to generate complex surfaces with geometrygeometry

Images can convey the illusion of geometryImages can convey the illusion of geometry

Images painted onto Images painted onto polygons is called texture polygons is called texture mappingmapping

Page 3: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Texture Maps

Chapter 9 of Open GL Programming Guide (Red Chapter 9 of Open GL Programming Guide (Red Book)Book)

Images applied to polygons to enhance the visual Images applied to polygons to enhance the visual effect of a sceneeffect of a scene• Rectangular arrays of dataRectangular arrays of data

– Color, luminance, Color, luminance, alphaalpha

– Components of array called Components of array called texelstexels

We’ve also had volumetricWe’ve also had volumetric voxels voxels

Chapter 9 of Open GL Programming Guide (Red Chapter 9 of Open GL Programming Guide (Red Book)Book)

Images applied to polygons to enhance the visual Images applied to polygons to enhance the visual effect of a sceneeffect of a scene• Rectangular arrays of dataRectangular arrays of data

– Color, luminance, Color, luminance, alphaalpha

– Components of array called Components of array called texelstexels

We’ve also had volumetricWe’ve also had volumetric voxels voxels

Page 4: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Texture Mapping

Texture map is an image, two-dimensional array of color Texture map is an image, two-dimensional array of color values (values (texelstexels))

Texels are specified by texture’s (u,v) spaceTexels are specified by texture’s (u,v) space

At each screen pixel, texel can be used to substitute a At each screen pixel, texel can be used to substitute a polygon’s surface property (color)polygon’s surface property (color)

We must map (u,v) space to polygon’s (s, t) spaceWe must map (u,v) space to polygon’s (s, t) space

Texture map is an image, two-dimensional array of color Texture map is an image, two-dimensional array of color values (values (texelstexels))

Texels are specified by texture’s (u,v) spaceTexels are specified by texture’s (u,v) space

At each screen pixel, texel can be used to substitute a At each screen pixel, texel can be used to substitute a polygon’s surface property (color)polygon’s surface property (color)

We must map (u,v) space to polygon’s (s, t) spaceWe must map (u,v) space to polygon’s (s, t) space

U

V

S

T

Page 5: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Texture Mapping

(u,v) to (s,t) mapping can be explicitly set at vertices (u,v) to (s,t) mapping can be explicitly set at vertices by storing by storing texture coordinatestexture coordinates with each vertex with each vertex

How do we compute (u,v) to (s,t) mapping for points How do we compute (u,v) to (s,t) mapping for points in betweenin between

• Watch for aliasingWatch for aliasing

• Watch for many to one mappingsWatch for many to one mappings

• Watch for perspective foreshortening effects and linear Watch for perspective foreshortening effects and linear interpolationinterpolation

(u,v) to (s,t) mapping can be explicitly set at vertices (u,v) to (s,t) mapping can be explicitly set at vertices by storing by storing texture coordinatestexture coordinates with each vertex with each vertex

How do we compute (u,v) to (s,t) mapping for points How do we compute (u,v) to (s,t) mapping for points in betweenin between

• Watch for aliasingWatch for aliasing

• Watch for many to one mappingsWatch for many to one mappings

• Watch for perspective foreshortening effects and linear Watch for perspective foreshortening effects and linear interpolationinterpolation

Page 6: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Example Texture Map

Applied to tilted polygon

Page 7: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Example Texture Map

glVertex3d (s, s, s)glTexCoord2d(1,1);

glVertex3d (-s, -s, -s)glTexCoord2d(1,1);

Page 8: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Example Texture Map

glVertex3d (s, s, s)glTexCoord2d(5, 5);

glVertex3d (s, s, s)glTexCoord2d(1, 1);

Page 9: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Texture Coordinates

Every polygon has object coordinates and texture Every polygon has object coordinates and texture coordinatescoordinates• Object coordinates describe where polygon vertices are on Object coordinates describe where polygon vertices are on

the screenthe screen

• Texture coordinates describe texel coordinates of each Texture coordinates describe texel coordinates of each vertex (usually 0 -> 1)vertex (usually 0 -> 1)

• Texture coordinates are interpolated along vertex-vertex Texture coordinates are interpolated along vertex-vertex edgesedges

glTexCoord{1234}{sifd}(TYPE coords)glTexCoord{1234}{sifd}(TYPE coords)

Every polygon has object coordinates and texture Every polygon has object coordinates and texture coordinatescoordinates• Object coordinates describe where polygon vertices are on Object coordinates describe where polygon vertices are on

the screenthe screen

• Texture coordinates describe texel coordinates of each Texture coordinates describe texel coordinates of each vertex (usually 0 -> 1)vertex (usually 0 -> 1)

• Texture coordinates are interpolated along vertex-vertex Texture coordinates are interpolated along vertex-vertex edgesedges

glTexCoord{1234}{sifd}(TYPE coords)glTexCoord{1234}{sifd}(TYPE coords)

Page 10: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Textures

Texture ObjectTexture Object

• An OpenGL data type that keeps textures resident in memory and An OpenGL data type that keeps textures resident in memory and provides identifiers to easily access themprovides identifiers to easily access them

• Provides efficiency gains over having to repeatedly load and reload a Provides efficiency gains over having to repeatedly load and reload a texturetexture

• 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 ObjectTexture Object

• An OpenGL data type that keeps textures resident in memory and An OpenGL data type that keeps textures resident in memory and provides identifiers to easily access themprovides identifiers to easily access them

• Provides efficiency gains over having to repeatedly load and reload a Provides efficiency gains over having to repeatedly load and reload a texturetexture

• 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

Page 11: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Example use of Texture

Read .bmp from fileRead .bmp from file• Use Image data typeUse Image data type

– getc()getc() and and fseek()fseek() to read image x & y size to read image x & y size

– fread()fread() fills the Image->data memory with actual fills the Image->data memory with actual red/green/blue values from .bmpred/green/blue values from .bmp

• NoteNote

– malloc()malloc() Image->data to appropriate size Image->data to appropriate size

– .bmp stores color in bgr order and we convert to rgb order.bmp stores color in bgr order and we convert to rgb order

Read .bmp from fileRead .bmp from file• Use Image data typeUse Image data type

– getc()getc() and and fseek()fseek() to read image x & y size to read image x & y size

– fread()fread() fills the Image->data memory with actual fills the Image->data memory with actual red/green/blue values from .bmpred/green/blue values from .bmp

• NoteNote

– malloc()malloc() Image->data to appropriate size Image->data to appropriate size

– .bmp stores color in bgr order and we convert to rgb order.bmp stores color in bgr order and we convert to rgb order

Page 12: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Step 2 – create Texture Objects

glGenTextures(1, &texture[texture_num]);glGenTextures(1, &texture[texture_num]);

• First argument tells GL how many Texture Objects to First argument tells GL how many Texture Objects to createcreate

• Second argument is a pointer to the place where Second argument is a pointer to the place where OpenGL will store the names (unsigned integers) of the OpenGL will store the names (unsigned integers) of the Texture Objects it createsTexture Objects it creates

– texture[] is of type GLuinttexture[] is of type GLuint

glGenTextures(1, &texture[texture_num]);glGenTextures(1, &texture[texture_num]);

• First argument tells GL how many Texture Objects to First argument tells GL how many Texture Objects to createcreate

• Second argument is a pointer to the place where Second argument is a pointer to the place where OpenGL will store the names (unsigned integers) of the OpenGL will store the names (unsigned integers) of the Texture Objects it createsTexture Objects it creates

– texture[] is of type GLuinttexture[] is of type GLuint

Page 13: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Step 3 – Specify which texture object is about to be defined

Tell OpenGL that you are going to define the Tell OpenGL that you are going to define the specifics of the Texture Object it createdspecifics 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 wellTextures can be 1D and 3D as well

Tell OpenGL that you are going to define the Tell OpenGL that you are going to define the specifics of the Texture Object it createdspecifics 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 wellTextures can be 1D and 3D as well

Page 14: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Step 4 – Begin defining texture

glTexParameter()glTexParameter()

• Sets various parameters that control how a texture is treated as it’s Sets various parameters that control how a texture is treated as it’s applied to a fragment or stored in a texture objectapplied to a fragment or stored in a texture object

• // scale linearly when image bigger than texture // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTERglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);,GL_LINEAR);

• // scale linearly when image smaller than texture // scale linearly when image smaller than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTERglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); ,GL_LINEAR);

glTexParameter()glTexParameter()

• Sets various parameters that control how a texture is treated as it’s Sets various parameters that control how a texture is treated as it’s applied to a fragment or stored in a texture objectapplied to a fragment or stored in a texture object

• // scale linearly when image bigger than texture // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTERglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);,GL_LINEAR);

• // scale linearly when image smaller than texture // scale linearly when image smaller than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTERglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); ,GL_LINEAR);

Page 15: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Step 5 – Assign image data

• glTexImage2D();glTexImage2D();• glTexImage2D();glTexImage2D();

GL_TEXTURE_2DGL_TEXTURE_2D (2D Texture)(2D Texture)

00 (level of detail 0)(level of detail 0)

33 (3 components, RGB)(3 components, RGB)

image1->sizeXimage1->sizeX (size)(size)

image1->sizeYimage1->sizeY (size)(size)

00 (no border pixel)(no border pixel)

GL_RGBGL_RGB (RGB color order)(RGB color order)

GL_UNSIGNED_BYTEGL_UNSIGNED_BYTE (unsigned byte data)(unsigned byte data)

image1->dataimage1->data (pointer to the data))(pointer to the data))

Page 16: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

glTexImage2D – Arg 1

GLenum targetGLenum target• GL_TEXTURE_2DGL_TEXTURE_2D

• GL_PROXY_TEXTURE_2DGL_PROXY_TEXTURE_2D

– Provides queries for texture resourcesProvides queries for texture resources

– Proceed with hypothetical texture use (GL won’t apply Proceed with hypothetical texture use (GL won’t apply the texture)the texture)

– After query, call GLGetTexLevelParamter to verify After query, call GLGetTexLevelParamter to verify presence of required system componentspresence of required system components

– Doesn’t check possibility of multiple texture interferenceDoesn’t check possibility of multiple texture interference

GLenum targetGLenum target• GL_TEXTURE_2DGL_TEXTURE_2D

• GL_PROXY_TEXTURE_2DGL_PROXY_TEXTURE_2D

– Provides queries for texture resourcesProvides queries for texture resources

– Proceed with hypothetical texture use (GL won’t apply Proceed with hypothetical texture use (GL won’t apply the texture)the texture)

– After query, call GLGetTexLevelParamter to verify After query, call GLGetTexLevelParamter to verify presence of required system componentspresence of required system components

– Doesn’t check possibility of multiple texture interferenceDoesn’t check possibility of multiple texture interference

Page 17: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

glTexImage2D – Arg 2

GLint levelGLint level• Used for Level of Detail (LOD)Used for Level of Detail (LOD)

• LOD stores multiple versions of texture that can be used at LOD stores multiple versions of texture that can be used at runtime (set of sizes)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 texturePixel size of polygon used to select best texture

– Eliminates need for error-prone filtering algorithmsEliminates need for error-prone filtering algorithms

GLint levelGLint level• Used for Level of Detail (LOD)Used for Level of Detail (LOD)

• LOD stores multiple versions of texture that can be used at LOD stores multiple versions of texture that can be used at runtime (set of sizes)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 texturePixel size of polygon used to select best texture

– Eliminates need for error-prone filtering algorithmsEliminates need for error-prone filtering algorithms

Page 18: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

glTexImage2D – Arg 3

GLint internalFormatGLint internalFormat• Describes which of R, G, B, and A are used in internal Describes which of R, G, B, and A are used in internal

representation of texelsrepresentation of texels

• Provides control over things texture can doProvides control over things texture can do

– High bit depth alpha blendingHigh bit depth alpha blending

– High bit depth intensity mappingHigh bit depth intensity mapping

– General purpose RGBGeneral purpose RGB

• GL doesn’t guarantee all options are available on given GL doesn’t guarantee all options are available on given hardwarehardware

GLint internalFormatGLint internalFormat• Describes which of R, G, B, and A are used in internal Describes which of R, G, B, and A are used in internal

representation of texelsrepresentation of texels

• Provides control over things texture can doProvides control over things texture can do

– High bit depth alpha blendingHigh bit depth alpha blending

– High bit depth intensity mappingHigh bit depth intensity mapping

– General purpose RGBGeneral purpose RGB

• GL doesn’t guarantee all options are available on given GL doesn’t guarantee all options are available on given hardwarehardware

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

glTexImage2D – Args 4-6

GLsizei widthGLsizei width

GLsizei heightGLsizei height• Dimensions of texture imageDimensions of texture image

– Must be 2Must be 2mm + 2b (b=0 or 1 depending on border) + 2b (b=0 or 1 depending on border)

– min, 64 x 64min, 64 x 64

GLint borderGLint border• Width of border (1 or 0)Width of border (1 or 0)

– Border allows linear blending between overlapping texturesBorder allows linear blending between overlapping textures

– Useful when manually tiling texturesUseful when manually tiling textures

GLsizei widthGLsizei width

GLsizei heightGLsizei height• Dimensions of texture imageDimensions of texture image

– Must be 2Must be 2mm + 2b (b=0 or 1 depending on border) + 2b (b=0 or 1 depending on border)

– min, 64 x 64min, 64 x 64

GLint borderGLint border• Width of border (1 or 0)Width of border (1 or 0)

– Border allows linear blending between overlapping texturesBorder allows linear blending between overlapping textures

– Useful when manually tiling texturesUseful when manually tiling textures

Page 20: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

glTexImage2D – Args 7 & 8

GLenum formatGLenum format

• Describe how texture data is stored in input arrayDescribe how texture data is stored in input array

– GL_RGB, GL_RGBA, GL_BLUE…GL_RGB, GL_RGBA, GL_BLUE…

GLenum type GLenum type

• Data size of array componentsData size of array components

– GL_SHORT, GL_BYTE, GL_INT…GL_SHORT, GL_BYTE, GL_INT…

GLenum formatGLenum format

• Describe how texture data is stored in input arrayDescribe how texture data is stored in input array

– GL_RGB, GL_RGBA, GL_BLUE…GL_RGB, GL_RGBA, GL_BLUE…

GLenum type GLenum type

• Data size of array componentsData size of array components

– GL_SHORT, GL_BYTE, GL_INT…GL_SHORT, GL_BYTE, GL_INT…

Page 21: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

glTexImage2D – Arg 9

Const GLvoid *texelsConst GLvoid *texels

• Pointer to data describing texture mapPointer to data describing texture map

Const GLvoid *texelsConst GLvoid *texels

• Pointer to data describing texture mapPointer to data describing texture map

Page 22: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Step 6 – Apply texture

Before defining geometryBefore 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, glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);GL_TEXTURE_ENV_MODE, GL_REPLACE);

Before defining geometryBefore 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, glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);GL_TEXTURE_ENV_MODE, GL_REPLACE);

Page 23: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

glTexEnv()

GL_TEXTURE_ENV_MODEGL_TEXTURE_ENV_MODE GL_DECALGL_DECAL

GL_REPLACEGL_REPLACE

GL_MODULATEGL_MODULATE

GL_BLENDGL_BLEND

If GL_BLEND selected, second call to If GL_BLEND selected, second call to glTexEnv() must specify glTexEnv() must specify GL_TEXTURE_ENV_COLORGL_TEXTURE_ENV_COLOR

4-float array for R,G,B,A 4-float array for R,G,B,A blendblend

First argument to function is always GL_TEXTURE_ENV

Page 24: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

gluScaleImage()

Alters the size of an image to meet the 2Alters the size of an image to meet the 2mm size size requirement of OpenGLrequirement of OpenGL

• Scaling performed by linear and box filteringScaling performed by linear and box filtering

Alters the size of an image to meet the 2Alters the size of an image to meet the 2mm size size requirement of OpenGLrequirement of OpenGL

• Scaling performed by linear and box filteringScaling performed by linear and box filtering

Page 25: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

glCopyTexImage2D()

Use current frame buffer contents as textureUse current frame buffer contents as texture

Copy frame buffer to named texture locationCopy frame buffer to named texture location

Use current frame buffer contents as textureUse current frame buffer contents as texture

Copy frame buffer to named texture locationCopy frame buffer to named texture location

Page 26: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

glTexSubImage2D()

Replace a region of current working texture with a Replace a region of current working texture with a smaller texturesmaller texture

SubImage need not adhere to 2SubImage need not adhere to 2mm size limitation size limitation

This is how you add data from your system’s This is how you add data from your system’s camera to GL environmentcamera to GL environment

glCopyTexSubImage2DglCopyTexSubImage2D• Frame buffer cut and paste possible tooFrame buffer cut and paste possible too

Replace a region of current working texture with a Replace a region of current working texture with a smaller texturesmaller texture

SubImage need not adhere to 2SubImage need not adhere to 2mm size limitation size limitation

This is how you add data from your system’s This is how you add data from your system’s camera to GL environmentcamera to GL environment

glCopyTexSubImage2DglCopyTexSubImage2D• Frame buffer cut and paste possible tooFrame buffer cut and paste possible too

Page 27: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Bump Mapping

Use textures to modify surface geometryUse textures to modify surface geometry

Use texel values to modify surface normals of Use texel values to modify surface normals of polygonpolygon

Texel values correspond to Texel values correspond to height fieldheight field

• Height field models a rough surfaceHeight field models a rough surface

Partial derivative of bump map specifies change Partial derivative of bump map specifies change to surface normalto surface normal

Use textures to modify surface geometryUse textures to modify surface geometry

Use texel values to modify surface normals of Use texel values to modify surface normals of polygonpolygon

Texel values correspond to Texel values correspond to height fieldheight field

• Height field models a rough surfaceHeight field models a rough surface

Partial derivative of bump map specifies change Partial derivative of bump map specifies change to surface normalto surface normal

Page 28: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Bump Mapping

Page 29: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Displacement Mapping

Bump mapped normals are inconsistent with actual Bump mapped normals are inconsistent with actual geometry. Problems arise (shadows).geometry. Problems arise (shadows).

Displacement mapping actually affects the surface Displacement mapping actually affects the surface geometrygeometry

Bump mapped normals are inconsistent with actual Bump mapped normals are inconsistent with actual geometry. Problems arise (shadows).geometry. Problems arise (shadows).

Displacement mapping actually affects the surface Displacement mapping actually affects the surface geometrygeometry

Page 30: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Mipmaps

multum in parvomultum in parvo -- many things in a small place -- many things in a small place

A texture LOD techniqueA texture LOD technique

Prespecify a series of prefiltered texture maps of Prespecify a series of prefiltered texture maps of decreasing resolutionsdecreasing resolutions

Requires more texture storageRequires more texture storage

Eliminates shimmering and flashing as objects Eliminates shimmering and flashing as objects movemove

multum in parvomultum in parvo -- many things in a small place -- many things in a small place

A texture LOD techniqueA texture LOD technique

Prespecify a series of prefiltered texture maps of Prespecify a series of prefiltered texture maps of decreasing resolutionsdecreasing resolutions

Requires more texture storageRequires more texture storage

Eliminates shimmering and flashing as objects Eliminates shimmering and flashing as objects movemove

Page 31: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

MIPMAPS

With versus without MIPMAPWith versus without MIPMAPWith versus without MIPMAPWith versus without MIPMAP

Page 32: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

MIPMAPS

Arrange different versions into one block of Arrange different versions into one block of memorymemory

Arrange different versions into one block of Arrange different versions into one block of memorymemory

Page 33: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

gluBuild2DMipmaps

Automatically constructs a family of textures from Automatically constructs a family of textures from original texture size down to 1x1original texture size down to 1x1

Automatically constructs a family of textures from Automatically constructs a family of textures from original texture size down to 1x1original texture size down to 1x1

Page 34: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Advanced Mipmaps

You can specify additional mipmap levels on You can specify additional mipmap levels on the flythe fly

• MIN_LOD may reduce poppingMIN_LOD may reduce popping

• MAX_LOD may reduce over compressionMAX_LOD may reduce over compression

You can specify min mipmap levelYou can specify min mipmap level

• Useful for mosaicing (Alphabet on a texture)Useful for mosaicing (Alphabet on a texture)

You can specify additional mipmap levels on You can specify additional mipmap levels on the flythe fly

• MIN_LOD may reduce poppingMIN_LOD may reduce popping

• MAX_LOD may reduce over compressionMAX_LOD may reduce over compression

You can specify min mipmap levelYou can specify min mipmap level

• Useful for mosaicing (Alphabet on a texture)Useful for mosaicing (Alphabet on a texture)

Page 35: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

FilteringOpenGL tries to pick best mipmap levelOpenGL tries to pick best mipmap level

Question: Question: Which texel corresponds to a particular pixel?Which texel corresponds to a particular pixel?

GL_NEAREST (Point Sampling)GL_NEAREST (Point Sampling)• Pick the texel with center nearest pixelPick the texel with center nearest pixel

GL_LINEAR (Bilinear Sampling)GL_LINEAR (Bilinear Sampling)• Weighted average of 2x2 closest texelsWeighted average of 2x2 closest texels

GL_NEAREST_MIPMAP_LINEARGL_NEAREST_MIPMAP_LINEAR• Average nearest texels from two mipmap levelsAverage nearest texels from two mipmap levels

GL_LINEAR_MIPMAP_LINEAR (Trilinear)GL_LINEAR_MIPMAP_LINEAR (Trilinear)• Average two averaged texels from two mipmapsAverage two averaged texels from two mipmaps

OpenGL tries to pick best mipmap levelOpenGL tries to pick best mipmap level

Question: Question: Which texel corresponds to a particular pixel?Which texel corresponds to a particular pixel?

GL_NEAREST (Point Sampling)GL_NEAREST (Point Sampling)• Pick the texel with center nearest pixelPick the texel with center nearest pixel

GL_LINEAR (Bilinear Sampling)GL_LINEAR (Bilinear Sampling)• Weighted average of 2x2 closest texelsWeighted average of 2x2 closest texels

GL_NEAREST_MIPMAP_LINEARGL_NEAREST_MIPMAP_LINEAR• Average nearest texels from two mipmap levelsAverage nearest texels from two mipmap levels

GL_LINEAR_MIPMAP_LINEAR (Trilinear)GL_LINEAR_MIPMAP_LINEAR (Trilinear)• Average two averaged texels from two mipmapsAverage two averaged texels from two mipmaps

Page 36: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Next Assignment

Assignment 3 will go out tonightAssignment 3 will go out tonight

Will be due in two weeksWill be due in two weeks

Image Morphing == FUN!!!Image Morphing == FUN!!!

To get started, read:To get started, read:

http://www.cs.princeton.edu/courses/archive/fall00/cs426/papers/beier92.pdfhttp://www.cs.princeton.edu/courses/archive/fall00/cs426/papers/beier92.pdf

Assignment 3 will go out tonightAssignment 3 will go out tonight

Will be due in two weeksWill be due in two weeks

Image Morphing == FUN!!!Image Morphing == FUN!!!

To get started, read:To get started, read:

http://www.cs.princeton.edu/courses/archive/fall00/cs426/papers/beier92.pdfhttp://www.cs.princeton.edu/courses/archive/fall00/cs426/papers/beier92.pdf

Page 37: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Final Exam

Final Exam will be:Final Exam will be:• Thursday 12/12 at 1900 hoursThursday 12/12 at 1900 hours

• This will conflict if you are inThis will conflict if you are in

– HIST 290HIST 290

– PLIR 210PLIR 210

– RELG 264RELG 264

– MATH 111,121,122MATH 111,121,122

– STAT 110STAT 110

Final Exam will be:Final Exam will be:• Thursday 12/12 at 1900 hoursThursday 12/12 at 1900 hours

• This will conflict if you are inThis will conflict if you are in

– HIST 290HIST 290

– PLIR 210PLIR 210

– RELG 264RELG 264

– MATH 111,121,122MATH 111,121,122

– STAT 110STAT 110

Page 38: CS 445 / 645 Introduction to Computer Graphics Lecture 17 Texture Maps Lecture 17 Texture Maps

Tests

Return testsReturn tests

Mean = 80, Median = 79, Mode = 77Mean = 80, Median = 79, Mode = 77

Standard Dev = 11Standard Dev = 11

Return testsReturn tests

Mean = 80, Median = 79, Mode = 77Mean = 80, Median = 79, Mode = 77

Standard Dev = 11Standard Dev = 11