Computer Graphics Spring 2009

46
Computer Graphics Spring 2009 Advanced Topics I: Texturing K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology

description

Computer Graphics Spring 2009. Advanced Topics I: Texturing K. H. Ko Department of Mechatronics Gwangju Institute of Science and Technology. Overview. Texturing is a process that takes a surface and modifies its appearance at each location using some image, function, or other data source. - PowerPoint PPT Presentation

Transcript of Computer Graphics Spring 2009

Page 1: Computer Graphics  Spring 2009

Computer Graphics Spring 2009

Advanced Topics I: TexturingK. H. Ko

Department of MechatronicsGwangju Institute of Science and Technology

Page 2: Computer Graphics  Spring 2009

2

Overview

• Texturing is a process that takes a surface and modifies its appearance at each location using some image, function, or other data source.– Huge modeling, memory and speed savings are

obtained by combining images and surfaces.– Color image texturing also provides a way to use

photographic images and animations on surfaces.

Page 3: Computer Graphics  Spring 2009

3

Generalized Texturing

• Texturing is a technique for efficiently modeling the surface’s properties.

• Generalized Texture Pipeline

Page 4: Computer Graphics  Spring 2009

4

Generalized Texturing

• A location in space is the starting point for the texturing process.– It is more often in the model’s frame of reference.

• When the model moves, the texture moves along with it.

• Projector Function– The goal of the projector function is to generate texture coordinates.– It is a function to give parameter space values, which will be used for

accessing the texture.– It typically works by converting a three-dimensional point in space

into texture coordinates.: projection of a point in 3D to a point in 2D.• Spherical, cylindrical and planar projections• Natural projections

Page 5: Computer Graphics  Spring 2009

5

Generalized Texturing

• Projector Function– Spherical projection casts points onto an imaginary sphere centered

around some point.– Cylindrical projection computes the u texture coordinate the same as

spherical projection, with the v texture coordinate computed as the distance along the cylinder’s axis.

– The planar projection is like an x-ray slide projector, projecting along a direction and applying the texture to all surfaces. It uses orthographic projection.

Page 6: Computer Graphics  Spring 2009

6

Generalized Texturing

• Corresponder Functions– They convert parameter-space values to texture-space loc

ations.– They provide flexibility in applying textures to surfaces.– An optional matrix transformation: translate, rotate, scale,

shear and even project the texture on the surface.– Another class of corresponder functions controls the way

an image is applied.• Determine the behavior when values are outside of the range.

– Wrap, mirror, clamp, border.

Page 7: Computer Graphics  Spring 2009

7

Generalized Texturing

• Once the texture values have been retrieved, they may be used directly or further transformed.

• The resulting values are used to modify one or more surface attributes.– Almost all real-time systems use Gouraud shading, meani

ng that only certain values are interpolated across a surface.

• So these are the only values that the texture can modify.– We modify the RGB result of the lighting equation, since

this equation was evaluated at each vertex and the color is then interpolated.

Page 8: Computer Graphics  Spring 2009

8

Generalized Texturing

• Combine Functions or Texture Blending Operations: They glue an image texture onto a surface.– Replace– Decal– Modulate

Page 9: Computer Graphics  Spring 2009

9

Generalized Texturing

• Summary with a brick wall texture example.– A modeler sets the (u,v) parameter values once in advance

for the wall model vertices.– The texture is read into the renderer, and the wall polygon

s are sent down the rendering pipeline.– A white material is used in computing the illumination at

each vertex. – This color and (u,v) values are interpolated across the surf

ace.– At each pixel, the proper brick image’s texel is retrieved a

nd modulated by the illumination color and displayed.

Page 10: Computer Graphics  Spring 2009

10

Image Texturing

• In image texturing, a two-dimensional image is effectively glued onto the surface of a polygon and rendered.

• Issues– We have an image of size 256×256 and want to use it as a texture on

a square.– Case 1: The projected square on the screen is roughly the same size a

s the texture.– Case 2: The projected square on the screen is larger than the texture.

• Magnification– Case 3: The projected square on the screen is smaller than the texture.

• Minification

• Solution depends on what kind of sampling and filtering methods are used.

Page 11: Computer Graphics  Spring 2009

11

Magnification

• Nearest Neighbor– The method takes the val

ue of the nearest texel to each pixel center when magnifying, resulting in a blocky appearance.

– One characteristic of this magnification technique is that the individual texels may become apparent.

Page 12: Computer Graphics  Spring 2009

12

Magnification

• Bilinear Interpolation– Find the four neighbori

ng texels and linearly interpolates in two dimensions to find a blended value for the pixel.

– The result is blurrier.– Much of the jaggedness

from using the nearest neighbor method has disappeared.

Page 13: Computer Graphics  Spring 2009

13

Magnification

• Bilinear Interpolation

Page 14: Computer Graphics  Spring 2009

14

Minification

• When a texture is minimized, several texels may cover a pixel’s cell.

• To get a correct color value for each pixel, integrate the effect of the texels influencing the pixel.

• However, it is difficult to determine precisely the exact influence of all texels near a particular pixel.

• It is effectively impossible to do so perfectly in real time.

Page 15: Computer Graphics  Spring 2009

15

Minification

• One method– Use the nearest neighbor.

• It selects the texel which is visible at the very center of the pixel’s cell.

• This filter may cause severe aliasing problems.– Temporal aliasing: only one of the many texels influencing

a pixel is chosen to represent the surface.

Page 16: Computer Graphics  Spring 2009

16

Minification

• Bilinear Interpolation– The same as the magnification filter.– It is only slightly better than the nearest neighbor

approach for minification.• It blends four texels instead of using just one.• When a pixel is influenced by more than four texels, t

he filter soon fails and produces aliasing.

Page 17: Computer Graphics  Spring 2009

17

Minification

• Increase the pixel’s sampling frequency or decrease the texture frequency.– The Nyquist limit.

• We need to make sure that the texture’s signal frequency is no greater than half the sample frequency.

– In general, for textures, there should be at most one texel per pixel to avoid aliasing.

• All texture antialiasing algorithms– To preprocess the texture and create data structure that will help com

pute a quick approximation of the effect of a set of texels on a pixel.– A single sample will retrieve the effects of one or more texels.

Page 18: Computer Graphics  Spring 2009

18

Minification

• Mipmapping– The most popular antialisaing metho

d for textures.– The texture (level zero) is downsam

pled to a quarter of the original area.• Each new texel value is often computed

as the average of the four neighbor texels.

• The new, level-one texture is called a subtexture of the original texture.

– The reduction is performed recursively until one or both of the dimensions of the texture equals 1 texel.

Page 19: Computer Graphics  Spring 2009

19

Minification

• Mipmapping– The goal is to determine roughly ho

w much of the texture influences the pixel.

• We compute d for the mipmap.– The intent of computing the coordin

ate d is to determine where to sample along the mipmap’s pyramid axis.

• A pixel-to-texel ratio is at least 1:1 to achieve the Nyquist rate.

• As the pixel cell comes to include more texels, d increaes.

– A smaller, blurrier version of the texture is accessed.

Page 20: Computer Graphics  Spring 2009

20

Minification

• Mipmapping– The result of mipmapping is that, instead of tryin

g to sum all the texels which affect the pixel individually, precombined sets of texels are access and interpolated.

• Causes overblurring.

Page 21: Computer Graphics  Spring 2009

21

Minification

• Ripmapping– To avoid some or all of the overblurring– The idea is to extend the mipmap to include down

sampled rectangular areas as subtextures that can be accessed.

– Need four coordinates for access

Page 22: Computer Graphics  Spring 2009

22

Minification• Summed-Area Table

– Create an array that is the size of the texture but contains more bits of precision for the color stored.

– At each location in this array, one must compute and store the sum of all the corresponding texture’s texels in the rectangle formed by this location and texel (0,0).

– During texturing, the pixel cell’s projection onto the texture is bound by a rectangle.

– The summed-area table is then accessed to determine the average color of this rectangle, which is passed back as the texture’s color for the pixel.

Page 23: Computer Graphics  Spring 2009

23

Minification

• Unconstrained Anisotropic Filtering– For current graphics hardware, the most common method

to further improve texture filtering is to reuse existing mipmap hardware.

– The basic idea• The pixel cell is back-projected.• This quadrilateral on the texture is then sampled a number of time

s.• The samples are combined.

– Each mipmap sample has a location and a squarish area associated with it.

– Instead of using a single mipmap sample to approximate this quad’s coverage, the algorithm uses a number of squares to cover the quad.

Page 24: Computer Graphics  Spring 2009

24

Minification

• Unconstrained Anisotropic Filtering

Page 25: Computer Graphics  Spring 2009

25

Multipass Texture Rendering• The various parts of the lighting equation can be evaluated in

separate passes, with each successive pass modifying the previous results.– Motion blur, antialiasing, shadows, etc.

• Example– To have the diffuse color modulated by a texture and want the specul

ar highlight to be unmodified by the texture.• In the first pass, compute and interpolate the diffuse illumination contrib

ution and modulate it by the texture.• Then compute and interpolate the specular part and render the scene agai

n.• This result then would be added to the existing diffusely lit, textured ima

ge.

Page 26: Computer Graphics  Spring 2009

26

Multipass Texture Rendering

• The basic idea behind multipass rendering is that each pass computes a piece of the lighting equation and the frame buffer is used to store intermediate results.

• On the fastest machine, up to 10 passes are done on some objects to render a single frame.– Passes 1-4 : accumulate bump map– Pass 5 : diffuse lighting– Pass 6 : base texture with specular component– Pass 7 : specular lighting– Pass 8 : emmisive lighting– Pass 9 : volumetric/atmospheric effects– Pass 10: screen flashes

Page 27: Computer Graphics  Spring 2009

27

Multitexturing

• Most graphics hardware today allows two or more textures to be applied in a single rendering pass. -> Multitexturing.

• To combine the results of these texture accesses, a texture blending cascade is defined that is made up of a series of texture stages, or texture units.– The first texture stage combines two texture values, typically RGB an

d alpha, and this result is then passed on to the next texture stage.– Second and successive stages blend another texture’s or interpolant’s

values with the previous result.

Page 28: Computer Graphics  Spring 2009

28

Texturing Methods

• We will cover various other forms of texturing beyond gluing simple color images onto surfaces.– Alpha blending in texturing– Reflections via environment mapping– Rough surface simulation using bump mapping– Etc.

Page 29: Computer Graphics  Spring 2009

29

Alpha Mapping

• The alpha value can be used for many interesting effects.– Decaling

• You wish to put a picture of a flower on a teapot.• By properly setting the decal texture’s alpha, you can replace or b

lend the underlying surface with the decal.– By assigning an alpha of 0 to a texel, you make it transparent so that

it has no effect.

– Making cutouts• You make a decal image of a tree, but you do not want the backgr

ound of this image to affect the scene at all.– If an alpha is found to be fully transparent, the textured surface itsel

f does not affect that pixel.

Page 30: Computer Graphics  Spring 2009

30

Alpha Mapping

• The alpha value can be used for many interesting effects.– Combining alpha blending and texture animation can

produce convincing special effects• Flickering torches, plant growth, explosions, atmospheric effects,

etc.

Page 31: Computer Graphics  Spring 2009

31

Light Mapping

• For static lighting in an environment, the diffuse component on any surface remains the same from any angle.

• Because of this view-independence, the contribution of light to a surface could be captured in a texture structure attached to a surface.

• By using a separate, pre-computed texture that captured the lighting contributions, and multiplying it with the underlying surface, one can achieve Phong-like shading.

Page 32: Computer Graphics  Spring 2009

32

Light Mapping

• If the lighting will never change, or will only change in overall brightness, the light texture can simply be multiplied by the surface’s material texture during the modeling stage, and the single resulting texture can be used.

• Using textures to represent shadows and projective textures: both are related with light maps.

Page 33: Computer Graphics  Spring 2009

33

Gloss Mapping

• Not all objects are uniformly shiny over their surface.– This can be simulated by using a technique called gloss m

apping and the texture that makes this happen is called a gloss map.

• A gloss map is a texture that varies the contribution of the specular component over the surface.

• The key idea is that all material properties can be supplied by textures rather than by constants or per-vertex values.

Page 34: Computer Graphics  Spring 2009

34

Environment Mapping

• Environment Mapping (EM), also called reflection mapping, is a simple yet powerful method of generating approximations of reflections in curved surfaces.– All EM methods start with a ray from the viewer to a point on the

reflector.– This ray is then reflected with respect to the normal at that point.– Instead of finding the intersection with the closest surface, EM uses

the direction of the reflection vector as an index to an image containing the environment.

Page 35: Computer Graphics  Spring 2009

35

Environment Mapping

• The steps of an EM algorithm are– Generate or load a two-dimensional image representing th

e environment.– For each pixel that contains a reflective object, compute t

he normal at the location on the surface of the object.– Compute the reflection vector from the view vector and th

e normal.– Use the reflection vector to compute an index into the env

ironment map that represents the objects in the reflection direction.

– Use the texel data from the environment map to color the current pixel.

Page 36: Computer Graphics  Spring 2009

36

Cubic Environment Mapping• Far and away the most popular EM method implemented in

modern graphics hardware, due to its speed and flexibility.• The cubic environment map is obtained by placing the camera

in the center of the environment and then projecting the environment onto the sides of a cube positioned with its center at the camera’s location.

• The images of the cube are then used as the environment map.• In practice, the scene is rendered six times with the camera at

the center of the cube, looking at each cube face with a 90-degree view angle.

Page 37: Computer Graphics  Spring 2009

37

Cubic Environment Mapping

• Cubic maps have no singularities, and are view-independent. They can be used for any view direction.

Page 38: Computer Graphics  Spring 2009

38

Sphere Mapping

• The texture image is derived from the appearance of the environment as viewed orthographically in a perfectly reflective sphere.– This texture is called a sphere map.– One way to make a sphere map of a real environment is to

take a photograph of a shiny sphere.– Sphere map textures for synthetic

scene can be generated using ray tracing or by warping the images generated for a cubic environment map.

Page 39: Computer Graphics  Spring 2009

39

Lighting Using Environment Mapping

• An important use of EM techniques is generating specular reflections and refractions.– Gouraud shading can miss highlights (reflections of light

s). – EM can solve this problem by representing the lights in th

e texture.– We can simulate highlighting on a per-pixel basis for any

number of lights at a fixed cost.

Page 40: Computer Graphics  Spring 2009

40

Lighting Using Environment Mapping

• Recursive reflections of objects in a scene can be performed using EM.– Compute only one environment map per frame

using the environment maps from the previous frame.

Page 41: Computer Graphics  Spring 2009

41

Bump Mapping• Bump mapping is a technique that makes a surface appear

uneven in some manner: bumpy, wrinkled, wavy, etc.• Bump maps can simulate features that would otherwise take

many polygons to model.• The basic idea is that instead of using a texture to change a

color component in the illumination equation, we access a texture to modify the surface normal.– The geometric normal of the surface remains the same. We merely

modify the normal used in the lighting equation.• We perform changes on the surface normal, but the surface itself remains

smooth in the geometric sense.

Page 42: Computer Graphics  Spring 2009

42

Bump Mapping• Method 1(offset vector bump map or offset map): Store in a t

exture two signed values, bu and bv, at each point. – These two vectors are added to the normal to change its direction.

• Method 2: Use a heightfield to modify the surface normal’s direction.– The heightfield is used to derive u and v signed values.

Page 43: Computer Graphics  Spring 2009

43

Bump Mapping

• Two drawbacks– The illusion breaks down around the silhouettes of objects.

• The viewer notices that there are no real bumps, just smooth outlines.

– The bumps do not cast shadows onto their own surface, which can look unrealistic.

• More advanced real-time rendering methods can be used to provide self-shadowing effects.

Page 44: Computer Graphics  Spring 2009

44

Bump Mapping

• Emboss Bump Mapping– It is a way to give a chiseled look to an image.

• Render the surface with the heightfield applied as a diffuse monochrome texture.

• Shift all the vertex (u,v) coordinates in the direction of the light.• Render this surface with the heightfield again applied as a diffuse

texture, subtracting from the first-pass result. This gives the emboss effect.

• Render the surface again with no heightfield, diffusely illuminated and Gouraud-shaded. Add this shaded image to the result.

Page 45: Computer Graphics  Spring 2009

45

Bump Mapping

• Dot Product Bump Mapping– Instead of storing heights or slopes, the actual normals for

the surface are stored as (x,y,z) vectors in a normal map.– The bump texture, which consists of normals, is then com

bined with the interpolated light vector at each pixel.• These are combined by taking their dot product, which is a specia

l texture-blending function provided precisely for this purpose.

Page 46: Computer Graphics  Spring 2009

46

Bump Mapping

• Environment Map Bump Mapping (EMBM)– One way to give the appearance of bumpiness to a shiny s

urface.– The idea is to perturb (u,v) environment-mapping coordin

ates by u and v differentials found in the bump texture.• This gives the effect of wobbling the reflection vector, thereby di

storting the look of the reflected surface.