Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon When scan...

52
Texture Mapping Fall, 2011

Transcript of Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon When scan...

Page 1: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Mapping

Fall, 2011

Page 2: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Textures

Describe color variation in interior of 3D polygon When scan converting a polygon, vary pixel colors according

to values fetched from a texture

Page 3: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

The Quest for Visual Realism

Page 4: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Surface Textures

Add visual detail to surfaces of 3D objects

Page 5: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

3D Rendering Pipeline

Texture Mapping

Page 6: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Mapping Overview

Texture mapping methods Parameterization Mapping Filtering

Texture mapping applications Modulation textures Illumination mapping Bump mapping Environment mapping Image-based rendering Non-photorealistic rendering

Page 7: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Parameterization

Q: How do we describe where on the geometry each color from the image should go?

Page 8: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Option: Varieties of projections

Cylinder Mapping Sphere MappingCube MappingPlane Mapping

Page 9: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Option: unfold the surface

Page 10: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Option: make an atlas

Page 11: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Mapping Overview

Texture mapping methods Parameterization Mapping Filtering

Texture mapping applications Modulation textures Illumination mapping Bump mapping Environment mapping Image-based rendering Non-photorealistic rendering

Page 12: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Mapping

Steps: Define texture Specify mapping from texture to surface Lookup texture values during scan conversion

Page 13: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Mapping

When scan convert, map from … Image coordinate system (x, y) to Modeling coordinate system (u, v) to Texture image (t, s)

Page 14: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Mapping

Texture mapping is a 2D projective transformation Texture coordinate system (t, s) to Image coordinate system (x, y)

Page 15: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Mapping

Scan conversion Interpolate texture coordinates down/across scan lines Distortion due to bilinear interpolation approximation

• Cut polygons into smaller ones, or

• Perspective divide at each pixel

Page 16: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Mapping

Linear interpolation Perspective-correct interpolation

Page 17: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Mapping Overview

Texture mapping methods Parameterization Mapping Filtering

Texture mapping applications Modulation textures Illumination mapping Bump mapping Environment mapping Image-based rendering Non-photorealistic rendering

Page 18: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Filtering

Must sample texture to determine color at each pixel in image

Page 19: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Filtering

Aliasing is a problem

Point Sampling Area Filtering

Page 20: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Filtering

Ideally, use elliptically shaped convolution filters

Page 21: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Filtering

Size of filter depends on projection warp Can prefiltering images

• Mip maps

• Summed area tables

Page 22: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Mip Maps

Keep textures prefiltered at multiple resolutions For each pixel, linearly interpolate between two closest

levels (e. g. trilinear filtering) Fast, easy for hardware

u

v

d

Page 23: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Summed-area tables

At each texel keep sum of all values down & right To compute sum of all values within a rectangle, simply

subtract two entries Better ability to capture very oblique projections But, cannot store values in a single byte

CBAColCol totalpix

Page 24: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Mapping Overview

Texture mapping methods Parameterization Mapping Filtering

Texture mapping applications Modulation textures Illumination mapping Bump mapping Environment mapping Image-based rendering Non-photorealistic rendering

Page 25: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Modulation textures

Map texture values to scale factor

Page 26: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Illumination Mapping

Map texture values to surface material parameter KA

KD

KS

KT

n

Key-frameKey-framemodelmodelgeometrygeometry

Key-frameKey-framemodelmodelgeometrygeometry DecalDecal

skinskinDecalDecalskinskin

BumpBumpskinskinBumpBumpskinskin

GlossGlossskinskinGlossGlossskinskin

WOW!WOW!ResultResultWOW!WOW!ResultResult

++++

Page 27: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Bump Mapping

Texture values perturb surface normals

geometry Bump mapStores heights: can derive normals

+Bump mapped geometry

=

Page 28: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Bump Mapping

Page 29: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Displacement Mapping

Normal Mapping Problem Doesn’t take into account geometric surface depth

• Does not exhibit parallax

• No self-shadowing of the surface

• Coarse silhouettes expose the actual geometry being drawn

Displacement Mapping Displace actual positions from Heightfield Map

Page 30: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Displacement Mapping (Result)

Displacement Offset

Page 31: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Environment Mapping

Texture values are reflected off surface patch

Page 32: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Cube Mapping

Cube mapping is the norm nowadays

x

y

z

neye

Page 33: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Image-Based Rendering

Map photographics textures to provide details for coarsely detailed polygon model

Page 34: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Solid Textures

Texture values indexed by 3D location (x, y, z) Expensive storage, or Compute on the fly ex) Perlin Noise

Page 35: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Texture Mapping Summary

Texture mapping methods Parameterization Mapping Filtering

Texture mapping applications Modulation textures Illumination mapping Bump mapping Environment mapping Image-based rendering Volume textures

Page 36: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Example)Quake 2 Models: Piece by Piece

Model Key Frames

Quake 2 interpolates between key frames

Page 37: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Example)Quake 2 Models: Piece by Piece

Knight model’s decal skin

Texture coordinates mapTexture coordinates maptriangles to skin.triangles to skin.

Note clever packing ofNote clever packing ofdecal skin. Only halfdecal skin. Only halfface because trianglesface because triangles““mirror” the face.mirror” the face.

Page 38: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Example)Standard Quake 2: Model Rendering

Texture key-frame with decal skin

++++

ResultResultResultResult

Key-frameKey-framemodelmodelgeometrygeometry

Key-frameKey-framemodelmodelgeometrygeometry DecalDecal

skinskinDecalDecalskinskin

Page 39: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Example)GPU Bump-mapped: Quake 2 Model Rendering!

Bump-map model with bump, gloss, & decal skin

Key-frameKey-framemodelmodelgeometrygeometry

Key-frameKey-framemodelmodelgeometrygeometry DecalDecal

skinskinDecalDecalskinskin

BumpBumpskinskinBumpBumpskinskin

GlossGlossskinskinGlossGlossskinskin

WOW!WOW!ResultResultWOW!WOW!ResultResult

++++

Page 40: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Example)Quake 2 Bump Mapping: Rendering Passes

) + () + () + () + ((((( ) =) =) =) =

DiffuseDiffuseDiffuseDiffuse GlossGlossGlossGlossSpecularSpecularSpecularSpecularDecalDecalDecalDecal

Final result!Final result!Final result!Final result!

Page 41: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Example)More Bump-mapped Knight Examples

Different light positions and key-frames

All lighting including specular is computed per-fragment!All lighting including specular is computed per-fragment!All lighting including specular is computed per-fragment!All lighting including specular is computed per-fragment!

Page 42: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Example)Bump Mapping Models

Viva la difference

Page 43: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

OpenGL Texture Mapping

Texture Mapping in OpenGL Allows you to modify the color of a polygon surface Textures are simply rectangular arrays of data (color,

luminance, color+alpha). Individual values in a texture are called texels

Page 44: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

OpenGL Texture Mapping: Step

Steps necessary to use texture mapping: Create a texture object and specify the texture Indicate how the texture is to be applied to each pixel Enable texture mapping Draw the scene, supplying both texture and geometric

coordinates

Page 45: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

OpenGL Texture Mapping: 2D Texture Specification

2D Texture Specification glTexImage2D(GLenum target, GLint level, GLint

internalFormat, GLsizei width, GLsizei height, Glint border, GLenum format, Glenum type, const Glvoid *pixels);

• target: GL_TEXTURE_2D• level: specifies the level of detail when using multi

resolution textures. “0” is the base image, “n” is the n-th mipmap reduction image

• internalFormat: an integer 1 to 4, or one of 38 symbolic constants

• width, height: the dimensions of the texture (MUST BE power of 2)

• format: the kind of pixel-data elements• type: the data-type of each element• pixels: array containing the texture image data

Ex) glTexImage2D(GL_TEXTURE_2D, 0, 3, iwidth, iheight, 0, GL_RGB, GL_UNSIGNED_BYTE, image);

Page 46: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

OpenGL Texture Mapping: Values for Format and Type

Format Constants: GL_COLOR_INDEX: A single color index GL_RGB: A red component, followed by green & blue components GL_RGBA: Like GL_RGB, followed by an alpha component. GL_RED: A single red-color component GL_GREEN: A single green-color component GL_BLUE: A single blue-color component GL_ALPHA: A single alpha-color component

Type Constants: GL_UNSIGNED_BYTE: unsigned 8-bit integer GL_BYTE: signed 8-bit integer GL_UNSIGNED_SHORT: unsigned 16-bit integer GL_SHORT: signed 16-bit integer GL_INT: signed 32-bit integer GL_FLOAT: single-precision floating point

Page 47: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

OpenGL Texture Mapping: Texture Coordinates

Texture Coordinates You need to specify BOTH texture & geometric

coordinates as you specify the object in your scene

glColor3f(1.0f, 0.0f, 0.0f);glBegin(GL_TRIANGLES);

glNormal3d(0,0,-1);glTexCoord2d(0,0);

glVertex3d(-100,-100,0); glTexCoord2d(1,0);glVertex3d(100,-100,0);glTexCoord2d(0,1);glVertex3d(-100,100,0);

glEnd();

Page 48: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

OpenGL Texture Mapping: Texture Filtering

glTexParameteri( target, type, mode) Target : GL_TEXTURE_1D, GL_TEXTURE_2D Type : GL_TEXTURE_MIN_FILTER Mode :

• GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR

Type : GL_TEXTURE_MAG_FILTER• GL_NEAREST or GL_LINEAR

Ex) glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MIN_FILTER, GL_LINEAR);

Page 49: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

Min / Max Filter : GL_NEAREST Min / Max Filter : GL_LINEAR

No mipmapping Mipmappping

Page 50: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

OpenGL Texture Mapping: Texture Wrapping

glTexParameteri( target, type, mode) Target : GL_TEXTURE_1D, GL_TEXTURE_2D Type

• GL_TEXTURE_WRAP_S

• GL_TEXTURE_WRAP_T mode

• GL_CLAMP or GL_REPEAT

Wrap S : GL_CLAMPWrap T : GL_CLAMP

Wrap S : GL_CLAMPWrap T : GL_REPEAT

Wrap S : GL_REPEATWrap T : GL_CLAMP

Wrap S : GL_REPEATWrap T : GL_REPEAT

Page 51: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

OpenGL Texture Mapping: Texturing Functions

Texturing Functions Indicate how the texture is applied to each pixel: REPLACE or DECAL: Texture is painted on top of the

fragment MODULATE: Combine texture with fragment color. This

technique is useful to combine the effects of lighting with texturing

BLEND: A constant color is blended with that of the fragment, based on the texture value

Ex) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

Page 52: Texture Mapping Fall, 2011. Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.

OpenGL Texture Mapping: Texture Functions