Presentation is loading. Please wait.

Presentation is loading. Please wait.

2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.

Similar presentations


Presentation on theme: "2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e."— Presentation transcript:

1 2IV60 Computer Graphics set 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 1D Texture mapping 2 Interpolation of colors gives poor results… (255,0,0) (0,255,0) (0,0,255) (0,128,128) (128,128,0) (128,0,128) (85,85,85) H&B 18-2:580-585

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

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

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

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

9 (s 0, t 0 ) (s 1, t 1 ) (s 2, t 2 ) 2D Texture mapping triangles H&B 10-17:629-634 texture space image space (s,t)(s,t) x y (s,t)(s,t) s t (s 0, t 0 ) (s 1, t 1 ) (s 2, t 2 ) 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. (s,t)(s,t) color(s,t)

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

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

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

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. H&B 18-5:587-599 1234

25 Finally How about hidden surfaces?


Download ppt "2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e."

Similar presentations


Ads by Google