1 / 57

Texture Mapping

Texture Mapping. +. Texture. Object. =. Texture Mapped Object. Texture Mapping Basics. Basic Concepts. Texture ( 2D Texture ): A two-dimensional array of data. Texel : An individual data element in a texture.

horsley
Download Presentation

Texture Mapping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Texture Mapping + Texture Object = Texture Mapped Object

  2. Texture Mapping Basics Basic Concepts Texture (2D Texture): A two-dimensional array of data Texel : An individual data element in a texture Texture Space : A normalized coordinate space in which the texture is specified. t 1 (s, t): Texture Coordinates 0.0 s 1.0, 0.0 t 1.0 s 0 1

  3. Surface-Texture Transformation Transform from object space (x, y, z) to texture space (s, t) Curved surface Parametric equation P = P(u, v). Usually transform from parametric space (u, v) to texture space (s, t) Example: Sphere Parametric equation: z P = (x, y, z) r  y  Surface-Texture Transformation x

  4. Polygon surface Specify texture coordinates for each vertex. Then linearly interpolate texture coordinates across projected polygon. y 3 1 Scan line y 4 p(x, y) 5 2 x

  5. Texture Mapping Procedure Projected Pixel Area yd t Pixel Area Object Surface s Pixel Center xd Device Space Object Space Texture Space Surface-texture transformation

  6. Texture Wrapping Methods Methods to deal with texture coordinates outside [0, 1] range. (0, 3) (3, 3) Texture (0, 0) (3, 0) Polygon surface with texture coordinates for four corners

  7. Repeat Mirrored Repeat n s < n  1 s  s  n n s < n  1 if (n is even number) s  s  n if (n is odd number) s  n  1  s

  8. Clamp Border Clamp if (s < 0) s  0 if (s > 1) s  1 if (s < 0) {s  0; Use border color;} if (s > 1) {s  1; Use border color;} Border Color:

  9. One-Dimensional and Three-Dimensional Texture One-Dimensional Texture (Linear Texture) Three-Dimensional Texture (Volume Texture, Solid Texture) One-dimensional array of data. Three-dimensional array of data. Texture coordinate s. Texture coordinates (s, t, r). r s 0 1 s t

  10. Texture Mapping Examples

  11. Texture Filtering Texture Filtering: Determine screen pixel color from texel color values using projected pixel area in texture space. Nearest Filtering Linear Filtering Mipmap Nearest Filtering Mipmap Linear Filtering Anisotropic Filtering

  12. Texture Minification and Magnification t t Projected Pixel Area Projected Pixel Area s s Minification: Projected pixel area in texture space is larger than a single texel. Magnification: Projected pixel area in texture space is smaller than a single texel.

  13. Nearest Filtering (Point Sampling) Select the texel whose center lies nearest to the projected pixel center. Use the color of this texel as pixel color. t Projected Pixel Center Nearest Texel Center s Nearest filtering can result in severe aliasing effects and blocky images.

  14. Linear Filtering (Bilinear Filtering) Select 22 array of texels that lie nearest to the projected pixel center. The pixel color is linearly interpolated from these texels. t Projected Pixel Center s Linear filtering produces better and smooth texture mapped images.

  15. (s0, t0+t) (s0+s, t0+t) Texture array mn (s, t) (s0, t0) (s0+s, t0)

  16. Mipmap Using a single texture, when object surface moves further away from the viewer, texture mapping may result in artifacts such as shimmering and flashing. Mipmap (multum in parvo, many things in a small place): A series of prefiltered texture images with decreasing resolution. Level 0 (8  8) Level 1 (4  4) Level 2 (2  2) Level 3 (1  1) Mipmap is only used for texture minification. Higher mipmap level should be chosen for longer distance between object surface and the viewer.

  17. Mipmap Nearest Filtering Choose the nearest mipmap level. Mipmap Linear Filtering Choose the two nearest mipmap levels. Linearly interpolate between texels sampled from these two levels. Trilinear Filtering: Use mipmap linear filtering for sampling between mipmap levels and use bilinear filtering for sampling within each mipmap level.

  18. Without Mipmap With Mipmap

  19. Anisotropic Filtering Texture anisotropy: The projected pixel area in texture space has elongated shape if the object surface forms a steep angle with respect to view plane. yd Projected Pixel Area t Pixel Area Object Surface s xd View Plane

  20. yd Object Surface Projected Pixel Area t Pixel Area s xd View Plane Anisotropic Filtering: Use multiple samples in projected pixel area. Different sample patterns are used for different projected pixel area shape.

  21. Trilinear Filtering Anisotropic

  22. OpenGL Texture Mapping • OpenGL Texture Mapping Procedures: • Create Texture Object. • Specify Texture Image for Texture Object. • Specify Texture Parameters (Texture Wrapping and Filtering Modes) for Texture Object. • Specify Texture Environment (The way in which texel color is combined with fragment color). • Enable Texture Mapping and Bind Texture Object. • Render Primitives. Specify Texture Coordinates for Each Vertex.

  23. Texture Objects A texture object stores texture image data and texture parameters. Each texture object is identified by a positive integer index number. • Procedures to use texture objects: • Generate texture object names. • Initially bind texture objects and set texture image data and parameters. • Bind and rebind texture objects for rendering. • Delete texture objects when they are no longer needed.

  24. Generate Texture Object Names void glGenTextures(GLsizei n, GLuint *textureNames) Return n currently unused integer index names for texture objects and store them in array textureNames. GLboolean glIsTexture(GLuint textureName) Return GL_TRUE if textureName is currently used as the name for a texture object. Otherwise return GL_FALSE. Delete Texture Objects void glDeleteTextures(GLsizei n, const GLuint *textureNames) Delete n texture objects whose names are stored in array textureNames. Their data is released and their names are freed.

  25. Bind Texture Objects void glBindTexture(GLenum target, GLuint textureName) When using textureName for the first time, a new texture object is created. When binding to a previously created texture object, that texture object becomes active. target: Texture target textureName: Texture object name Use glEnable(target) to enable texture mapping. Use glDisable(target) to disable texture mapping.

  26. Specify Texture Image • Texture image can be specified from system memory or frame buffer. • Texture image of a texture object can be replaced entirely or partly after it is initially specified. • Texture image can be 1D, 2D or 3D. 3D texture support was added in OpenGL 1.2. • Cube environment map texture consists of six 2D square texture images. Cube map support was added in OpenGL 1.3.

  27. Specify or Replace Texture Image from System Memory glTexImage*(), glTexSubImage*() System Memory Texture Memory Frame Buffer Unpack Pack Fragment Operations Pixel Storage Modes Pixel Transfer Operations (Pixel Map) Rasterization (Pixel Zoom)

  28. Specify or Replace Texture Image from Frame Buffer glCopyTexImage*(), glCopyTexSubImage*() System Memory Texture Memory Frame Buffer Unpack Pack Fragment Operations Pixel Storage Modes Pixel Transfer Operations (Pixel Map) Rasterization (Pixel Zoom)

  29. Two-Dimensional Texture void glTexImage2D(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *texels) Specify a 2D texture image from system memory. The image is set for texture object currently bound to target. target: 2D texture image target. level: Mipmap level. Base level is 0. internalFormat: Internal format for texel data. Indicates how texture image is stored internally in texture memory. width: Width of the texture image. height: Height of the texture image. border: Width of the texture image border. Must be 0 or 1. format: Texel data format of source image. type: Texel data type of source image. texels: System memory that stores source image data.

  30. width and height must be (2n + 2border), where n is an integer. format and type have the same meaning as in glReadPixels() and glDrawPixels(), except that format can not be GL_STENCIL_INDEX. 2D Texture Image Target

  31. Internal Format R = Red, G = Green, B = Blue, A = Alpha L = Luminance, I = Intensity

  32. Use glGetIntegerv(GL_MAX_TEXTURE_SIZE, …) to obtain maximum supported texture size without border. Use glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, …) to obtain maximum supported cube map texture size without border. To use an image with width or height that is not power of two (without border) as texture image, it must be scaled first. int gluScaleImage(GLenum format, GLint widthin, GLint heightin, GLenum typein, const void *datain, GLint widthout, GLint heightout, GLenum typeout, const void *dataout) Scale an image. Return 0 if succeeds, otherwise return a GLU error code. format: Pixel data format widthin, heightin: Width and height of input image typein: Pixel data type of input image datain: Input image data widthout, heightout: Width and height of output image typeout: Pixel data type of output image dataout: Output image data

  33. void glCopyTexImage2D(GLenum target, GLint level, GLint internalFormat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) Specify a 2D texture image from frame buffer. target: 2D texture image target. level: Mipmap level. Base level is 0. internalFormat: Internal format for texel data. x, y: Lower left corner of the source image in frame buffer. width: Width of the texture image. height: Height of the texture image. border: Width of the texture image border. Must be 0 or 1. target, level, internalFormat, width, height and border have the same meaning as in glTexImage2D().

  34. void glTexSubImage2D(GLenum target, GLint level, GLint xoff, GLint yoff, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *texels) Replace a subimage of a 2D texture with image data from system memory. xoff, yoff: Texel offsets of the lower left corner of the subimage with respect to the lower left corner of the entire texture image. width: Width of the texture subimage. height: Height of the texture subimage. Other parameters have the same meaning as in glTexImage2D(). void glCopyTexSubImage2D(GLenum target, GLint level, GLint xoff, GLint yoff, GLint x, GLint y, GLsizei width, GLsizei height) Replace a subimage of a 2D texture with image data from frame buffer. x, y: Lower left corner of the source image rectangle in frame buffer. Other parameters have the same meaning as in glTexSubImage2D().

  35. width Sub-Image height xoff yoff Texture Image

  36. Automatic Mipmap Generation int gluBuild2DMipmaps(GLenum target, GLint internalFormat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *texels) Construct a series of mipmaps down to resolution of 1  1, then call glTexImage2D() to load texture images on all mipmap levels. Also automatically scale the original image so that its width and height become power of two. All parameters have the same meaning as in glTexImage2D(). Return 0 if succeeds, otherwise return a GLU error code.

  37. One-Dimensional Texture glTexImage1D(), glTexSubImage1D() glCopyTexImage1D(), glCopyTexSubImage1D() gluBuild1DMipmaps() Three-Dimensional Texture glTexImage3D(), glTexSubImage3D() glCopyTexImage3D(), glCopyTexSubImage3D() gluBuild3DMipmaps()

  38. Specify Texture Parameters void glTexParameteri(GLenum target, GLenum pname, GLint param) void glTexParameterf(GLenum target, GLenum pname, GLfloat param) void glTexParameteriv(GLenum target, GLenum pname, GLint *param) void glTexParameterfv(GLenum target, GLenum pname, GLfloat *param) Specify texture parameters for texture object that is currently bound to target. target: GL_TEXTURE_1D GL_TEXTURE_2D GL_TEXTURE_3D GL_TEXTURE_CUBE_MAP pname: Texture parameter name param: Texture parameter value

  39. GL_CLAMP_TO_EDGE was added in OpenGL 1.2. GL_MIRRORED_REPEAT was added in OpenGL 1.4.

  40. Constant Texture Border Color pname = GL_TEXTURE_BORDER_COLOR Constant texture border color is used as border color when the texture image does not have borders. Texture Magnification Filter pname = GL_TEXTURE_MAG_FILTER

  41. Texture Minification Filter pname = GL_TEXTURE_MIN_FILTER

  42. Texture Wrapping Modes

  43. Specify Texture Environment void glTexEnvi(GLenum envtarget, GLenum pname, GLint param) void glTexEnvf(GLenum envtarget, GLenum pname, GLfloat param) void glTexEnviv(GLenum envtarget, GLenum pname, GLint *param) void glTexEnvfv(GLenum envtarget, GLenum pname, GLfloat *param) Specify texture environment. Texture environment determines how texture color is combined with incoming fragment color. envtarget: Must be GL_TEXTURE_ENV

  44. Texture source color (Rs, Gs, Bs, As) • Incoming fragment color (Rf, Gf, Bf, Af) • Constant environment color (Rc, Gc, Bc, Ac) • Final combined color (R, G, B, A)

  45. Replace Mode The texture source color components replace corresponding fragment color components.

  46. Modulation Mode (default mode) The texture source color components multiply corresponding fragment color components.

  47. Decal Mode For GL_RGB format, The texture source color replace fragment color. For GL_RGBA format, The texture source color is linearly blended with fragment color, using source alpha as blending weight.

  48. Blending Mode The fragment color is linearly blended with constant environment color, using texture source color as blending weight.

More Related