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

Post on 16-Jan-2016

221 views 0 download

Tags:

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

Texture Mapping

Fall, 2011

Textures

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

to values fetched from a texture

The Quest for Visual Realism

Surface Textures

Add visual detail to surfaces of 3D objects

3D Rendering Pipeline

Texture Mapping

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

Parameterization

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

Option: Varieties of projections

Cylinder Mapping Sphere MappingCube MappingPlane Mapping

Option: unfold the surface

Option: make an atlas

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

Texture Mapping

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

Texture Mapping

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

Texture Mapping

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

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

Texture Mapping

Linear interpolation Perspective-correct interpolation

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

Texture Filtering

Must sample texture to determine color at each pixel in image

Texture Filtering

Aliasing is a problem

Point Sampling Area Filtering

Texture Filtering

Ideally, use elliptically shaped convolution filters

Texture Filtering

Size of filter depends on projection warp Can prefiltering images

• Mip maps

• Summed area tables

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

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

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

Modulation textures

Map texture values to scale factor

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

++++

Bump Mapping

Texture values perturb surface normals

geometry Bump mapStores heights: can derive normals

+Bump mapped geometry

=

Bump Mapping

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

Displacement Mapping (Result)

Displacement Offset

Environment Mapping

Texture values are reflected off surface patch

Cube Mapping

Cube mapping is the norm nowadays

x

y

z

neye

Image-Based Rendering

Map photographics textures to provide details for coarsely detailed polygon model

Solid Textures

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

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

Example)Quake 2 Models: Piece by Piece

Model Key Frames

Quake 2 interpolates between key frames

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.

Example)Standard Quake 2: Model Rendering

Texture key-frame with decal skin

++++

ResultResultResultResult

Key-frameKey-framemodelmodelgeometrygeometry

Key-frameKey-framemodelmodelgeometrygeometry DecalDecal

skinskinDecalDecalskinskin

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

++++

Example)Quake 2 Bump Mapping: Rendering Passes

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

DiffuseDiffuseDiffuseDiffuse GlossGlossGlossGlossSpecularSpecularSpecularSpecularDecalDecalDecalDecal

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

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!

Example)Bump Mapping Models

Viva la difference

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

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

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);

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

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();

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);

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

No mipmapping Mipmappping

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

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);

OpenGL Texture Mapping: Texture Functions