Download presentation
Presentation is loading. Please wait.
Published byDarrell Fitzgerald Modified over 9 years ago
1
第三课
2
Overview of this Section Concept of Texture Mapping ( 纹理映射 ) 2D Texture 3D Texture Environment Mapping Bump Mapping Others OpenGL Implementation
3
Concept of Texture Mapping
6
2D Texture Texture is an image, two-dimensional array of color values (texels) Texels are specified by texture’s (u, v) space At each screen pixel, texel can be used to subtitute a polygon’s surface color We mush map (u, v) space to polygon’s (s, t) space
7
Texture coordinates ( 纹理坐标 ) It is necessary to tell render the texture coordinate for each vertex
8
Texture coordinates Each polygon can have object coordinates and texture coordinates Object coordinates describe where polygon vertices are on the screen Texture coordinates describe texel coordinates of each vertex (usually 0 -> 1) Texture coordinates are interpolated along vertex-vertex edges
9
Texture coordinates
10
3D Texture (Solid Texture) Consider a texture as a function defined over a 3D surface Effective at representing some type of materials such as marble and wood
12
3D Texture High lights: Psuedo-random number generation with repeatability in Smooth Band-limited (low-pass filter), i.e. rolling hills vs. sharp peaks. Noise Functions: Perlin noise (most popular function) produces noise with the desirable property that the transition from one point to another within the function is a smooth one. [Vase with Perlin noise, Image courtesy of graphics.lcs.mit.edu ]graphics.lcs.mit.edu
13
3D Texture Fractals ( 分形 statistical self-similarity): A complex object, the complexity of which arises from the repetition of a given shape at a variety of scales.”[tam:apa, pg. 571] Fractal Terrain Generation (Basic idea): 1.Start with a course model (square) 2.Subdivision of surfaces (2x2) 3.Vertically perturb each of the 5 new vertices by a random amount 4.Repeat until done
14
3D Texture
15
Analytical Examples: Marble Wood - Vertical cylinders [Procedural wood, both courtesy of http://renderman.ru] [Procedural marble] * i continually increases the noise amplitude animates the Formation of the veins * s,t,r are solid texture coordinates, these are used to do a color map look up for the texture.
16
Environment Map 环境映射 Use texture to represent reflected color Texture indexed by reflection vector Approximation works when objects are far away from the reflective object Object Viewer Reflected ray Environment Map
17
Sphere Environment Mapping
18
Environment Map Cubic Environment Mapping
19
Environment Map The map should contain a view of the world with the point of interest on the object as the eye We can ’ t store a separate map for each point, so one map is used with the eye at the center of the object Introduces distortions in the reflection, but the eye doesn ’ t notice Distortions are minimized for a small object in a large room The object will not reflect itself The mapping can be computed at each pixel, or only at the vertices
20
Bump Map 凹凸纹理 Use texture to perturb normals - creates a bump-like effect + = original surface bump map modified surface
21
Bump Map Physically displace Physically displace Generate many triangles Simulate Simulate Change the normal Normal affects lighting Assume ‘Bump’ to the surface is small In the direction of the normal Height-map
22
Bump Map Texture used to alter the surface normal Actual shape of the object does not change
23
Another Example
24
Bump Map
25
Treat the texture as a single-valued height function Does not allow silhouette ( 侧面轮廓 ) effects Does not allow self-shadowing
26
Displace Map Modifies the surface position Along surface normal, typically Use if Bumps are large Get silhouettes, shadows right Much more expensive Tessellate geometry Some support in modern GPUs
27
Lighting Map 光照图 Use texture to represent illumination footprint
28
Lighting Map Quake light maps
29
OpenGL Implementation Specify textures Set texture filter Set texture function Set texture wrap mode Bind texture object Enable texturing Supply texture coordinates for vertex
30
Define Image as Texture glTexImage2D Target: type of texture, e.g. GL_TEXTURE_2D Level: used for mipmapping, 0 for common Components: elements per texel, 3 for RGB W, h: width and height of texels in pixels Border: 0 for common Format: describe texels, GL_RGB, GL_RGBA Texels: pointer to texel array
31
Convert Image to Texture OpenGL requires texture dimensions to be power of 2 (except for High OpenGL version) If not gluScaleImage(format, w_in, h_in, type_in, *data_in, w_out, h_out, type_out, *data_out);
32
Mapping a Texture Based on parametric texture coordinates glTexCoord*() specified at each vertex
33
Typical Code glBegin(GL_POLYGON); glColor3f(r0, g0, b0); //if no shading glNormal3f(u0, v0, w0); //if shading glTexCoord2f(s0, t0); glVertex3f(x0, y0, z0); glNormal3f(u1, v1, w1); glTexCoord2f(s1, t1); glVertex3f(x1, y1, z1); … glEnd();
34
Texture Parameters Wrapping parameters determine what happens if s and t are outside the (0, 1) range Filter modes allow us to use area averaging instead of point sample Mipmapping allows us to use textures at multiple resolutions Environment parameters determine how texture mapping with shading
35
Wrapping Mode Clamping: if s,t > 1use 1, if s,t < 0 use 0 Repeating: use s,t mod 1 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
36
Magnification and Minification More than one texel can cover a pixel (min) More than one pixel can cover a texel (mag)
37
Filter Mode glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
38
Mipmapped Textures Prefiltered texture maps of decreasing resolutions Lessens interpolation errors for smaller texture objects glTextureImage2D(GL_TEXTURE_2D, level, …); gluBuild2DMipmaps()
39
Mipmap
40
Sample Demo application
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.