cs 3388 texture mapping n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
CS 3388: Texture Mapping PowerPoint Presentation
Download Presentation
CS 3388: Texture Mapping

Loading in 2 Seconds...

play fullscreen
1 / 19

CS 3388: Texture Mapping - PowerPoint PPT Presentation


  • 130 Views
  • Uploaded on

CS 3388: Texture Mapping. [Hill § 8.5]. Enemy Territory: Quake Wars . Per-vertex colour not enough. In real objects, large changes to shape less frequent than large changes in colour. colour change: red vs white. shape change: almost flat!.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'CS 3388: Texture Mapping' - tacy


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
cs 3388 texture mapping

CS 3388: Texture Mapping

[Hill §8.5]

Enemy Territory: Quake Wars

per vertex colour not enough
Per-vertex colour not enough...
  • In real objects, large changes to shape less frequent than large changes in colour

colour change: red vs white

shape change: almost flat!

Do we build this wall out of 1,000 vertices

of different colours?

Or ... only 4 vertices + “brick texture”!

texture mapping
Texture Mapping
  • Instead of interpolating solid colour...
  • Interpolate (x,y) location in bitmap and then sample current(x,y)to get colour!

thousands of vertices

dozens of vertices

+ texture

vs.

bitmap mapping texture mapping
Bitmap + Mapping = Texture Mapping!

texture (bitmap)

texture coordinates (per-vertex)

+

= texture mapped

mesh

very few vertices

very complex colour!

re use vertices with new texture
Re-use Vertices with New Texture!

texture 1

texture 2

mesh 1

mesh 2

texture coordinates texcoords
Texture Coordinates (texcoords)

3D positions

2D texcoords

  • Each vertex has position (x,y,z) in space and position (u,v) in texture
  • Colour at (x,y,z)is texture[u,v]

(u0,v0)

(x0,y0,z0)

(x2,y2,z2)

(x1,y1,z1)

(u1,v1)

(u2,v2)

sample the texture at (u,v)

texture coordinates texcoords1
Texture Coordinates (texcoords)

3D positions

2D texcoords

  • Texture coordinates t= (u,v)2 [0,1]2
    • note textbook/opengl call them (s,t), but in general this is called “u-v mapping” in 3D modeling software, so we call them (u,v)

t0 = (0,0)

p0

p2

t1= (0,1)

p1

t2= (1,1)

texture coordinates texcoords2
Texture Coordinates (texcoords)

3D positions

2D texcoords

  • Given p on triangle what’s corresponding t?
  • If (®,¯,°)is barycentriccoord of p, coord then (®,¯,°) is alsobarycentriccoord of t!

t0 = (0,0)

p0

p

t

p2

t1= (0,1)

p1

t2= (1,1)

perspective correction

[Hill §8.5.2]

Perspective Correction
  • The (®,¯,°)must be barycentriccoord of the 3D point, not 2D screen coordinate!
  • All modern hardware supports perspective correct texture mapping

interpolate (u,v) based on 2Dscreen coords

interpolate (u,v)based on 3D eye coords

halfway mark in ...

screen coords 3D coords

linear

non-linear

opengl texture mapping pre 3 0
OpenGL Texture Mapping (pre-3.0)
  • See texture_demo.cpp documentation
texture sampling filtering
Texture Sampling (“Filtering”)

Texture pixel = “texel”

Q: what should colour of this pixel be?

... and what about this pixel?

avg = 1

avg¼ 0.6

A: integrated colour (average colour)

over corresponding area in texture

But how do we integrate texture for each pixel??

(slow? complex? or is there a fast hacky trick?)

hack solution mip mapping
Hack Solution: Mip Mapping
  • Pre-compute low-frequency versions of the texture

(a “mipmap”)

128£128

64£64

get avg of 64 samples here

by taking just 1 sample here!

glGenerateMipmap(GL_TEXTURE_2D);

16£16

32£32

how to visualize mip map sampling
How to Visualize Mip-Map Sampling
  • Manually load solid colour texture at each mipmap level!

sampling of fake colour-coded mipmaps

(yellow=128£128 white = 1£1)

sampling of actual texture mipmaps

minification

magnification

opengl texture filtering
OpenGL Texture Filtering
  • Two cases to configure
    • magnification: what should OpenGL do when a screen pixel maps to region smaller than a texel?
    • minification: what if screen pixel maps to region much larger than a texel?
  • Configure mode of bound texture

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,mag_mode);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,min_mode);

// where mag_mode = GL_NEAREST or GL_LINEAR

// where min_mode= GL_NEAREST or GL_LINEAR or GL_LINEAR_MIPMAP_LINEAR

opengl texture wrapping
OpenGL Texture Wrapping
  • Some textures repeat over and over...

2004 George Bush campaign ad

opengl texture wrapping1
OpenGL Texture Wrapping
  • Some textures repeat over and over...
  • If interpolated (u,v)is outside texmap range [0,1]2, where should we sample?
    • GL_CLAMP_TO_EDGE: clamp u and v to range [0,1]
    • GL_REPEAT: take fractional part of u and v

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,wrap_mode); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,wrap_mode);

// where wrap_mode = GL_CLAMP_TO_EDGE or GL_REPEAT

clamped

repeated once

repeated four times

6£6 texture

anisotropic sampling filtering
Anisotropic Sampling/Filtering
  • Normal mip-maps are isotropic: they blur same amount in each direction.
  • Pixel may project onto highly stretched region in texture
  • Anisotropic filtering uses “rip-maps” to sample more in u than in v etc.
anisotropic sampling filtering1
Anisotropic Sampling/Filtering
  • Avoids oblique textures looking blurred
anisotropic sampling filtering2
Anisotropic Sampling/Filtering
  • Higher-detail samples in one dimension