2iv60 computer graphics set 10: texture mapping
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/1.jpg)
2IV60 Computer Graphicsset 10: Texture mapping
Jack van Wijk
TU/e
![Page 2: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/2.jpg)
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
![Page 3: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/3.jpg)
1D Texture mapping 1
1D texture mapping:
Color scale for visualization
H&B 18-2:580-585
![Page 4: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/4.jpg)
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
![Page 5: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/5.jpg)
1D Texture mapping 3
Coloring with 1D texture-map: better result
s=0.5
s=1
s=0
s=0.5
s=0.5
s=0
s=1s=0.75
s=0.25
H&B 18-2:580-585
![Page 6: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/6.jpg)
2D Texture mapping
H&B 10-17:629-634
texture space object space image space
(u,v) (x,y)
uv
x
y
(s,t)
s
t
(s(u),t(v))
![Page 7: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/7.jpg)
Forward mapping
Forward mapping: project texture to pixel
H&B 10-17:629-634
texture space object space image space
(u,v) (x,y)
uv
x
y
(s,t)
s
t
(s(u),t(v))
![Page 8: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/8.jpg)
Backward mapping
Backward mapping: lookup texture per pixel
H&B 10-17:629-634
texture space object space image space
(u,v) (x,y)
uv
x
y
(s,t)
s
t
(s(u),t(v))
![Page 9: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/9.jpg)
(s0, t0)
(s1, t1)(s2, t2)
2D Texture mapping triangles
H&B 10-17:629-634
texture space image space
(s,t)
x
y(s,t)
s
t
(s0, t0)
(s1, t1)(s2, t2)
• 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)
color(s,t)
![Page 10: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/10.jpg)
3D Texture mapping3D 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
![Page 11: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/11.jpg)
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
![Page 12: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/12.jpg)
Perlin Procedural texturing
Images Ken Buckner. H&B 10-17:629-634
![Page 13: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/13.jpg)
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
![Page 14: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/14.jpg)
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
![Page 15: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/15.jpg)
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
![Page 16: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/16.jpg)
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
![Page 17: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/17.jpg)
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
![Page 18: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/18.jpg)
OpenGL texture parameters 2glTexparameteri(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
![Page 19: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/19.jpg)
OpenGL texture parameters 3glTexparameteri(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
![Page 20: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/20.jpg)
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 PixelV = GL_NEAREST
Texture PixelV = GL_LINEAR
Can be set independently for enlarged textures (MAG_FILTER) and shrunk textures (MIN_FILTER).
![Page 21: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/21.jpg)
OpenGL texture colorglTexEnvi(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
![Page 22: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/22.jpg)
OpenGL named textures 1Multiple 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
![Page 23: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/23.jpg)
OpenGL named textures 2Multiple 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
![Page 24: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/24.jpg)
Texture mapping hintsUse texture maps with dimensions that are a power of 2 (128128,
128256, 512512, 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
1 2 3 4
![Page 25: 2IV60 Computer Graphics set 10: Texture mapping](https://reader033.vdocument.in/reader033/viewer/2022061618/568139d2550346895da184b3/html5/thumbnails/25.jpg)
Finally
• How about hidden surfaces?