Images & Textures

Second Life landscape by Vania Lahtoh, CC-BY-SA






Image Files

Image data is often saved in or loaded from a file

There are many common image formats: JPEG, TIFF, PNG, GIF, etc

Features which may vary between formats are:






Texturing






Textures vs. Images

Drawing an image (glDrawPixels in OpenGL)
Applies transformations to the starting point
After that, skips the 3D rendering pipeline and just copies pixels directly from the image to the framebuffer

Graphics.Blit in Unity3d is roughly similar


Texturing
Is a stage in the 3D rendering pipeline, for polygon data
Determines the color of each pixel while filling in a polygon
                  





Texturing

Applying textures involves the following steps:

Texture Objects

Textures usually originate as image data in main memory (often from a file)

Data is passed to the graphics card for rendering

A "texture object" holds the data in graphics card memory for repeated use

Texture size

Note: Historically, width & height had to be powers of 2 - i.e., 2, 4, 8, 16, 32, 64, 128, 256, 512, etc.
This is often still a good idea.

Maximum size is typically 4096 x 4096






Texture Coordinates

Objects need texture coordinates to define how a texture is applied

Texture coordinates form a coordinate system on the texture image, ranging from 0 to 1 in each direction

They are referred to as U & V (Unity3D, Maya, etc) or S & T (OpenGL)
(to distinguish them from X & Y geometric coordinates)






Texture Coordinates

One texture coordinate should be assigned for each vertex

This defines what part of the texture should be used at that point

When a polygon is filled in, the vertices' texture coordinates are interpolated across its surface, to find the texture data for each pixel






Texture Coordinates

A texture does not have to be evenly applied to a polygon.

The image can appear distorted, either as a result of the geometry or the texture coordinates used.






Texture Tiling

Texture coordinates outside the range 0 - 1 can be used to tile a texture

The "wrap" mode can select between repeating or clamping the texture






Textured Mesh

When applying a texture across a mesh, or collection of polygons, vertices that correspond to the same point should have the same texcoord.




Filtering

Applying a texture involves sampling - for each pixel drawn on the screen, OpenGL must compute a color from the texture image.

Texels (texture pixels) rarely match up exactly 1-to-1 with the pixels on the screen .

Filtering modes select what to do when texels are larger than screen pixels (magnification), or when texels are smaller than screen pixels (minification).

    

Common modes:






Mipmapping

Mipmapping uses versions of the texture at smaller & smaller sizes image, to effectively pre-compute the average of many texels.

As a texture gets more and more minified, many texels will correspond to a single screen pixel, and using a "nearest" or "linear" filter will not compute an accurate result. The texture will appear to flicker as the object moves.


A mipmapped texture avoids the flickering problem when minified. As a result, it can look a bit fuzzier.



Creative Commons License
This document is by Dave Pape, and is released under a Creative Commons License.