1 / 25

2IV60 Computer Graphics set 10: Texture mapping

2IV60 Computer Graphics set 10: Texture mapping. Jack van Wijk TU/e. Texture mapping. Need more detail? Paste a picture! Texture: 1-D, 2-D and 3-D image Texture coordinates: Per vertex 1, 2 or 3 extra coordinates that point in the texture. H&B 18: 579-601. 1D Texture mapping 1.

judyalonso
Télécharger la présentation

2IV60 Computer Graphics set 10: Texture mapping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2IV60 Computer Graphicsset 10: Texture mapping Jack van Wijk TU/e

  2. Texture mapping Need more detail? Paste a picture! • Texture: 1-D, 2-D and 3-D image • Texture coordinates: Per vertex 1, 2 or 3 extra coordinates that point in the texture H&B 18: 579-601

  3. 1D Texture mapping 1 1D texture mapping: Color scale for visualization H&B 18-2:580-585

  4. (255,0,0) (128,128,0) (85,85,85) (0,255,0) (128,0,128) (0,128,128) (0,0,255) 1D Texture mapping 2 Interpolation of colors gives poor results… H&B 18-2:580-585

  5. s=1 s=0.75 s=0.5 s=0.5 s=0.5 s=0.25 s=0 1D Texture mapping 3 Coloring with 1D texture-map: better result s=1 s=0 H&B 18-2:580-585

  6. (s(u),t(v)) t (s,t) s 2D Texture mapping y (u,v) (x,y) v u x texture space object space image space H&B 10-17:629-634

  7. (s(u),t(v)) t (s,t) s Forward mapping Forward mapping: project texture to pixel y (u,v) (x,y) v u x texture space object space image space H&B 10-17:629-634

  8. (s(u),t(v)) t (s,t) s Backward mapping Backward mapping: lookup texture per pixel y (u,v) (x,y) v u x texture space object space image space H&B 10-17:629-634

  9. 2D Texture mapping triangles (s0, t0) (s,t) y (s0, t0) (s,t) color(s,t) t (s,t) (s2, t2) (s2, t2) (s1, t1) (s1, t1) x s texture space image space • Per vertex: specify position (x, y, z) and texture coordinates (s, t) • Texture coordinates are interpolated during scan conversion and used to look-up the color. H&B 10-17:629-634

  10. 3D Texture mapping 3D texture mapping: • Texture map is volume (stack of bitmaps): memory intensive • Per vertex (s,t,r) coordinates • Applications: • medical 3D images (plane through scan) • solid materials (wood) H&B 10-17:629-634

  11. Procedural texturing • Instead of using a 1-, 2-, or 3-D image: Define function that returns color dependent on value of s, (s,t) or (s,t,r) • Simple: chessboard • Advanced: wood, marble, etc. H&B 10-17:629-634

  12. Perlin Procedural texturing Images Ken Buckner . H&B 10-17:629-634

  13. OpenGL 1D Texture Mapping 1 First, make sure texture mapping is enabled: glEnable(GL_TEXTURE_1D); Load the 1D texture map: GlTexImage1D(GL_TEXTURE_1D, // here comes a 1D map 0, // 0: not part of larger array GL_RGBA, // we use RGBA colors nTexColors, // the number of colors (use power of 2) 0, // no border GL_RGBA, // order of bytes in color GL_UNSIGNED_BYTE, // components color: unsigned bytes lineTexArray); // array with color values H&B 18-5:587-599

  14. OpenGL 1D Texture Mapping 2 Use the 1D color map during rendering: glBegin(…); glTexCoord1f(0.2); // one coordinate per vertex glVertex3fv(p1); glTexCoord1f(0.8); glVertex3fv(p2); … glEnd(); H&B 18-5:587-599

  15. OpenGL 2D Texture Mapping 1 First, make sure texture mapping is enabled: glEnable(GL_TEXTURE_1D); Load the 2D texture map: GlTexImage2D(GL_TEXTURE_2D, // here comes a 2D map 0, // 0: not part of larger array GL_RGBA, // we use RGBA colors texwidth, // width of texture map (use power of 2) texHeight, // heigth of map (use power of 2) 0, // no border GL_RGBA, // order of bytes in color GL_UNSIGNED_BYTE, // components color: unsigned bytes surfTexArray); // array with color values H&B 18-5:587-599

  16. OpenGL 2D Texture Mapping 2 Use the 2D color map during rendering: glBegin(…); glTexCoord1f(0.2, 0.8); // two coordinates per vertex glVertex3fv(p1); glTexCoord1f(0.8, 0.8); glVertex3fv(p2); … glEnd(); H&B 18-5:587-599

  17. OpenGL texture parameters 1 Generic call: glTexparameter*(target, parameter, value(s)); * = iv or fv target = GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D Some useful parameters: GL_TEXTURE_WRAP_S GL_TEXTURE_WRAP_T GL_TEXTURE_MIN_FILTER GL_TEXTURE_MAG_FILTER H&B 18-5:587-599

  18. OpenGL texture parameters 2 V = GL_REPEAT: Use only fractional part of texture coordinate V = GL_CLAMP: Clamp texture coordinate to [0, 1] range glTexparameteri(GL_TEXTURE_2D, GL_WRAP_S, V); glTexparameteri(GL_TEXTURE_2D, GL_WRAP_T, V); (-1,2) (2,3) (0,1) (1,1) All coordinates: (s,t) texture coordinates (0,0) (1,0) texture map (-1,-1) (2,-1) H&B 18-5:587-599 Quadrilateral

  19. OpenGL texture parameters 3 V = GL_REPEAT: Use only fractional part of texture coordinate V = GL_CLAMP: Clamp texture coordinate to [0, 1] range glTexparameteri(GL_TEXTURE_2D, GL_WRAP_S, V); glTexparameteri(GL_TEXTURE_2D, GL_WRAP_T, V); (-1,2) (2,3) (-1,-1) (2,-1) GL_REPEAT, GL_CLAMP GL_CLAMP, GL_CLAMP GL_REPEAT, GL_REPEAT H&B 18-5:587-599

  20. OpenGL texture parameters 4 glTexparameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, V); glTexparameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, V); Texture Pixel V = GL_NEAREST Texture Pixel V = GL_LINEAR Can be set independently for enlarged textures (MAG_FILTER) and shrunk textures (MIN_FILTER). H&B 18-5:587-599

  21. OpenGL texture color glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, V) V = GL_MODULATE Final color is product of current color and texture color Default value. Using texture on black object has no effect! V = GL_REPLACE Final color is texture color Simplest to use. V = GL_DECAL, GL_BLEND If you want to do something special. H&B 18-5:587-599

  22. OpenGL named textures 1 Multiple textures simultaneously in one scene? Using glTexImage2D multiple times per frame is expensive. Solution: named textures. Initially bind textures to symbolic id’s: myTextureInit(); // Taken care of in template assignment { glBindTexture(GL_TEXTURE_2D, head_texture_id); glTexImage2D(..., head_texture); glBindTexture(GL_TEXTURE_2D, torso_texture_id); glTexImage2D(..., torso_texture); glBindTexture(GL_TEXTURE_2D, bricks_texture_id); glTexImage2D(..., bricks_texture); } H&B 18-5:587-599

  23. OpenGL named textures 2 Multiple textures simultaneously in one scene? Using glTexImage2D multiple times per frame is expensive. Solution: named textures. During drawing: refer to symbolic id’s: myDraw(); { glBindTexture(GL_TEXTURE_2D, head_texture_id); myDrawHead(); glBindTexture(GL_TEXTURE_2D, torso_texture_id); myDrawTorso(); glBindTexture(GL_TEXTURE_2D, bricks_texture_id); myDrawBricks(); } H&B 18-5:587-599

  24. Texture mapping hints Use texture maps with dimensions that are a power of 2 (128128, 128256, 512512, etc.); Try to minimize distortion, i.e., aim at using dimensions in texture space that are proportional to dimensions in world space; Use: glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); You can use multiple pictures in one texture map, and control via texture coordinates which picture you use. 1 2 3 4 H&B 18-5:587-599

  25. Finally • How about hidden surfaces?

More Related