Author: Romain Vergne (
website)
Please cite my name and add a link to my web page if you use this course
Image synthesis and OpenGL: textures
Quick links to:
- Textures for what?
- Parametrization
- Mapping functions
- Texture modes
- Filtering
- Sources
Textures for what?
Parametrization
Correspondance
between 3D data and texture coordinates
- Correspondence between fragment and texture
- Unfold the 3D surface in 2D
- Parametrization
- compute a texture coordinate per vertex
- the rasterization/interpolation is automatically done from vertex to
fragment shader
- fetch texture using uv coordinates in the fragment shader
- Texture space: \( \left[ 0,1 \right] \)
1D textures
\( (x,y,z) \rightarrow (u) \)
2D textures
\( (x,y,z) \rightarrow (u,v) \)
3D textures
\( (x,y,z) \rightarrow (u,v,w) \)
Mapping functions
Flat mapping
Cylindrical mapping
Spherical mapping
Cube mapping
Parametric mapping
UV mapping
- Possibility to compute many kinds of uv-coordinates
- via automatic algorithms (difficult problem)
- via designers
- Possibility to deform textures
- by non-linearly varying texture coordinates
Texture modes
- GL_CLAMP: use a user defined border value
- GL_CLAMP_TO_EDGE: use the texture border value
- GL_REPEAT: use fractional part of texture coordinates
- GL_MIRRORED_REPEAT: use (possibly reversed) fractional part of texture
coordinates
- Also use transformation matrices for offsets, scales, rotation, etc.
GL_CLAMP (deprecated)
|
GL_CLAMP_TO_EDGE
|
GL_REPEAT
|
GL_MIRRORED_REPEAT
|
Filtering
Problem
- Which color do we apply if one texel is projected on several fragments
(magnification - GL_TEXTURE_MAG_FILTER)?
- Which color do we apply if several texels are projected on one
fragments (minification - GL_TEXTURE_MIN_FILTER)?
Options
- GL_NEAREST: nearest texel from the uv coordinate
- GL_LINEAR: bilinear interpolation. Slower but better.
|
|
|
|
GL_NEAREST /
GL_NEAREST
|
GL_LINEAR /
GL_LINEAR
|
Images
from Jerome
Jouvie
|
- Bilinear interpolation
- weighted sum of 4 texels
- \( R_1 = z(1,1)+(z(2,1)-z(1,1))\frac{x-x_1}{x_2-x_1} \)
- \( R_2 = z(1,2)+(z(2,2)-z(1,2))\frac{x-x_1}{x_2-x_1} \)
- \( z = R_1+(R_2-R_1)\frac{y-y_1}{y_2-y_1} \)
Mipmapping
- Pyramid of textures at different resolutions
- Automatic choice by OpenGL depending on filtering options
|
|
|
|
|
|
level 0
1:1
|
level 1
4:1
|
level 2
16:1
|
level 3
64:1
|
level 4
256:1
|
level 5
1024:1
|
|
|
|
|
|
|
- Options (only for minification - GL_TEXTURE_MIN_FILTER)
- GL_NEAREST_MIPMAP_NEAREST: nearest texel in the nearest mipmap level
- GL_LINEAR_MIPMAP_NEAREST: bilinear interpolation in the nearest
mipmap level
- GL_NEAREST_MIPMAP_LINEAR: nearest texel linearly interpolated from
the 2 closest mipmap levels
- GL_LINEAR_MIPMAP_LINEAR: bilinear interpolation, interpolated from
the 2 closest mipmap levels (trilinear interpolation)
|
|
|
|
|
|
GL_NEAREST /
GL_NEAREST
|
GL_LINEAR /
GL_LINEAR
|
GL_LINEAR /
GL_LINEAR_MIPMAP_LINEAR
|
Images
from Jerome
Jouvie
|
Sources