Download presentation
Presentation is loading. Please wait.
Published byJennifer Owen Modified over 9 years ago
1
Texture Mapping Fall, 2011
2
Textures Describe color variation in interior of 3D polygon When scan converting a polygon, vary pixel colors according to values fetched from a texture
3
The Quest for Visual Realism
4
Surface Textures Add visual detail to surfaces of 3D objects
5
3D Rendering Pipeline Texture Mapping
6
Texture Mapping Overview Texture mapping methods Parameterization Mapping Filtering Texture mapping applications Modulation textures Illumination mapping Bump mapping Environment mapping Image-based rendering Non-photorealistic rendering
7
Parameterization Q: How do we describe where on the geometry each color from the image should go?
8
Option: Varieties of projections Cylinder MappingSphere MappingCube MappingPlane Mapping
9
Option: unfold the surface
10
Option: make an atlas
11
Texture Mapping Overview Texture mapping methods Parameterization Mapping Filtering Texture mapping applications Modulation textures Illumination mapping Bump mapping Environment mapping Image-based rendering Non-photorealistic rendering
12
Texture Mapping Steps: Define texture Specify mapping from texture to surface Lookup texture values during scan conversion
13
Texture Mapping When scan convert, map from … Image coordinate system (x, y) to Modeling coordinate system (u, v) to Texture image (t, s)
14
Texture Mapping Texture mapping is a 2D projective transformation Texture coordinate system (t, s) to Image coordinate system (x, y)
15
Texture Mapping Scan conversion Interpolate texture coordinates down/across scan lines Distortion due to bilinear interpolation approximation Cut polygons into smaller ones, or Perspective divide at each pixel
16
Texture Mapping Linear interpolationPerspective-correct interpolation
17
Texture Mapping Overview Texture mapping methods Parameterization Mapping Filtering Texture mapping applications Modulation textures Illumination mapping Bump mapping Environment mapping Image-based rendering Non-photorealistic rendering
18
Texture Filtering Must sample texture to determine color at each pixel in image
19
Texture Filtering Aliasing is a problem Point SamplingArea Filtering
20
Texture Filtering Ideally, use elliptically shaped convolution filters
21
Texture Filtering Size of filter depends on projection warp Can prefiltering images Mip maps Summed area tables
22
Mip Maps Keep textures prefiltered at multiple resolutions For each pixel, linearly interpolate between two closest levels (e. g. trilinear filtering) Fast, easy for hardware u v d
23
Summed-area tables At each texel keep sum of all values down & right To compute sum of all values within a rectangle, simply subtract two entries Better ability to capture very oblique projections But, cannot store values in a single byte
24
Texture Mapping Overview Texture mapping methods Parameterization Mapping Filtering Texture mapping applications Modulation textures Illumination mapping Bump mapping Environment mapping Image-based rendering Non-photorealistic rendering
25
Modulation textures Map texture values to scale factor
26
Illumination Mapping Map texture values to surface material parameter K A K D K S K T n Key-framemodelgeometryKey-framemodelgeometry Decal skin Bump skin Gloss skin WOW!ResultWOW!Result ++
27
Bump Mapping Texture values perturb surface normals geometry Bump map Stores heights: can derive normals + Bump mapped geometry =
28
Bump Mapping
29
Displacement Mapping Normal Mapping Problem Doesn’t take into account geometric surface depth Does not exhibit parallax No self-shadowing of the surface Coarse silhouettes expose the actual geometry being drawn Displacement Mapping Displace actual positions from Heightfield Map
30
Displacement Mapping (Result) Displacement Offset
31
Environment Mapping Texture values are reflected off surface patch
32
Cube Mapping Cube mapping is the norm nowadays x y z n eye
33
Image-Based Rendering Map photographics textures to provide details for coarsely detailed polygon model
34
Solid Textures Texture values indexed by 3D location (x, y, z) Expensive storage, or Compute on the fly ex) Perlin Noise
35
Texture Mapping Summary Texture mapping methods Parameterization Mapping Filtering Texture mapping applications Modulation textures Illumination mapping Bump mapping Environment mapping Image-based rendering Volume textures
36
Example) Quake 2 Models: Piece by Piece Model Key Frames Quake 2 interpolates between key frames
37
Example) Quake 2 Models: Piece by Piece Knight model’s decal skin Texture coordinates map triangles to skin. Note clever packing of decal skin. Only half face because triangles “mirror” the face.
38
Example) Standard Quake 2: Model Rendering Texture key-frame with decal skin ++ ResultResult Key-framemodelgeometryKey-framemodelgeometry Decal skin
39
Example) GPU Bump-mapped: Quake 2 Model Rendering! Bump-map model with bump, gloss, & decal skin Key-framemodelgeometryKey-framemodelgeometry Decal skin Bump skin Gloss skin WOW!ResultWOW!Result ++
40
Example) Quake 2 Bump Mapping: Rendering Passes ) + ( (( ) = DiffuseDiffuseGlossGlossSpecularSpecularDecalDecal Final result!
41
Example) More Bump-mapped Knight Examples Different light positions and key-frames All lighting including specular is computed per-fragment!
42
Example) Bump Mapping Models Viva la difference
43
OpenGL Texture Mapping Texture Mapping in OpenGL Allows you to modify the color of a polygon surface Textures are simply rectangular arrays of data (color, luminance, color+alpha). Individual values in a texture are called texels
44
OpenGL Texture Mapping : Step Steps necessary to use texture mapping: Create a texture object and specify the texture Indicate how the texture is to be applied to each pixel Enable texture mapping Draw the scene, supplying both texture and geometric coordinates
45
OpenGL Texture Mapping : 2D Texture Specification 2D Texture Specification glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, Glint border, GLenum format, Glenum type, const Glvoid *pixels); target: GL_TEXTURE_2D level: specifies the level of detail when using multi resolution textures. “0” is the base image, “n” is the n-th mipmap reduction image internalFormat: an integer 1 to 4, or one of 38 symbolic constants width, height: the dimensions of the texture (MUST BE power of 2) format: the kind of pixel-data elements type: the data-type of each element pixels: array containing the texture image data Ex) glTexImage2D(GL_TEXTURE_2D, 0, 3, iwidth, iheight, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
46
OpenGL Texture Mapping : Values for Format and Type Format Constants: GL_COLOR_INDEX: A single color index GL_RGB: A red component, followed by green & blue components GL_RGBA: Like GL_RGB, followed by an alpha component. GL_RED: A single red-color component GL_GREEN: A single green-color component GL_BLUE: A single blue-color component GL_ALPHA: A single alpha-color component Type Constants: GL_UNSIGNED_BYTE: unsigned 8-bit integer GL_BYTE: signed 8-bit integer GL_UNSIGNED_SHORT: unsigned 16-bit integer GL_SHORT: signed 16-bit integer GL_INT: signed 32-bit integer GL_FLOAT: single-precision floating point
47
OpenGL Texture Mapping : Texture Coordinates Texture Coordinates You need to specify BOTH texture & geometric coordinates as you specify the object in your scene glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_TRIANGLES); glNormal3d(0,0,-1); glTexCoord2d(0,0); glVertex3d(-100,-100,0); glTexCoord2d(1,0); glVertex3d(100,-100,0); glTexCoord2d(0,1); glVertex3d(-100,100,0); glEnd();
48
OpenGL Texture Mapping : Texture Filtering glTexParameteri( target, type, mode) Target : GL_TEXTURE_1D, GL_TEXTURE_2D Type : GL_TEXTURE_MIN_FILTER Mode : GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR Type : GL_TEXTURE_MAG_FILTER GL_NEAREST or GL_LINEAR Ex) glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MIN_FILTER, GL_LINEAR);
49
Min / Max Filter : GL_NEAREST Min / Max Filter : GL_LINEAR No mipmappingMipmappping
50
OpenGL Texture Mapping : Texture Wrapping glTexParameteri( target, type, mode) Target : GL_TEXTURE_1D, GL_TEXTURE_2D Type GL_TEXTURE_WRAP_S GL_TEXTURE_WRAP_T mode GL_CLAMP or GL_REPEAT Wrap S : GL_CLAMP Wrap T : GL_CLAMP Wrap S : GL_CLAMP Wrap T : GL_REPEAT Wrap S : GL_REPEAT Wrap T : GL_CLAMP Wrap S : GL_REPEAT Wrap T : GL_REPEAT
51
OpenGL Texture Mapping : Texturing Functions Texturing Functions Indicate how the texture is applied to each pixel: REPLACE or DECAL: Texture is painted on top of the fragment MODULATE: Combine texture with fragment color. This technique is useful to combine the effects of lighting with texturing BLEND: A constant color is blended with that of the fragment, based on the texture value Ex) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
52
OpenGL Texture Mapping : Texture Functions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.