View
225
Download
2
Category
Preview:
Citation preview
Texture MappingTexture Mapping
ScopeScope
BuffersBuffersVarious of graphics imageVarious of graphics imageTexture mappingTexture mapping
IntroductionIntroduction
When we deal with texture When we deal with texture 2D image may use as texture for surface2D image may use as texture for surface
Frame Buffers
Color bufferColor buffer Front bufferFront buffer Back bufferBack buffer 32 bit for RGBA32 bit for RGBA
Depth bufferDepth buffer Deal with z valueDeal with z value
Image formatImage format Bitmap (bmp)Bitmap (bmp) TIFFTIFF
2 forms: uncompress and compressed2 forms: uncompress and compressed JPGJPG
Compressed imageCompressed image Post Script (PS)Post Script (PS)
used in printer controlused in printer control Coded in 7 bit of ASCII character setCoded in 7 bit of ASCII character set Understood by a large class of printerUnderstood by a large class of printer Large in sizeLarge in size
Encapsulated Post Script (EPS)Encapsulated Post Script (EPS) PS similar but add additional information for previewing images.
GIFGIF For index images with color table and an array of image indices.
Writes into BuffersWrites into Buffers
OpenGL Buffers and the Pixel OpenGL Buffers and the Pixel PipelinePipeline
Color buffersFront and back buffer
Depth bufferHidden surface removal
Accumulation bufferCombination of multiple image
Stencil bufferMasking operation
Pixels and ImagesPixels and Images
Screen smallest elementScreen smallest element Image just 2DImage just 2D
Mapping MethodsMapping Methods
Texture mappingTexture mappingPattern (texture) determined the color of Pattern (texture) determined the color of
fragmentfragmentMap on smooth surfaceMap on smooth surface
Bump mappingBump mappingDistort the normal vector Distort the normal vector Make some bump on surfaceMake some bump on surface
Environmental mappingEnvironmental mapping Image that have the appearance of ray traceImage that have the appearance of ray trace
Texture MappingTexture Mapping
Some patternsSome patternsRegardless of patternRegardless of pattern
1D for stripe, curve etc1D for stripe, curve etc2D use to map on surface2D use to map on surface3D map on solid box3D map on solid box
Two-Dimensional Texture MappingTwo-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 systemScreen coordinate at first, Final at world coordinate system World coordinate: object is described hereWorld coordinate: object is described here Texture coordinate: describe textureTexture coordinate: describe texture Parametric coordinate: for the relation of curve or surfaceParametric coordinate: for the relation of curve or surface
Texture processTexture process Start out with 2D image may come fromStart out with 2D image may come from
Photo scanningPhoto scanning Form by applicationForm by application
Brought into the memory arrayBrought into the memory array Smallest element call texel (texture element) Smallest element call texel (texture element) texel is represented by T(s,t) texel is represented by T(s,t) (texel coordinate)(texel coordinate)
where s where s and and tt are texture coordinate. are texture coordinate. Often range between 0 and 1Often range between 0 and 1
Mapping approachMapping approach
General form of General form of mappingmapping
Let (x,y,z,w) object Let (x,y,z,w) object coordinate and coordinate and
( , )
( , )
( , )
( , )
x x s t
y y s t
z z s t
w w s t
Texture mapping function
( , , , )
( , , , )
s s x y z w
t t x y z w
Inverse function
A method of texture mappingA 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
Map the texture coordinate to geometric Map the texture coordinate to geometric coordinatecoordinate
Texture to screen coordinateTexture to screen coordinateWe interested in mapping area to areaWe interested in mapping area to area
Aliasing problem may happenAliasing problem may happen
Direct mapping between texel Direct mapping between texel coordinate to parametric coordinatecoordinate to parametric coordinate
( )
p( )= ( )
( )
x u,v
u,v y u,v
z u,v
=
=
u as+bt +c
v ds+et + f( )
( )
minmin max min
max min
minmin max min
max min
s su u u u
s s
t tv v v v
t t
Two-part mappingTwo-part mapping
Use for map on curve surface Use for map on curve surface 2 steps2 steps
Map texture on intermediate surfaceMap texture on intermediate surfaceMap intermediate surface to surface being Map intermediate surface to surface being
renderedrenderedUseable both parametric and geometric Useable both parametric and geometric
coordinatecoordinate
Suppose that map on the cylinder surfaceSuppose that map on the cylinder surface
cos(2 )
sin(2 )
/
x r u
y r u
z v h
Texture mapping with a cylinder
s u
t v
What happen if the object is sphere? Some distortion happen at the pole. Why ?
Mapping texture on the intermediate object to the Mapping texture on the intermediate object to the desire surfacedesire surface
3 possible strategies3 possible strategies a. Place the texture at the finding point of intersection a. Place the texture at the finding point of intersection
of normal from object edgeof normal from object edge b. place the texture at the interaction point of normal b. place the texture at the interaction point of normal
intersect the intermediate surfaceintersect the intermediate surface c. draw a line from the center of the object to edgec. draw a line from the center of the object to edge
Texture Mapping in OpenGLTexture 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
Define texel arrayDefine texel array
Assign to texture imageAssign to texture image
Enable textureEnable 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);
Defining texture to object.Defining texture to object.
t and s have value between 0 and 1 t and s have value between 0 and 1 correspond to texel array (mytexels)correspond to texel array (mytexels)
Mapping can happened at object definition Mapping can happened at object definition stage in glBegin and glEnd loopstage 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
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.
When (s,t) outside (0,1)When (s,t) outside (0,1)
We can set for repeat or clamp when We can set for repeat or clamp when value is out of boundvalue is out of bound
For clamping use GL_CLAMP instead of For clamping use GL_CLAMP instead of GL_REPEATGL_REPEAT
glTexParameteri(GL_TEXTURE_WRAP_S, GL_REPEAT); // for sglTexParameteri(GL_TEXTURE_WRAP_T, GL_CLAMP); // clamp t
Alias problemAlias problem
Texel is rarely get the centerTexel is rarely get the center Use point samplingUse point sampling
Closet texel is use for interpolateCloset texel is use for interpolate
Weighted average of a group of texelWeighted average of a group of texel Linear filteringLinear filtering
Problem may occur at the edgeProblem may occur at the edge Add more texel row and columAdd more texel row and colum (2(2mm+1)x(2+1)x(2nn+1)+1)
Most of texel doesn’t math the pixelMost 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
What do we do when texel is larger than pixel ?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 We can reduce size of texel to match the image by let
OpenGL interpolate for a small oneOpenGL 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);
Texture and shading
2 options2 optionsMultiply the shading and texture by controlMultiply 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);
Projection correctionProjection correction
No need for orthogonal projection if linear No need for orthogonal projection if linear interpolation is useinterpolation is use
For perspective projectionFor perspective projection due to non linear depth scaling due to non linear depth scaling a better interpolation is apply by usea better interpolation is apply by use
glHint(GL_PERSPECTIVE_CORRECTION, GL_NICEST);
Texture transformationTexture transformation
As vertices definitionAs vertices definitionTransformation such as scaling, rotating, Transformation such as scaling, rotating,
move etcmove etcTexture coordinate store in the form of 4D Texture coordinate store in the form of 4D
matrix call matrix call texture matrixtexture matrix Initially matrix is identicalInitially matrix is identicalManipulate by glMatrixMode()Manipulate by glMatrixMode()
glMatrixMode(GL_TEXTURE);
Environmental / Reflection MapsEnvironmental / Reflection Maps
appear on highly specular surface eg. mirrorappear on highly specular surface eg. mirror use physically base rendering method such as ray use physically base rendering method such as ray
tracertracer basic ideabasic idea
follow the r = 2(v.n)n-v until intersect the environmentfollow the r = 2(v.n)n-v until intersect the environment shad the reflect to the objectshad the reflect to the object approximate using step 2approximate using step 2
Recommended