W7: Texture Mapping Part One
Introduction
- Texture Mapping: A technique in computer graphics used to apply images (textures) to 3D models to make them appear realistic.
- Presenter: Shima Rezasoltani
- Course: CSCI 3090
- Faculty: Science, Ontario Tech
Class Goals
- Utilize texture maps in OpenGL programs
- Describe texture generation methods
- Define mipmaps in texture mapping
Texture Mapping Overview
- Enhances realism by applying photographs or patterns to 3D models.
- Instead of modeling complex objects (like a brick wall) individually, simpler polygons can be textured.
- Textures can be created using personal images or purchased collections.
Texture Coordinates
- Definition: Coordinates on the object's surface used to map the 2D textures.
- Assigned to vertices, allowing for interpolation across polygons.
- Standard convention for texture coordinates uses (u, v) with a range of [0,1].
- Bottom-left of texture: (0,0) and top-right: (1,1).
- Texture can repeat if (u,v) goes beyond 0–1 range.
Mapping Textures to 3D Models
- Mapping Process: Use fractional parts of (u,v) to determine pixel locations in texture images.
- Issues can arise if screen pixels and texture pixels differ significantly in size.
- If screen pixels are too small compared to texture pixels, blocky effects (magnification) occur.
- If screen pixels are too large, aliasing artifacts can distort images during movement.
Solutions to Scaling Problems
- Use a higher resolution texture to reduce blockiness.
- Implement mipmapping to tackle texture aliasing.
- Mipmapping is a pyramid of textures with varying resolutions, allowing for efficient texture sampling based on distance from the viewer.
Mipmapping
- Creating Mipmaps: Generate a hierarchy that reduces the texture size by averaging pixels.
- Original texture is the base; subsequent levels are created by halving dimensions until a dimension reaches 1.
- Common use of mipmaps optimizes both speed and quality.
- Requires texture dimensions to be powers of two (e.g., 128x64).
Texture Interpolation Techniques
- Types of Mipmap Interpolation:
GL_NEAREST_MIPMAP_NEAREST: Nearest mipmap level, nearest pixel. GL_LINEAR_MIPMAP_NEAREST: Nearest mipmap level, linear interpolation between pixels. GL_NEAREST_MIPMAP_LINEAR: Linear interpolation between adjacent mipmap levels. GL_LINEAR_MIPMAP_LINEAR: Linear interpolation in both mipmap levels and pixels.
Implementation Example in OpenGL
- Procedural Texturing: Techniques to generate textures programmatically (see checkerboard texture example).
- Texture Object: Texture data stored in a structured format making multiple textures manageable.
- Setting Texture Parameters:
glTexImage2D(): Initializes texture data. - Parameters: provide texture dimensions, format, and data type of the texture.
- Handles wrapping modes and filtering options for texture sampling.
Vertex and Fragment Shaders
- Vertex Shader: Handles processing of vertex positions and texture coordinates for rendering.
- Fragment Shader: Utilizes a sampler to fetch the appropriate texture value based on texture coordinates.
Conclusion
- Introduction to basic concepts of texture mapping, mipmapping, and shader integration.
- Upcoming topics include advanced techniques in texture mapping and various blending functions.
Summary Points
- Texture mapping enhances the visual realism in 3D graphics.
- Proper usage of texture coordinates is crucial for accurate mapping.
- Mipmapping and interpolation techniques are essential to maintain quality regardless of viewer distance.
- Practical implementation requires knowledge of OpenGL texture handling and shader coding.