• No results found

Image Mapping. A Very Powerful Computer Graphics Tool!

N/A
N/A
Protected

Academic year: 2021

Share "Image Mapping. A Very Powerful Computer Graphics Tool!"

Copied!
45
0
0

Loading.... (view fulltext now)

Full text

(1)

A Very Powerful Computer Graphics Tool!

Image Mapping

(2)

Our Current Renderer

(3)

The Problem:

• We don't want to represent all this detail with geometry

(4)

Texture Mapping: Motivation

► Scenes created with diffuse lighting look

convincingly three-dimensional, but are flat, chalky, and ''cartoonish''

► Phong lighting lets us simulate materials like plastic and (to a lesser extent) metal, but scenes still seem very cartoonish and unreal

► Big problem: polygons are too coarse-grained to usefully model fine surface detail

Solution: Texture mapping

(5)

Why Texture Maps?

+ =

Size and Speed = Efficiency

(6)

The Quest for Visual Realism

Model

Moctel + shqding

Model + shading

+Textures

At wh t point

cf o things st rl: · look ing re I ?

m r rtwotk of Jerem Sitn

I

(7)

Texture Mapping: Motivation

► Adding surface detail helps keep CG images from looking simple and sterile

► Explicitly modeling this detail in geometry can be very .

expensive

► Zebra stripes, wood grain, writing on a whiteboard

► Texture mapping pastes images onto the surfaces in

the scene, adding realistic fine detail without exploding

the geometry

(8)

Texture Mapping: Examples

(9)

Texture Mapping

► In short: it is impractical to explicitly model fine surface detail with geometry

► Solution: use images to capture the "texture" of surfaces

► Texture maps can modulate many factors that affect the rendering of a surface

► Color or reflectance (diffuse, ambient, specular)

► Transparency (smoke effects)

What else?

(10)

Texture Mapping: Fundamentals

► A texture is typically a 2-D image

► Image elements are called texels

► Value stored at a texel affects surface appearance in some way

► Example: diffuse reflectance, shininess, transparency ...

The mapping of the texture to the surface determines the correspondence, i.e., how the texture lies on the surface

► Mapping a texture to a triangle is easy (why?)

► Mapping a texture to an arbitrary 3-D shape is more complicated

(why?)

(11)

Texture Mapping

► Increase the apparent complexity of

simple geometry

► Like wallpapering or gift-wrapping with stretchy paper

► Curved surfaces require extra

stretching or even cutting

I $

(12)

Photo-textures

>l"'_, =·ilr

(13)

Texture Coordinates – s, t

(14)

Planar Texture Projection

(15)

Texture Mapping in OpenGL (checker.c)

#include <GL/glut.h>

#include <stdlib.h>

#include <stdio.h>

/* Create checkerboard texture */

#define

#define

checkimageWidth 64 checkimageHeight64

static GLubyte checkimage[checkimageHeight][checkimageWidth][4];

static GLuint tex:Name;

void makeCheckimage(void)

int iI jI C;

for (i = 0; i < checkimageHeight; i++) { for (j 0; j < checkimageWidth; j++)

c = ( ( ((i&0x8)= 0)"( (j &0x8))= 0))*255;

checkimage[i][j][0]

checkimage[i][j][1]

checkimage[i][j][2]

checkimage[i][j][3]

(GLubyte) c;

(GLubyte) c;

(GLubyte) c;

(GLubyte) 255;

(16)

void init(void)

{ glClearColor (0.0, 0.0, 0.0, 0.0);

glShadeModel(GL_FLAT);

glEnable(GL_DEPTH_TEST);

makeCheckimage();

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glGenTextures(l, &texName);

glBindTexture(GL_TEXTURE 2D, texName);

glTexParameteri(G_LTEXTURE_2D, GL TEXTURE_WRAP_S, GL REPEAT);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL REPEAT);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL NEAREST);

glTexParameteri(GL_TEXTURE_2D, GL TEXTURE_MIN_FILTER, GL NEAREST);

glTeximage2D(GL TEXTURE 2D, 0, GL RGBA, checkimageWidth, checkimageHeight, 0, GL RGBA, GL UNSIGNED BYTE, checkimage);

(17)

void display(void)

{ glClear(GL_COLOR_BUFFER BIT I GL DEPTH BUFFER BIT);

g1Enable(GL_TEXTURE_2D);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL DECAL);

glBindTexture(GL TEXTURE 2D, texName);

glBegin(GL_QUADS);

glTexCoord2f(0.0, 0.0); g1Vertex3f(-2.0, -1.0, 0.0);

glTexCoord2f(0.0, 1.0); g1Vertex3f(-2.0, 1.0, 0.0);

glTexCoord2f(l.0, 1.0); g1Vertex3f(0.0, 1.0, 0.0);

glTexCoord2f(l.0, 0.0); g1Vertex3f(0.0, -1.0, 0.0);

glTexCoord2f(l.0, glEnd();

glFlush();

glTexCoord2f(0.0, 0. 0) ; glTexCoord2f(0.0, 1 . 0) ; glTexCoord2f(l.0, 1. 0) ; 0. 0) ;

glDisable(GL TEXTURE 2D);

}

g1Vertex3f(l.0, -1.0, 0.0);

g1Vertex3f(l.0, 1.0, 0.0);

g1Vertex3f(2.41421, 1.0, -1.41421);

g1Vertex3f(2.41421, -1.0, -1.41421);

(18)

void reshape(int w, int h)

{ glViewport(0, 0, (GLsizei) w, (GLsizei) h);

glMatrixMode(GL_PROJECTION);

glLoadidentity();

gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0);

glMatrixMode(GL_MODELVIEW);

glLoadidentity();

glTranslatef(0.0, 0.0, -3.6);

void keyboard (unsigned char key, int x, int y) switch (key) {

case 27:

exit(0);

break;

default:

break;

int main(int argc, char** argv) glutinit(&argc, argv);

glutinitDisplayMode(GLUT SINGLE I GLUT RGB glutinitWindowSize(250, 250);

glutinitWindowPosition(l00, 100);

glutCreateWindow(argv[0]);

init();

glutDisplayFunc(display);

glutReshapeFunc(reshape);

glutKeyboardFunc(keyboard);

glutMainLoop();

return 0;

GLUT DEPTH);

(19)

Output (checker.c)

·· · checker RlilEi

(20)

Texture Mapping Difficulties

► Tedious to specify texture coordinates

► Acquiring textures is surprisingly difficult

► Photographs have projective distortions

► Variations in reflectance and illumination

► Tiling problems

Can't do this!

ruucw,xetaro111ul lhls prvblttmfor planars111fo,-esif

ro11spe,·tf.i·./ pmnts...

(21)

Common Texture Coordinate Mappings

Orthogonal

Cylindrical

Spherical

Perspectiv e Projection

Texture

Chart

(22)

► Pack triangles

into a single image

(23)

What's Missing?

► What's the difference between a real brick wall and a photograph of the

wall texture-mapped onto a plane?

► What happens

if we change

the lighting or

the camera

position?

(24)

What Tools Do We have Now?

• Have Images that store data that can be accessed at render time.=fast, small

• Have several different ways to map data to geometry: Planar, Spherical, … =flexible

• So what could we do with this?

(25)

Advanced Mapping

(26)

Texture Mapping & Illumination

► Texture mapping can be used to alter some or all of the constants in the illumination equation:

► pixel color, diffuse color, alter the normal, ....

!

1

tot al = a k a l m bietn + f

l=1

i 1 ( kA fl· i) + s k (V · R m r ,;ny )

Phong'sIllumination Model

Constant Diffuse Color Diffuse Texture Color Texture used asLabel Texture used as Diffuse Color

(27)

Bump Mapping

► Use textures to alter the surface normal

► Does not change the actual shape of the surface

► Just shaded as if it were a different shape

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

(28)

Bump Mapping

► Treat the texture as a single-valued height function

► Compute the normal from the partial derivatives in the texture

N

p p

...

···

(29)

Another Bump Map Example

Cylinder w/Diffuse Texture Map

■■■■■■■■

I

■■■■■■■■

I

■■■■■■■

I

■■■■■■■■

I

■■■■■■■■

Bump Map

► Demo CrazyMap

Cylinderw/Texture Map&Bump Map

(30)

What's Missing?

► There are no bumps on the silhouette of a

bump-mapped object

Bump maps

don't allow self-occlusion

or self-shadowing

(31)

Displacement Mapping

► Use the texture map to actually move the surface point

► The geometry must be displaced before visibility is

determined

(32)

Displacement Mapping

Image from:

Geometry Cachingfor

Ray-Tracing Displacement Maps by Matt Pharr and Pat Hanrahan.

note the detailed shadorvs

cast by the stones

(33)

Displacement Mapping

► Ken Musgrave

(34)

Procedural Textures

f (x,y,z) > color

Image by Turner Whitted

(35)

ProceduralTextures

► Advantages:

► easy to implement in ray tracer

► more compact than texture maps (especially for solid textures)

► infinite resolution

► Disadvantages

► non-intuitive

► difficult to match existing texture

(36)

Examples of Procedural Textures

Justin Legakis

Justin Legakis Ken Perlin

Demo:

http://graphics.lcs.1nit.edu/classes/6.837/F98/Lecture22/Slide27.ht1nl

(37)

Environment Maps

► We can simulate reflections by using the direction of the reflected ray to index a spherical texture map at "infinity".

► Assumes that all reflected rays begin from the same point.

View Point

Environment map on a sphere

Object

(38)

What's the Best Chart?

- - - l atit tued 1l1np

Box1Wnp

GL/t1np

(39)

Environment Mapping Example

-

· ==== -

- -

,.. - ,, · , - . - .. - ;)"

Terminator II

(40)

Environment mapping example

Image by Henrik Wann Jensen

Environment map by Paul Debevec

(41)

Illumination Maps

► Quake introduced illumination maps or light maps to capture lighting effects in video games

Texture map:

Light map

► Texture map

+ light map:

(42)

Illumination Maps

Also called "Light Maps"

Quake _

(43)

Illumination Maps

• Illumination maps differ from texture maps in that they:

- Usually apply to only a single surface - Are usually fairly low resolution

- Usually capture just intensity (1 value) rather than color (3 values)

• Illumination maps can be:

- Painted by hand: Disney's Aladdin ride

- Calculated by a global illumination process

(44)

Other Texture Applications

• Lots of other interesting applications of the texture-map concept (we'll return to some):

- Shadow maps

- 3-D textures (marble, wood, clouds) - Procedural textures

- Environment maps & cube maps

• For a neat explanation of the first three (with cool applets, as usual) check out:

► http://graphics.lcs.mit .edu/classes/6.837/F98/Lecture22/Slide2I.htmI

(45)

End Part I

References

Related documents

Dichos resultados muestran que los multiplicadores que operan en paralelo, como son los multiplicadores de Mastrovito para polinomios generales, para AOPs y para base normal

Given the lack of con- sistent estimates to aid health policy and district management, this paper reports the maternal mortality risk and MMR for Kilombero District obtained with

solar cell concept: interdigitated back-junction structure with virtually 100% emitter coverage of the cell area, in: Proceedings of the 24th European Photovoltaic Solar

For the high- temperature case (1201 K), the reflected shock pressure increases gradually before the main ignition event; it leads a third stage ignition behavior during the

– Macro scale: describes scene geometry (triangulated mesh) Macro scale: describes scene geometry (triangulated mesh) – Meso scale: fine scale geometric detail (displacement map)

– Macro scale: describes scene geometry (triangulated mesh) Macro scale: describes scene geometry (triangulated mesh) – Meso scale: fine scale geometric detail (displacement map)

– Macro scale: describes scene geometry (triangulated mesh) Macro scale: describes scene geometry (triangulated mesh) – Meso scale: fine scale geometric detail (displacement map)

An example of reflection mapping. In computer graphics, environment mapping, or reflection mapping, is an efficient Image-based lighting technique for approximating the appearance of