9.1si31_2001 si31 advanced computer graphics agr lecture 9 adding realism through texture

Post on 28-Mar-2015

216 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

9.1si31_2001

SI31Advanced Computer

GraphicsAGR

SI31Advanced Computer

GraphicsAGR

Lecture 9Adding Realism Through

Texture

9.2si31_2001

Adding RealismAdding Realism

Objects rendered using Phong reflection model and Gouraud or Phong interpolated shading often appear rather ‘plastic’ ‘plastic’ and ‘floating in ‘floating in air’air’

Addition of shadows (Lect 8) helps to plantplant the objects on a ground surface

In this lecture we look at how texture texture effects can be added to give more realistic looking surface appearance

9.3si31_2001

Adding Surface DetailAdding Surface Detail

The most obvious solution is not the best– breaking the scene into smaller and

smaller polygonal objects increases the detail

– ..BUT it is very hard to model and very time-consuming to render

Preferred solution is texture mapping – typically a 2D image ‘painted’ ‘painted’ onto

objects

9.4si31_2001

A Simple ExampleA Simple Example

Suppose we have a 2D image...

.. and a 3D box

.. we can paint the image on a face of the box

9.5si31_2001

… or a teapot… or a teapot

9.6si31_2001

Basic ConceptBasic Concept

Replace the shading calculation with a look-up into a texture map (ie 2D image) to get the colour of a pixel

May replace shaded value - or modulate it in some way

9.7si31_2001

QuestionQuestion

We could apply the texture in screen space (ie after projection)

... or we could apply it in object space (ie before projection)

Which is more sensible?

9.8si31_2001

Texture Mapping - Overview

Texture Mapping - Overview

screen space

I

J

object space

during scan conversionof each polygon, findcorresponding positionof pixel on object

texture space

V

U

X

Y

Z

paint textureon to object

9.9si31_2001

Texture Mapping : Mapping Textures to

Objects

Texture Mapping : Mapping Textures to

Objects

We need to establish a mapping from object space (x,y,z) to texture space (u,v)

– mapping functions

u=fu(x,y,z) and v=fv(x,y,z)

– given a point (x,y,z) on object, these functions give us a position (u,v) in texture space

object space

texture space

V

U

X

Y

Z

paint textureon to object

9.10si31_2001

Mapping Texture to Polygons

Mapping Texture to Polygons

For polygon texture mapping, we explicitly define the (u,v) co-ordinates of the polygon vertices

That is, we pin the texture at the vertices

We interpolate within the triangle at the time of scan converting into screen space

X

Z

Y

object

texture space

V

U

9.11si31_2001

Texture Mapping TrianglesTexture Mapping Triangles

(x1,y1,z1)

(x2,y2,z2) (x3,y3,z3)

(u1,v1)

(u2,v2) (u3,v3)

(i1,j1)

(i2,j2) (i3,j3)

Interpolation is doneduring scan conversion,similar as is done forGouraud interpolatedshading

But rather than interpolateto get RGB values, weget (u,v) values whichpoint to elements of texturemap.

9.12si31_2001

Interpolation in Texture Space

Interpolation in Texture Space

The interpolation in texture space has to be done carefully

Equal steps in screen space do not correspond to equal steps in object space (and hence texture space)

Why?

U

V

I

Jscreen

texture

A line is a line in all 3 spaces

X

Z

Y

object

9.13si31_2001

Interpolation in Texture Space

Interpolation in Texture Space

The rate of change in texture space will depend on the depth of the points from the viewer

Correct approach is to scale by the distance (zP, zQ) of the points from the viewer

U

Vtexture

I

Jscreen

P Q

P’Q’

If Q further away than P, then as we take equal steps from P towards Q, we want to take increasingly large steps in (U,V) space from P’ to Q’.

9.14si31_2001

Interpolation in Texture Space

Interpolation in Texture Space

Suppose (uP, vP) and (uQ,vQ) are texture co-ords at end-points P, Q

Linear interpolation would be:

– u = uQ + (1-)uP

with increasing from 0 to 1 (similarly for v)

Correct texture interpolation is:u = [ uQ / zQ + (1-)uP / zP ] / D

where D = [ / zQ + (1-)/ zP ]

U

Vtexture

P’Q’

I

Jscreen

P Q

Note: this is equivalentto a linear interpolationin projective space

9.15si31_2001

Check for YourselfCheck for Yourself

Suppose P is one unit from viewer, and Q is two units from viewer

Show that the mid-point in screen space is equivalent to one-third of the distance along the line in texture space

9.16si31_2001

Texture Mapping to an Object

Texture Mapping to an Object

How do we map to an entire object - rather than a polygon?

That is, how do we sensibly assign the texture co-ordinates to the polygon vertices?

object space

texture space

V

U

X

Y

Z

paint textureon to object

9.17si31_2001

Mapping Texture To Object

Mapping Texture To Object

This is achieved in two stages:

first: map texture to a simplesimple bounding shape

second: ‘project’ from bounding shape onto object itself

texture space

object spaceV

U

XY

Z

9.18si31_2001

Mapping to a CylinderMapping to a Cylinder

A simple bounding object for our bowl is a cylinder

We can wrap the texture around the cylinder as follows:– cylinder radius r, centre origin, has

equation

x = r cos , y = r sin , z– to wrap texture on to cylinder, we use

the mapping functions

u = = tan-1(y/x)

v = z

9.19si31_2001

ShrinkwrapShrinkwrap

We now need to ‘project’ from the bounding cylinder to the object

A common approach is shrinkwrappingshrinkwrapping

For an object position (x,y,z), we take the texture of the point (x’,y’,z’) on the bounding cylinder whose normal points at (x,y,z)

boundingcylinder

2d cross-section

9.20si31_2001

Intermediate Bounding Surfaces

Intermediate Bounding Surfaces

Other possible intermediate surfaces are:– box, sphere, plane

A simple default action is to calculate bounding box of object, map texture to box, and project from box to object

9.21si31_2001

Texture MappingTexture Mapping

This gives us a way of assigning the texture co-ordinates to the polygon vertices

We can then use the texture interpolation at scan conversion time

object space

texture space

V

U

X

Y

Z

9.22si31_2001

Planar Texture MappingPlanar Texture Mapping

9.23si31_2001

Cylindrical Texture Mapping

Cylindrical Texture Mapping

9.24si31_2001

Spherical Texture MappingSpherical Texture Mapping

9.25si31_2001

Texture ExtentTexture Extent

It is often useful to think of texture space having infinite extent

This can be achieved by replicating the image in texture space

V

U

9.26si31_2001

Summing UpSumming Up

We have seen how a 2D texture image can be mapped to an object, at the rendering stage– for a polygon, we pin texture to vertices and

interpolate (correctly!) at scan conversion time– assigning texture co-ordinates can be by

intermediate mapping The texture value is used to modifymodify the

colour that would otherwise be drawn– options include replacing completely, or

modulating (eg by multiplying shaded value with texture value)

9.27si31_2001

AcknowledgementsAcknowledgements

Thanks to Alan Watt for the images again

top related