Textures Lecture 11 Wed Oct 5 2005 Textures

  • Slides: 46
Download presentation
Textures Lecture 11 Wed, Oct 5, 2005

Textures Lecture 11 Wed, Oct 5, 2005

Textures A texture is an image that can be “pasted” onto a surface. The

Textures A texture is an image that can be “pasted” onto a surface. The image may be a simple one that was generated within the program, such as a checkerboard, or it may be a photograph (. bmp file).

Texture Format There are many internal formats for textures. n n n GL_RGB –

Texture Format There are many internal formats for textures. n n n GL_RGB – Each texel stored in 3 bytes (red, green, blue) GL_RGBA – Each texel stored in 4 bytes (red, green, blue, alpha) GL_R 3_G 3_B 2 – Each texel stored in 1 byte (3 red bits, 3 green bits, 2 blue bits), etc. We will use the GL_RGB format.

Creating Textures The GL_RGB texture image is created as a 3 -dimensional array. GLubyte

Creating Textures The GL_RGB texture image is created as a 3 -dimensional array. GLubyte image[rows][cols][3]; We think of it as a 2 -dimensional array of vectors. Each vector contains the red, green, and blue values as unsigned integers from 0 to 255.

Creating Textures There also 1 -dimensional textures (pasted onto lines) and 3 -dimensional textures

Creating Textures There also 1 -dimensional textures (pasted onto lines) and 3 -dimensional textures (pasted onto solids), but we will do only 2 -dimensionsal textures.

Creating Textures The dimensions of a texture image must be powers of 2, but

Creating Textures The dimensions of a texture image must be powers of 2, but they need not be the same power of 2. Typical dimensions n n n 256 256 512 32

Example A brick wall texture may be designed as a 8 8 texture. (192,

Example A brick wall texture may be designed as a 8 8 texture. (192, 0, 0) (208, 208)

Tiling Textures Often textures are “tiled” across a surface. When they are tiled, it

Tiling Textures Often textures are “tiled” across a surface. When they are tiled, it is desirable that the images match left-to-right and top-tobottom. The brick wall texture:

Tiling Textures Tiling textures works well if the texture is supposed to have a

Tiling Textures Tiling textures works well if the texture is supposed to have a regular pattern, such as in the case of the brick wall. Other textures look better if there is no discernable pattern, such as leaves.

Leaf Texture

Leaf Texture

Another Leaf Texture

Another Leaf Texture

Window Texture Other textures are not meant to be tiled.

Window Texture Other textures are not meant to be tiled.

Example of Photograph as Texture Read Run

Example of Photograph as Texture Read Run

Another Example Read Run

Another Example Read Run

Applying Textures When a texture is applied to a polygon, the texels are mapped

Applying Textures When a texture is applied to a polygon, the texels are mapped to the pixels of the rasterized polygon. This usually leads to one of two issues. n n One texel maps to several pixels. Several texels map to one pixel.

Applying Textures Mapping one texel to several pixels is called magnification (because the texel

Applying Textures Mapping one texel to several pixels is called magnification (because the texel is magnified). Mapping several texels to one pixel is called minification. (The opposite of magnify is minify? )

Applying Textures When mapping texels to pixels, we may choose between n n Applying

Applying Textures When mapping texels to pixels, we may choose between n n Applying the nearest texel. Interpolating among texels. Interpolation uses a weighted average of the 4 nearest texels, weighted by distance. This is called bilinear interpolation.

A Checkerboard Texture Read Run

A Checkerboard Texture Read Run

Magnification of Texels (Nearest) 64 Pixels 4 Texels

Magnification of Texels (Nearest) 64 Pixels 4 Texels

Magnification of Texels (Nearest) 64 Pixels 4 Texels

Magnification of Texels (Nearest) 64 Pixels 4 Texels

Magnification of Texels (Nearest) Image copied and pasted from demo program:

Magnification of Texels (Nearest) Image copied and pasted from demo program:

Magnification of Texels (Interpolated) 64 Pixels 4 Texels

Magnification of Texels (Interpolated) 64 Pixels 4 Texels

Magnification of Texels (Interpolated) 4 Texels

Magnification of Texels (Interpolated) 4 Texels

Magnification of Texels (Interpolated) Image copied and pasted from demo program:

Magnification of Texels (Interpolated) Image copied and pasted from demo program:

Close-up of Texture 1: 1 (Nearest)

Close-up of Texture 1: 1 (Nearest)

Close-up of Texture 2: 3 (Nearest)

Close-up of Texture 2: 3 (Nearest)

Close-up of Texture 1: 1 (Interpolated)

Close-up of Texture 1: 1 (Interpolated)

Close-up of Texture 2: 3 (Interpolated)

Close-up of Texture 2: 3 (Interpolated)

Minification of Texels (Nearest) 4 Pixels 64 Texels

Minification of Texels (Nearest) 4 Pixels 64 Texels

Minification of Texels (Nearest) “Nearest” texel 4 Pixels 64 Texels

Minification of Texels (Nearest) “Nearest” texel 4 Pixels 64 Texels

Minification of Texels (Nearest) 100% gray 4 Pixels 100% red 64 Texels

Minification of Texels (Nearest) 100% gray 4 Pixels 100% red 64 Texels

Minification of Texels (Interpolated) 4 Pixels 64 Texels

Minification of Texels (Interpolated) 4 Pixels 64 Texels

Minification of Texels (Interpolated) Nearest 4 texels 4 Pixels 64 Texels

Minification of Texels (Interpolated) Nearest 4 texels 4 Pixels 64 Texels

Minification of Texels (Interpolated) 100% blue 4 Pixels 75% green, 25% blue 64 Texels

Minification of Texels (Interpolated) 100% blue 4 Pixels 75% green, 25% blue 64 Texels

The Mapping is not Exact (Nearest) 64 Pixels 36 Texels

The Mapping is not Exact (Nearest) 64 Pixels 36 Texels

The Mapping is not Exact (Nearest) 64 Pixels 36 Texels

The Mapping is not Exact (Nearest) 64 Pixels 36 Texels

The Mapping is not Exact (Nearest) 64 Pixels 36 Texels

The Mapping is not Exact (Nearest) 64 Pixels 36 Texels

The Mapping is not Exact (Interpolated) 64 Pixels 36 Texels

The Mapping is not Exact (Interpolated) 64 Pixels 36 Texels

The Mapping is not Exact (Interpolated) 86% green, 14% blue 64 Pixels 42% green,

The Mapping is not Exact (Interpolated) 86% green, 14% blue 64 Pixels 42% green, 58% blue 36 Texels

The Mapping is not Exact (Interpolated) 64 Pixels 36 Texels

The Mapping is not Exact (Interpolated) 64 Pixels 36 Texels

Applying Textures The situation is often more complicated.

Applying Textures The situation is often more complicated.

Applying Textures The situation is often more complicated.

Applying Textures The situation is often more complicated.

Texture Example Read Run

Texture Example Read Run

Other Problems When the texel contains a regular pattern, there can be undesirable effects.

Other Problems When the texel contains a regular pattern, there can be undesirable effects.

Other Problems When the texel contains a regular pattern, there can be undesirable effects.

Other Problems When the texel contains a regular pattern, there can be undesirable effects.

Other Problems When the texture contains a regular pattern, there can be undesirable effects.

Other Problems When the texture contains a regular pattern, there can be undesirable effects.