mapping method

36
Mapping method Texture Mapping Environmental mapping (sphere mapping) (cube mapping)

Upload: cullen-newman

Post on 02-Jan-2016

48 views

Category:

Documents


2 download

DESCRIPTION

Mapping method. Texture Mapping Environmental mapping (sphere mapping) (cube mapping). Introduction. When we deal with texture 2D image may use as texture for surface. Image format. Bitmap (bmp) TIFF 2 forms: uncompress and compressed JPG Compressed image Post Script (PS) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Mapping method

Mapping method

Texture Mapping

Environmental mapping

(sphere mapping)

(cube mapping)

Page 2: Mapping method

Introduction

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

Page 3: Mapping method

Image format Bitmap (bmp) TIFF

2 forms: uncompress and compressed JPG

Compressed image Post Script (PS)

used in printer control Coded in 7 bit of ASCII character set Understood by a large class of printer Large in size

Encapsulated Post Script (EPS) PS similar but add additional information for previewing images.

GIF For index images with color table and an array of image indices.

Page 4: Mapping method

Mapping Methods

Texture mappingPattern (texture) determined the color of

fragmentMap on smooth surface

Bump mappingDistort the normal vector Make some bump on surface

Environmental mappingImage that have the appearance of ray trace

Page 5: Mapping method

Texture Mapping

Some patternsRegardless of pattern

1D for stripe, curve etc2D use to map on surface3D map on solid box

Page 6: Mapping method

Two-Dimensional Texture Mapping

Mapping involved among 3 or 4 different coordinate systems. Screen coordinate at first, Final at world coordinate system World coordinate: object is described here Texture coordinate: describe texture Parametric coordinate: for the relation of curve or surface

Texture process Start out with 2D image may come from

Photo scanning Form by application

Brought into the memory array Smallest 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 1

Page 7: Mapping method

Mapping approach

General form of mapping Let (x,y,z,w) be object

coordinate. They can be expressed

as a function of textel coordinate.

Texture also can express as a function of World coordinate (inverse function)

Page 8: Mapping method

Method of texture mapping

Texture maps on a parametric surface.

Map texture together with parametric on to geometric coordinate Last project onto the screen coordinate

Page 9: Mapping method

Map the texture coordinate to geometric coordinate

Texture to screen coordinateWe interested in mapping area to area

Aliasing problem may happen

Page 10: Mapping method

Direct mapping between texel coordinate to parametric coordinate

𝑝 (𝑢 ,𝑣 )=[𝑥 (𝑢 ,𝑣)𝑦 (𝑢 ,𝑣 )𝑧 (𝑢 ,𝑣 ) ]⇒ 𝑢=𝑎𝑠+𝑏𝑡+𝑐

𝑣=𝑑𝑠+𝑒𝑡+ 𝑓⇒𝑢=𝑢𝑚𝑖𝑛+

𝑠−𝑠𝑚𝑖𝑛

𝑠𝑚𝑎𝑥−𝑠𝑚𝑖𝑛(𝑢𝑚𝑎𝑥−𝑢𝑚𝑖𝑛 )

𝑣=𝑣𝑚𝑖𝑛+𝑡−𝑡𝑚𝑖𝑛

𝑡𝑚𝑎𝑥− 𝑡𝑚𝑖𝑛(𝑣𝑚𝑎𝑥−𝑣𝑚𝑖𝑛)

Page 11: Mapping method

Two-part mapping

Use for map on curve surface 2 steps

Map texture on intermediate surfaceMap intermediate surface to surface being

renderedUseable both parametric and geometric

coordinate

Page 12: Mapping method

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 ?

Page 13: Mapping method

Mapping texture on the intermediate object to the desire surface

3 possible strategies 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 c. draw a line from the center of the object to edge

Page 14: Mapping method

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

Page 15: Mapping method

Creating a texture process

Define texel arrayGLubyte my_texels[512][512]; // monochrome image

or

GLubyte my_texels[512][512][3]; // rgb image

Assign image to texture memoryglTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB,

GL_UNSIGNED_BYTE, my_texels);

Enable textureglEnable(GL_TEXTURE_2D);

Page 16: Mapping method

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 glTexCoord

Page 17: Mapping method

Mapping 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.

Page 18: Mapping method

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_REPEAT

glTexParameteri(GL_TEXTURE_WRAP_S, GL_REPEAT); // for sglTexParameteri(GL_TEXTURE_WRAP_T, GL_CLAMP); // clamp t

Page 19: Mapping method

Problem : Alias

Texel is rarely get the center Use point sampling

Closet texel is use for interpolate Weighted average of a group of texel

Linear filtering Problem may occur at the edge

Add more texel row and colum (2m+1)x(2n+1)

Page 20: Mapping method

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

Page 21: Mapping method

When 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 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);

Page 22: Mapping method

Texture and shading

2 optionsMultiply the shading and texture by control

glTexEnvi(GL_TEX_ENV,GL_TEX_ENV_MODE, GL_MODULATE);

Decal the texture to object

glTexEnvi(GL_TEX_ENV,GL_TEX_ENV_MODE, GL_DECAL);

Page 23: Mapping method

Projection correction

No need for orthogonal projection if linear interpolation is use

For perspective projection due to non linear depth scaling a better interpolation is apply by use

glHint(GL_PERSPECTIVE_CORRECTION, GL_NICEST);

Page 24: Mapping method

Texture transformation

As vertices definitionTransformation such as scaling, rotating,

move etcTexture coordinate store in the form of 4D

matrix call texture matrixInitially matrix is identicalManipulate by glMatrixMode()

glMatrixMode(GL_TEXTURE);

Page 25: Mapping method

Texture object

An OpenGL technique to deal with multitexture Former :

Load texture every time texture is change with glTexture2D()

Inefficient Using texture object

Load all textures that need to texture memory Only change the texture handle to switch between

texture

Page 26: Mapping method
Page 27: Mapping method

Multitexturing

Page 28: Mapping method

Environmental / Reflection Maps

appear on highly specular surface eg. mirror use physically base rendering method such as ray

tracer basic idea

follow the r = 2(v.n)n-v until intersect the environment shad the reflect to the object approximate using step 2

Page 29: Mapping method
Page 30: Mapping method

Cubemapping

A subtechnique of environmental mappingOpenGL support which is called by

glTexImage2D(GL_CUBE_MAP_dir_axis, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels);

dir : POSITIVE / NEGATIVE

axis : X, Y or Z

The object will be surrounded by environt with cube map

Page 31: Mapping method

Sphere map

Page 32: Mapping method

Bump mapping Purtube the normal vector

if disturb the normal by displace it in the normal direction with d(u,v) and ()

New point can find with

and its normal

Page 33: Mapping method

Bump (cont)Partial derivative of and

and

Calculation needs two arrays which disturbs texture and

Page 34: Mapping method

Compositing techniques

Opacity and blending Image compositing Image compositing in OpenGLAntialiasingBack to front and front to back renderingDepth cue and fog

Page 35: Mapping method

Multirendering and Accumulation buffer

Scene antialisingBump Mapping and Embossing Image Processing Image ExtensionsOther multipass method

Page 36: Mapping method

Sampling and Aliasing

sampling theoryreconstructionquantization