1gr2-00 gr2 advanced computer graphics agr lecture 9 adding realism through texture

24
1 GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

Upload: juan-miles

Post on 28-Mar-2015

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

1GR2-00

GR2Advanced Computer

GraphicsAGR

GR2Advanced Computer

GraphicsAGR

Lecture 9Adding Realism Through

Texture

Page 2: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

2GR2-00

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

Page 3: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

3GR2-00

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

Page 4: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

4GR2-00

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

Page 5: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

5GR2-00

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

Page 6: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

6GR2-00

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?

Page 7: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

7GR2-00

Texture Mapping - Overview

Texture Mapping - Overview

screen space

I

J

texture space

object space

V

U

X

Y

Z

Page 8: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

8GR2-00

Texture Mapping - Screen to Object

Texture Mapping - Screen to Object

For each screen pixel (i,j), we calculate the corresponding object position (x,y,z)– we can do this during z-buffer rendering– apply inverse transformations to get

from projection co-ordinates back to modelling co-ordinates

– this gives the corresponding (x,y,z) position

How can we map the texture image to the object?

Page 9: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

9GR2-00

Texture Mapping - Mapping Textures To

Objects

Texture Mapping - Mapping Textures To

Objects

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

u = fu(x,y,z) and v = fv(x,y,z)– given a point (x,y,z) on an object,

these functions give us a position (u,v) in texture space - and hence an element in the texture image

Page 10: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

10GR2-00

Texture Mapping - Mapping Textures to

Objects

Texture Mapping - Mapping Textures to

Objects

u = fu(x,y,z)

v = fv(x,y,z)

How can we calculate fu and fv?

texture space

object space

V

U

X

Y

Z

Page 11: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

11GR2-00

Texture Mapping - Two Approaches

Texture Mapping - Two Approaches

There are two approaches: map texture image to entire

objectie fu, fv calculated per object

map texture image to each polygonal facet separatelyie fu, fv calculated per polygon

Page 12: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

12GR2-00

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

Page 13: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

13GR2-00

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

Page 14: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

14GR2-00

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

Page 15: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

15GR2-00

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

Page 16: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

16GR2-00

Planar Texture MappingPlanar Texture Mapping

Page 17: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

17GR2-00

Cylindrical Texture Mapping

Cylindrical Texture Mapping

Page 18: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

18GR2-00

Spherical Texture MappingSpherical Texture Mapping

Page 19: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

19GR2-00

Polygon Texture MappingPolygon Texture Mapping

This is now increasingly common approach

With each vertex of polygon, associate a texture co-ordinate

(x1,y1,z1)

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

(u1,v1)

(u2,v2) (u3,v3)

So:u1=fu(x1,y1,z1)etc

Page 20: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

20GR2-00

How to Texture Map Interior

How to Texture Map Interior

There are now two possibilities:– try to define fu, fv at every interior

point (x,y,z) by interpolation in the 3D object space

– relate the texture co-ordinates to the pixel positions (i,j) of the projected vertices and interpolate in 2D screen space

Discuss!

Page 21: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

21GR2-00

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.

Page 22: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

22GR2-00

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

Page 23: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

23GR2-00

Summing UpSumming Up

We have seen how a 2D texture image can be mapped to an object, at the rendering stage– either per object or per polygon

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)

Page 24: 1GR2-00 GR2 Advanced Computer Graphics AGR Lecture 9 Adding Realism Through Texture

24GR2-00

AcknowledgementsAcknowledgements

Thanks to Alan Watt for the images again