Presentation is loading. Please wait.

Presentation is loading. Please wait.

Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.

Similar presentations


Presentation on theme: "Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping."— Presentation transcript:

1 Texture Mapping

2 Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping

3 Introduction When we deal with texture When we deal with texture 2D image may use as texture for surface 2D image may use as texture for surface

4 Frame Buffers Color buffer Color buffer Front buffer Front buffer Back buffer Back buffer 32 bit for RGBA 32 bit for RGBA Depth buffer Depth buffer Deal with z value Deal with z value

5 Image format Bitmap (bmp) Bitmap (bmp) TIFF TIFF 2 forms: uncompress and compressed 2 forms: uncompress and compressed JPG JPG Compressed image Compressed image Post Script (PS) Post Script (PS) used in printer control used in printer control Coded in 7 bit of ASCII character set Coded in 7 bit of ASCII character set Understood by a large class of printer Understood by a large class of printer Large in size Large in size Encapsulated Post Script (EPS) Encapsulated Post Script (EPS) PS similar but add additional information for previewing images. GIF GIF For index images with color table and an array of image indices.

6 Writes into Buffers

7 OpenGL Buffers and the Pixel Pipeline Color buffers Front and back buffer Depth buffer Hidden surface removal Accumulation buffer Combination of multiple image Stencil buffer Masking operation

8 Pixels and Images Screen smallest element Screen smallest element Image just 2D Image just 2D

9 Mapping Methods Texture mapping Texture mapping Pattern (texture) determined the color of fragment Pattern (texture) determined the color of fragment Map on smooth surface Map on smooth surface Bump mapping Bump mapping Distort the normal vector Distort the normal vector Make some bump on surface Make some bump on surface Environmental mapping Environmental mapping Image that have the appearance of ray trace Image that have the appearance of ray trace

10 Texture Mapping Some patterns Some patterns Regardless of pattern Regardless of pattern 1D for stripe, curve etc 1D for stripe, curve etc 2D use to map on surface 2D use to map on surface 3D map on solid box 3D map on solid box

11 Two-Dimensional Texture Mapping Mapping involved among 3 or 4 different coordinate systems. Mapping involved among 3 or 4 different coordinate systems. Screen coordinate at first, Final at world coordinate system Screen coordinate at first, Final at world coordinate system World coordinate: object is described here World coordinate: object is described here Texture coordinate: describe texture Texture coordinate: describe texture Parametric coordinate: for the relation of curve or surface Parametric coordinate: for the relation of curve or surface Texture process Texture process Start out with 2D image may come from Start out with 2D image may come from Photo scanning Photo scanning Form by application Form by application Brought into the memory array Brought into the memory array Smallest element call texel (texture element) Smallest element call texel (texture element) texel is represented by T(s,t) (texel coordinate) texel is represented by T(s,t) (texel coordinate) where s and t are texture coordinate. where s and t are texture coordinate. Often range between 0 and 1 Often range between 0 and 1

12 Mapping approach General form of mapping General form of mapping Let (x,y,z,w) object coordinate and Let (x,y,z,w) object coordinate and Texture mapping function Inverse function

13 A method of texture mapping Texture maps for a parametric surface. Map texture together with parametric on to geometric coordinate Last project onto the screen coordinate

14 Map the texture coordinate to geometric coordinate Map the texture coordinate to geometric coordinate Texture to screen coordinate Texture to screen coordinate We interested in mapping area to area We interested in mapping area to area Aliasing problem may happen Aliasing problem may happen

15 Direct mapping between texel coordinate to parametric coordinate

16 Two-part mapping Use for map on curve surface Use for map on curve surface 2 steps 2 steps Map texture on intermediate surface Map texture on intermediate surface Map intermediate surface to surface being rendered Map intermediate surface to surface being rendered Useable both parametric and geometric coordinate Useable both parametric and geometric coordinate

17 Suppose that map on the cylinder surface Texture mapping with a cylinder What happen if the object is sphere?Some distortion happen at the pole. Why ?

18 Mapping texture on the intermediate object to the desire surface 3 possible strategies 3 possible strategies a. Place the texture at the finding point of intersection of normal from object edge a. Place the texture at the finding point of intersection of normal from object edge b. place the texture at the interaction point of normal intersect the intermediate surface b. place the texture at the interaction point of normal intersect the intermediate surface c. draw a line from the center of the object to edge c. draw a line from the center of the object to edge

19 Texture Mapping in OpenGL OpenGL pipelines merge at rendering (rasterization) stage process: maps 3D points to pixels on the display. visibility is test (with the z-buffer) and is shaded if visible. Vertices are mapped to texture coordinates in object defined stage, values can then be obtained by interpolation like color to polygons

20 Define texel array Define texel array Assign to texture image Assign to texture image Enable texture Enable texture GLubyte my_texels[512][512]; glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels); glEnable(GL_TEXTURE_2D);

21 Defining texture to object. t and s have value between 0 and 1 correspond to texel array (mytexels) t and s have value between 0 and 1 correspond to texel array (mytexels) Mapping can happened at object definition stage in glBegin and glEnd loop Mapping can happened at object definition stage in glBegin and glEnd loop Correspond of texel to image coordinate. Opengl use interpolate to match the image. glBegin(GL_QUAD); glTexCoord2f(0.0,0.0); glVertex2f(x1, y1); glTexCoord2f(1.0,0.0); glVertex2f(x2, y2); glTexCoord2f(1.0,1.0); glVertex2f(x3, y3); glTexCoord2f(0.0,1.0); glVertex2f(x4, y4); glEnd(); Map texture using glTexCoord

22 Texture map condition (a) only 100% (b) 50% of texture Mapping of texture to polygons. (a and b) Mapping of a checkerboard texture to a triangle. (c) Mapping of a checkerboard texture to a trapezoid.

23 When (s,t) outside (0,1) We can set for repeat or clamp when value is out of bound We can set for repeat or clamp when value is out of bound For clamping use GL_CLAMP instead of GL_REPEAT For clamping use GL_CLAMP instead of GL_REPEAT glTexParameteri(GL_TEXTURE_WRAP_S, GL_REPEAT); // for s glTexParameteri(GL_TEXTURE_WRAP_T, GL_CLAMP); // clamp t

24 Alias problem Texel is rarely get the center Texel is rarely get the center Use point sampling Use point sampling Closet texel is use for interpolate Closet texel is use for interpolate Weighted average of a group of texel Weighted average of a group of texel Linear filtering Linear filtering Problem may occur at the edge Problem may occur at the edge Add more texel row and colum Add more texel row and colum (2 m +1)x(2 n +1) (2 m +1)x(2 n +1)

25 Most of texel doesn’t math the pixel Mapping texels to pixels condition (a) Magnification. (b) Minification. In both cases, use the value of the nearest point sampling. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); More smooth use GL_LINEAR instead of GL_NEAREST

26 What do we do when texel is larger than pixel ? Use mipmapping technique for minification Use mipmapping technique for minification We can reduce size of texel to match the image by let OpenGL interpolate for a small one We can reduce size of texel to match the image by let OpenGL interpolate for a small one gluBuild2DMipmaps(GL_TEXTURE_2D,3,64,64,GL_RGB,GL_UNSIGNED_BYTE, my_texels); Or control parameter level of glTexImage2D() instead glTexImage2D(GL_TEXTURE_2D, level, components, width, height, border, format, type, tarray);

27 Texture and shading 2 options 2 options Multiply the shading and texture by control Multiply the shading and texture by control Decal the texture to object Decal the texture to object glTexEnvi(GL_TEX_ENV,GL_TEX_ENV_MODE, GL_MODULATE); glTexEnvi(GL_TEX_ENV,GL_TEX_ENV_MODE, GL_DECAL);

28 Projection correction No need for orthogonal projection if linear interpolation is use No need for orthogonal projection if linear interpolation is use For perspective projection For perspective projection due to non linear depth scaling due to non linear depth scaling a better interpolation is apply by use a better interpolation is apply by use glHint(GL_PERSPECTIVE_CORRECTION, GL_NICEST);

29 Texture transformation As vertices definition As vertices definition Transformation such as scaling, rotating, move etc Transformation such as scaling, rotating, move etc Texture coordinate store in the form of 4D matrix call texture matrix Texture coordinate store in the form of 4D matrix call texture matrix Initially matrix is identical Initially matrix is identical Manipulate by glMatrixMode() Manipulate by glMatrixMode() glMatrixMode(GL_TEXTURE);

30 Environmental / Reflection Maps appear on highly specular surface eg. mirror appear on highly specular surface eg. mirror use physically base rendering method such as ray tracer use physically base rendering method such as ray tracer basic idea basic idea follow the r = 2(v.n)n-v until intersect the environment follow the r = 2(v.n)n-v until intersect the environment shad the reflect to the object shad the reflect to the object approximate using step 2 approximate using step 2


Download ppt "Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping."

Similar presentations


Ads by Google