43
Computer Graphics 8 - Texture mapping, bump mapping and antialiasing Tom Thorne Slides courtesy of Taku Komura www.inf.ed.ac.uk/teaching/courses/cg

Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Computer Graphics 8 - Texture mapping, bumpmapping and antialiasing

Tom Thorne

Slides courtesy of Taku Komura

www.inf.ed.ac.uk/teaching/courses/cg

Page 2: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Overview

• Texture mapping and bump mapping

• Anti-aliasing

Page 3: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Texture mapping

• Adding detail to polygon meshes to build high resolution models is computationally expensive

• In realtime applications these are not practical to use

by Rami Ali Al-ashqar

Page 4: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Texture mapping

• We can improve the appearance of polygons by mapping images onto their surface

• This is done during rasterisation

Page 5: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Overview of texture mapping

• Assign each triangle in the mesh a region of the image

• During rasterisation, colour the surface of the triangle based on the pixels in the image

• Typically done by assigning triangle vertices coordinates (uv) within the image

Page 6: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Interpolation of uv coordinates

• To calculate which pixel in the image corresponds to a point inside the triangle, we interpolate uv coordinates between vertices

• This can be done using barycentric coordinates

u= α u1 + β u2 + γ u3

v = α v1 + β v2 + γ v3

Page 7: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Example

Page 8: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Producing uv mappings

• Generated based on the mesh - cylindrical, spherical, orthogonal

• Captured from real objects by scanning

• Manually specifying coordinates

Page 9: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Common uv mappings

• Orthogonal

• Cylindrical

• Spherical

Page 10: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Capturing real data

• Scanning depth and colour of objects

http://www.3dface.org/media/images.html

Page 11: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Manual specification

• Painting on the geometry (Z-brush)

• Manually aligning an unfolded model on the image

Page 12: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Geometry unfolding

• Segment the mesh into regions that are arranged in a 2D plane

• Draw on these regions in 2D to texture the mesh

Levy et al. SIGGRAPH 2002

Page 13: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Linear interpolation

• Linearly interpolating uv coordinates does not produce the expected results

texture source what we get| what we want

Page 14: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Why does this happen?

• Uniform steps in 2D screen space do not correspond to uniform steps over the surface of the triangle

Page 15: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Hyperbolic interpolation

• To interpolate between vertices P and Q, rather than interpolating between u(P) and u(Q), we interpolate u(P)/z, u(Q)/z and 1/z

• Considering a point M between P and Q and its projection M’:

P 0 = �P/zP , Q0 = �Q/zQ

M 0 = ↵P 0 + (1� ↵)Q0

Page 16: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Hyperbolic interpolation

• For a point M the perspective correct interpolated u(M) is then:

u(M)

�zM= ↵

u(P )

�zP+ (1� ↵)

u(Q)

�zQ

u(M) =↵u(P )

�zP+ (1� ↵)u(Q)

�zQ

↵ 1�zP

+ (1� ↵) 1�zQ

Page 17: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Example

• Linear interpolation vs hyperbolic interpolation

Page 18: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Texture mapping and illumination

• We can use texture information to alter illumination

Page 19: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Bump mapping

• Texture mapping leaves the surface looking flat

• Adding extra mesh detail can be computationally too expensive

Page 20: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Bump mapping

• Uses a texture to alter the surface normal to change the illumination

• Applied during rasterisation

Sphere w/Diffuse Texture Swirly Bump Map Sphere w/Diffuse Texture & Bump Map

surface. Attempts to do this were not verysucessful. The images usually looked like smoothsurfaces with photographs of wrinkles glued on.The main reason for this is that the light sourcedirection when making the texture photograph wasrarely the same as that used when synthesizing theimage. In fact, if the surface (and thus themapped texture pattern) is curved, the angle ofthe light source vector with the surface is noteven the same at different locations on the patch.2. NORMAL VECTOR PERTURBATION

To best generate images of macroscopicsurface wrinkles and irregularities we mustactually model them as such. Modelling eachsurface wrinkle as a separate patch would probablybe prohibitively expensive. We are saved fromthis fate by the realization that the effect ofwrinkles on the perceived intensity is primarilydue to their effect on the direction of thesurface normal (and thus the light reflected)rather than their effect on the position of thesurface. We can expect, therefore, to get a goodeffect from having a texturing function whichperforms a small perturbation on the direction ofthe surface normal before using it in theintensity formula. This is similar to thetechnique used by Batson et al. [1] to synthesizeaerial picutres of mountain ranges fromtopographic data.

The normal vector perturbation is defined interms of a function which gives the displacementof the irregular surface from the ideal smoothone. We will call this function F(u,v). On thewrinkled patch the position of a point isdisplaced in the direction of the surface normalby an amount equal to the value of F(u,v). Thenew position vector can then be written as:

P' = P + F N/INIThis is shown in cross section in figure 2.

The partial derivatives involved are evaluated bythe chain rule. So

Pu' = d/du P' = d/du(P + F N/INI)= Pu + Fu N/INI + F (N/INI)u

Pv' = d/dv P' = d/dv(P + F N/INI)= Pv + Fv N/INI + F (N/INI)v

The formulation of the normal to the wrinkledsurface is now in terms of the original surfacedefinition functions, their derivatives, and thebump function, F, and its derivatives. It is,however, rather complicated. We can simplifymatters considerably by invoking the approximationthat the value of F is negligably small. This isreasonable for the types of surface irregularitiesfor which this process is intended where theheight of the wrinkles in a surface is smallcompared to the extent of the surface. With thissimplification we have

Pu' Pu + Fu N/INI

Pv' Pv + Fv N/INI

The new normal is then

N' = (Pu + Fu N/NI) x (Pv + Fv N/NI)= (Pu x Pv) + Fu (N x Pv)/INI

+ Fv (Pu x N)/INI + Fu Fv (NxN)/lNIThe first term of this is, by definition, N. Thelast term is identically zero. The net expressionfor the perturbed normal vector is then

N' =N +

where D = ( Fu (N x Pv) - Fv (N x Pu) ) / INI

This can be interpreted geometrically by observingthat (N x Pv) and (N x Pu) are two vectors in thetangent plane to the surface. An amount of eachof them proportional to the u and v derivatives ofF are added to the original, unperturbed normalvector. See figure 3

Another geometric interpretation is that thevector N' comes from rotating the original vectorN about some axis in the tangent plane to thesurface. This axis vector can be found as thecross product of N and N'.

287

Page 21: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Bump mapping

• Calculate finite differences from the bump map

!

• Calculate a perturbed normal vector

Fu =dF

du, Fv =

dF

dv

surface. Attempts to do this were not verysucessful. The images usually looked like smoothsurfaces with photographs of wrinkles glued on.The main reason for this is that the light sourcedirection when making the texture photograph wasrarely the same as that used when synthesizing theimage. In fact, if the surface (and thus themapped texture pattern) is curved, the angle ofthe light source vector with the surface is noteven the same at different locations on the patch.2. NORMAL VECTOR PERTURBATION

To best generate images of macroscopicsurface wrinkles and irregularities we mustactually model them as such. Modelling eachsurface wrinkle as a separate patch would probablybe prohibitively expensive. We are saved fromthis fate by the realization that the effect ofwrinkles on the perceived intensity is primarilydue to their effect on the direction of thesurface normal (and thus the light reflected)rather than their effect on the position of thesurface. We can expect, therefore, to get a goodeffect from having a texturing function whichperforms a small perturbation on the direction ofthe surface normal before using it in theintensity formula. This is similar to thetechnique used by Batson et al. [1] to synthesizeaerial picutres of mountain ranges fromtopographic data.

The normal vector perturbation is defined interms of a function which gives the displacementof the irregular surface from the ideal smoothone. We will call this function F(u,v). On thewrinkled patch the position of a point isdisplaced in the direction of the surface normalby an amount equal to the value of F(u,v). Thenew position vector can then be written as:

P' = P + F N/INIThis is shown in cross section in figure 2.

The partial derivatives involved are evaluated bythe chain rule. So

Pu' = d/du P' = d/du(P + F N/INI)= Pu + Fu N/INI + F (N/INI)u

Pv' = d/dv P' = d/dv(P + F N/INI)= Pv + Fv N/INI + F (N/INI)v

The formulation of the normal to the wrinkledsurface is now in terms of the original surfacedefinition functions, their derivatives, and thebump function, F, and its derivatives. It is,however, rather complicated. We can simplifymatters considerably by invoking the approximationthat the value of F is negligably small. This isreasonable for the types of surface irregularitiesfor which this process is intended where theheight of the wrinkles in a surface is smallcompared to the extent of the surface. With thissimplification we have

Pu' Pu + Fu N/INI

Pv' Pv + Fv N/INI

The new normal is then

N' = (Pu + Fu N/NI) x (Pv + Fv N/NI)= (Pu x Pv) + Fu (N x Pv)/INI

+ Fv (Pu x N)/INI + Fu Fv (NxN)/lNIThe first term of this is, by definition, N. Thelast term is identically zero. The net expressionfor the perturbed normal vector is then

N' =N +

where D = ( Fu (N x Pv) - Fv (N x Pu) ) / INI

This can be interpreted geometrically by observingthat (N x Pv) and (N x Pu) are two vectors in thetangent plane to the surface. An amount of eachof them proportional to the u and v derivatives ofF are added to the original, unperturbed normalvector. See figure 3

Another geometric interpretation is that thevector N' comes from rotating the original vectorN about some axis in the tangent plane to thesurface. This axis vector can be found as thecross product of N and N'.

287

Page 22: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Displacement mapping

• Bump mapping only changes shading of the surface, not the actual geometry

• Displacement mapping alters the surface using the texture as a mesh defined in uv coordinates

Page 23: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Displacement mapping

• Subdivide the surface to resolution of texture

• Displace vertices in normal direction of surface by height in displacement map

Page 24: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Overview

• Texture mapping

• Bump mapping

• Anti-aliasing

Page 25: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Anti-aliasing

• Aliasing is the distortion produced by representing a high resolution signal at a lower resolution

• Anti-aliasing aims to remove this distortion

Aliased polygons (jagged edges) Anti-aliased polygons

Page 26: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Why does aliasing happen?

• When the sampling frequency is too low to represent the signal

Page 27: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Nyquist limit

• To reproduce a signal, the sampling frequency should be twice the signal frequency

fsignal = 0.8fsample

fsignal = 0.5fsample

fsignal < 0.5fsample

Page 28: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Anti-aliasing by subsampling

• Subdivide each pixel into n regions

• Colour each sub-pixel

• Calculate average colour

Page 29: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Subsampling schemes

Page 30: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Subsampling schemes

Page 31: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Stochastic sampling

• Regular patterns still exhibit some aliasing for very small details

• Random sampling causes higher frequency signals to appear as noise rather than aliasing

• Our eyes are more sensitive to aliasing than noise

Page 32: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Stochastic sampling

• Subdivide pixels into n regions and randomly sample within those regions

• Calculate colours for each subsample and average

• Either precompute a table of sample positions or calculate them in real time

Page 33: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Comparison

Page 34: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Accumulation buffers

• Use a buffer of the same size as the target image

• Shift the frame buffer around each pixel center

• Accumulate and average

Pixel center

Subsampled point

Page 35: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Antialiasing textures

• When textures are zoomed in, individual texture pixels (texels) are clearly visible

• When zoomed out, several texels could be mapped to a single pixel

Page 36: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Magnification

Page 37: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Bilinear interpolation

• Averaging the neighbouring texels based on the uv coordinates for the current pixel

Page 38: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Bilinear interpolation

• Colour is calculated from coordinates by interpolation, with u’ and v’ the distance from the rounded down coordinates

u

0 =pu � (int)pu, v0 = pv � (int)pv

c(pu, pv) =(1� u

0)(1� v

0)t(xl, yb) + u

0(1� v

0)t(xr, yb)

+ (1� u

0)v0t(xl, yt) + u

0v

0t(xr, yt)

Page 39: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Minification

• When textures are zoomed out, multiple texels fall inside a single pixel. Causes aliasing due to the Nyquist limit

Page 40: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

MIP mapping

• Textures are produced at multiple resolutions

• Resolutions are switched depending on number of texels in a pixel

• Select a resolution where ration of texels to pixel is 1:1

Page 41: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

MIP mapping

• Map pixel corners to texture space

• Find a resolution where texel size is close to the pixel size

• Alternatively, use trilinear interpolation between multiple resolutions

Page 42: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

Example

MIP mappingStandard

Page 43: Computer Graphics 8 - Texture mapping, bump mapping and ...reasonable for the types of surface irregularities for which this process is intended where the height of the wrinkles in

References

• Texture mapping - Shirley Chapter 11 (Texture mapping)

• Bump mapping - Akenine-Möller Chapter 6.7 (6.7.1) Bump mapping. Blinn, J. F. (1978). Simulation of wrinkled surfaces. ACM SIGGRAPH Computer Graphics, 12(3).

• Anti-aliasing - Shirley Chapter 8.2 (Simple anti-aliasing), Akenine-Möller Chapter 5.6.2 (Screen-based anti-aliasing), Chapter 6.2.1,6.2.2 (Magnification and Minification)