mapping method texture mapping environmental mapping (sphere mapping) (cube mapping)
Post on 12-Jan-2016
Embed Size (px)
Mapping methodTexture MappingEnvironmental mapping(sphere mapping)(cube mapping)IntroductionWhen we deal with texture 2D image may use as texture for surfaceImage formatBitmap (bmp)TIFF2 forms: uncompress and compressedJPGCompressed imagePost Script (PS)used in printer controlCoded in 7 bit of ASCII character setUnderstood by a large class of printerLarge in sizeEncapsulated Post Script (EPS)PS similar but add additional information for previewing images.GIFFor index images with color table and an array of image indices.
Mapping Methods Texture mappingPattern (texture) determined the color of fragmentMap on smooth surfaceBump mappingDistort the normal vector Make some bump on surfaceEnvironmental mappingImage that have the appearance of ray traceTexture Mapping Some patternsRegardless of pattern1D for stripe, curve etc2D use to map on surface3D map on solid box
Two-Dimensional Texture Mapping Mapping involved among 3 or 4 different coordinate systems.Screen coordinate at first, Final at world coordinate systemWorld coordinate: object is described hereTexture coordinate: describe textureParametric coordinate: for the relation of curve or surfaceTexture processStart out with 2D image may come fromPhoto scanningForm by applicationBrought into the memory arraySmallest element called texel (texture element) texel is represented by T(s,t) (texel coordinate) where s and t are texture coordinate.Often range between 0 and 1Mapping approachMethod of texture mapping
Texture maps on a parametric surface.Map texture together with parametric on to geometric coordinate Last project onto the screen coordinateMap the texture coordinate to geometric coordinateTexture to screen coordinateWe interested in mapping area to areaAliasing problem may happenDirect mapping between texel coordinate to parametric coordinate
10 texel coordinate parametric coordinate u v texel (curve surface)Two-part mappingUse for map on curve surface 2 stepsMap texture on intermediate surfaceMap intermediate surface to surface being renderedUseable both parametric and geometric coordinateSuppose that map on the cylinder surface
Texture mapping with a cylinder12By using only the curved part of the cylinder, and not the top and bottom, wewere able to map the texture without distorting its shape. If we map to a closed object, such as a sphere, a shape distortion. Thisproblem is similar to the problem of creating a two-dimensional image of theearth for a map. If you look at the various maps of the earth in an atlas, alldistort shapes and distances. Both texture-mapping and map-design techniques must choose among a variety of representations, based on where we wish to place the distortion. For example, the familiar Mercator projection puts the most
Mapping texture on the intermediate object to the desire surface3 possible strategiesa. Place the texture at the finding point of intersection of normal from object edgeb. place the texture at the interaction point of normal intersect the intermediate surfacec. draw a line from the center of the object to edge
13The second step is to map the texture values on the intermediate object to thedesired surface. Three possible strategies. (a) we take the texture value at a point on the intermediate object, go from thispoint in the direction of the normal until we intersect the object, and then placethe texture value at the point of intersection. (b) starting at a point on the surface of the object and going in the direction of thenormal at this point until we intersect the intermediate object, where we obtainthe texture value, (c) if we know the center of the object, is to draw a line from the center through a point on the object, and to calculate the intersection of this line with the intermediate surface.
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 polygons14Creating a texture processDefine texel arrayGLubyte my_texels; // monochrome imageorGLubyte my_texels; // rgb imageAssign image to texture memoryglTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels);Enable textureglEnable(GL_TEXTURE_2D);
Defining texture to object.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
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 glTexCoordMapping condition
Texture map condition (a) 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.17We also could set new normals or colors before we specify each vertex. OpenGLthen uses bilinear interpolation to find the texture coordinates for the interiorpoints of a polygon, just as it uses bilinear interpolation to determine interiorcolors from vertex colors.Example shown in (a), the whole texture are used on a rectangle. (b) used only part of the range of s and t , for example (0.0, 0.5), wewould use only part of my_texels. OpenGL interpolates s and t across the quadrilateral, then maps these values back to the appropriate texel in my_texels. The quadrilateralexample is simple because there is an obvious map of texture coordinates tovertices.
For general polygons, the application programmer must decide how toassign the texture coordinates. Figure 7.26 shows a few of the possibilities withthe same texture map. Figures 7.26(a) and (b) use the same triangle but differenttexture coordinates. Note the effects of the bilinear interpolation and howquadrilaterals are treated as two triangles as they are rendered in Figure 7.26(c).When (s,t) outside (0,1)We can set for repeat or clamp when value is out of bound
For clamping use GL_CLAMP instead of GL_REPEATglTexParameteri(GL_TEXTURE_WRAP_S, GL_REPEAT); // for sglTexParameteri(GL_TEXTURE_WRAP_T, GL_CLAMP); // clamp t18Problem : Alias Texel is rarely get the centerUse point samplingCloset texel is use for interpolateWeighted average of a group of texelLinear filteringProblem may occur at the edgeAdd more texel row and colum(2m+1)x(2n+1)
19Aliasing is a major problem. When we map texture coordinates to the array oftexels, we rarely get a point that corresponds to the center of a texel. One optionis to use the value of the texel that is closest to the one computed by the bilinearinterpolation. This option is known as point sampling but, as we shall seemost subject to visible aliasing errors. A better strategy, although one that requires more work, is to use a weighted average of a group of texels in the neighborhood of the texel determined by point sampling. This option is known as linear filtering. Thus, in Figure 7.27 we see the location within a texel that is given by bilinear interpolation from the texture coordinates at thevertices and the four texels that would be used to obtain a smoother value. If weare using linear filtering, there is a problem at the edges of the texel array as weneed additional texels values outside the array. We can get around this problemby adding a 1-texel-wide border around the the texture and setting border inglTexImage2d to 1. Thus, if there is a border, then the texture array consists of(2m + 1) (2n + 1) texels.
Most of texel doesnt 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_NEARESTWhen texel is larger than pixel ?Use mipmapping technique for minification We can reduce size of texel to match the image by let OpenGL interpolate for a small onegluBuild2DMipmaps(GL_TEXTURE_2D,3,64,64,GL_RGB,GL_UNSIGNED_BYTE, my_texels);Or control parameter level of glTexImage2D() insteadglTexImage2D(GL_TEXTURE_2D, level, components, width, height,border, format, type, tarray);21OpenGL has another way to deal with the minification problem; it is calledmipmapping. For objects that project to an area of screen space that is smallcompared with the size of the texel array, we do not need the resolution ofthe original texel array. OpenGL allows us to create a series of texture arrays atreduced sizes; it will then automatically use the appropriate size. For a 64 64original array, we can set up 32 32, 16 16, 8 8, 4 4, 2 2, and 1 1arrays through the GLU function:gluBuild2DMipmaps(GL_TEXTURE_2D,3,64,64,GL_RGB,GL_UNSIGNED_BYTE, my_texels);
Texture and shading2 optionsMultiply the shading and texture by controlglTexEnvi(GL_TEX_ENV,GL_TEX_ENV_MODE, GL_MODULATE);Decal the texture to object glTexEnvi(GL_TEX_ENV,GL_TEX_ENV_MODE, GL_DECAL);22A final issue in using textures in OpenGL is the interaction between texture and shading. For RGB colors, there are two options. The texture can modulatethe shade that we would have assigned without texture mapping by multiplyingthe color components of the texture by the color components from the shader.Modulation is the default mode; it can be set byglTexEnvi(GL_TEX_ENV,GL_TEX_ENV_MODE,GL_MODULATE);
Projection correctionNo need for orthogonal projection if linear interpolation is useFor perspective projection due to non linear depth