Texture Mapping Graphics scene tanpa texture -> cenderung polosan-> sepi. Untuk membuat permukaan yang kompleks, jika hanya menggunakan bentuk geometri maka akan sangat terbatas Gambar/citra bisa membantu memberikan efek ilusi pada permukaan Images painted onto polygons is called texture mapping
51
Embed
Texture Mapping Graphics scene tanpa texture -> cenderung polosan- > sepi. Untuk membuat permukaan yang kompleks, jika hanya menggunakan bentuk geometri.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Texture Mapping
Graphics scene tanpa texture -> cenderung polosan-> sepi.
Untuk membuat permukaan yang kompleks, jika hanya menggunakan bentuk geometri maka akan sangat terbatas
Gambar/citra bisa membantu memberikan efek ilusi pada permukaan
Images painted onto polygons is called texture mapping
Texture Maps
Images applied to polygons to enhance the visual effect of a scene
Texture Mapping Texture map is an image, two-dimensional array
of color values (texels/texture pixel) Texels are specified by texture’s (u,v) space At each screen pixel, texel can be used to
substitute a polygon’s surface property (color) We must map (u,v) space to polygon’s (s, t) space
U
V
S
T
Example Texture Map
Example Texture Map
Applied to tilted polygon
Example Texture Map
glVertex3d (s, s, s)glTexCoord2d(1,1);
glVertex3d (-s, -s, -s)glTexCoord2d(0, 0);
The Art of 3D Computer Animation and EffectsIsaac Kerlow
Texture Representation
Bitmap (pixel map) textures (supported by OpenGL)
Procedural textures (used in advanced rendering programs)Bitmap texture:
A 2D image - represented by 2D array texture[height][width] Each pixel (or called texel ) by a unique pair texture coordinate (s, t) The s and t are usually normalized to a [0,1] range For any given (s,t) in the normalized range, there is a unique image value (i.e., a unique [red, green, blue] set )
s
t
(0,0)
(1,1)
Map textures to surfaces Establish mapping from texture to surfaces
(polygons): - Application program needs to specify texture
coordinates for each corner of the polygon
The polygon can bein an arbitrary size
(0,0) (1,0)
(1,0) (1,1)
Texture Value Lookup
For the given texture coordinates (u,v), we can find a unique image value from the texture map
(0,0)
(1,1)
(0.25,0) (0.5,0) (0.75,0) (1,0)
How about coordinates that are not exactly at the intersection (pixel) positions?
A) Nearest neighborB) Linear InterpolationC) Other filters
(0,0) (1,0)
OpenGL texture mapping
Steps in your program 1) Specify texture
- read or generate image- Assign to texture
2) Specify texture mapping parameters - Wrapping, filtering, etc.
3) Enable GL texture mapping (GL_TEXTURE_2D)
4) Assign texture coordinates to vertices5) Draw your objects6) Disable GL texture mapping (if you don’t
need to perform texture mapping any more)
Specify textures Load the texture map from main memory to
Draw_picture1(); // define texture coordinates and vertices in the function ….
Projector Functions How do we map the texture onto a arbitrary (complex)
object? Construct a mapping between the 3-D point to an
intermediate surface
Idea: Project each object point to the intermediate surface with a parallel or perspective projection The focal point is usually placed inside the object
Plane Cylinder Sphere Cube
Planar projector
courtesy of R. Wolfe
Planar Projector
Orthographic projection
onto XY plane:
u = x, v = y
...onto YZ plane ...onto XZ plane
courtesy of R. Wolfe
Cylindrical Projector Convert rectangular coordinates (x, y, z) to
cylindrical (r, µ, h), use only (h, µ) to index texture image
courtesy of R. Wolfe
Spherical Projector
Convert rectangular coordinates (x, y, z) to spherical (, )
courtesy of R. Wolfe
Parametric Surfaces A parameterized surface patch
x = f(u, v), y = g(u, v), z = h(u, v)
courtesy of R. Wolfe
Mipmaps
Membuat texture dalam berbagai ukuran untuk menghaluskan penampakan objek yang jauh
Ukuran dibedakan per level Level 0: original texture map Level 1: half size in width and height
GL_LINEAR_MIPMAP_NEAREST: use the nearest mipmap closest to the polygon resolution, and use linear filtering
GL_LINEAR_MIPMAP_LINEAR: use linear interpolation between the two mipmaps closest to the polygon resolution, and use GL_LINEAR filtering in each mipmap
Example Code: gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 64, 64, GL_RGB, GL_UNSIGNED_BYTE, texImage);
Procedural Texture Mapping Instead of looking up an image, pass the
texture coordinates to a function that computes the texture value on the fly
Renderman, the Pixar rendering language, does this Available in a limited form with vertex shaders on
current generation hardware Advantages:
Near-infinite resolution with small storage cost Idea works for many other things
Has the disadvantage of being slow in many cases
Other Types of Mapping
Environment mapping looks up incoming illumination in a map
Simulates reflections from shiny surfaces
Bump-mapping memberi lighting pada texture sehingga permukaan seperti ada efek timbul
Bukan geometri permukaan yang diubah, tapi hanya efek cahaya
Displacement mapping mengubah geometri permukaan texture sehingga kesan timbul memang karena geometri permukaan yang diubah jadi timbul
All are available in software renderers like RenderMan compliant renderers
All these are becoming available in hardware
Bump Mapping
• Textures can be used to alter the surface normal of an object, but does not change the actual shape of the surface -- we are only shading it as if it were a different shape! This technique is called bump mapping.
• Since the actual shape of the object does not change, the silhouette edge of the object will not change. Bump Mapping also assumes that the Illumination model is applied at every pixel (as in Phong Shading).
Sphere w/Diffuse Texture
Swirly Bump Map
Sphere w/Diffuse Texture & Bump Map
Bump Map Examples
Cylinder w/Diffuse Texture Map
Bump Map
Cylinder w/Texture Map & Bump Map
Displacement Mapping
We use the texture map to actually move the surface point (geometri memang benar-benar diubah jadi timbul). This is called displacement mapping. How is this fundamentally different than bump mapping?
The geometry must be displaced before visibility is determined.
Environment Maps
We use the direction of the reflected ray to index a texture map.
We can simulate reflections. This approach is not completely accurate. It assumes that all reflected rays begin from the same point, and that all objects in the scene are the same distance from that point.
Environment Mapping
Environment Mapping The environment map may take one of several forms:
Cubic mapping: map resides on 6 faces of a cube Spherical mapping: map resides on a sphere
surrounding the object The map should contain a view of the world with the
point of interest on the object as the eye The mapping can be computed at each pixel, or only
at the vertices
Spherical Mapping
Implemented in hardware Single texture map Problems:
OpenGL Spherical Map We can use automatically generated texture coordinates in
OpenGL. For example, to generate the texture coordinates of spherical mapping
// Build the environment as a texture object// Automatically generate the texture coordinatesglTexGenf(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);glTexGenf(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);glEnable(GL_TEXTURE_GEN_S);glEnable(GL_TEXTURE_GEN_T);// Bind the environment texture…// Draw object…
Example
OpenGL Cubemap Texture Enabling and disabling the cube map texture is done as