texture mapping cap4730: computational structures in computer graphics
Post on 14-Jan-2016
238 Views
Preview:
TRANSCRIPT
Texture MappingTexture Mapping
CAP4730: Computational Structures in Computer Graphics
OutlineOutline
What is texture mapping?What is texture mapping? Math behind texture mappingMath behind texture mapping OpenGL texture mappingOpenGL texture mapping Advanced Topics in texture Advanced Topics in texture
mappingmapping
Marching towards Visual Marching towards Visual RealismRealism
http://www.3drender.com/jbirn/productions.html
How do we do this?How do we do this?
Another ExampleAnother Example
Using only TrianglesUsing only Triangles
Using only triangles to Using only triangles to model everything is hardmodel everything is hard
Think about a label on a Think about a label on a soup cansoup can
Instead of interpolating Instead of interpolating colors, map a patterncolors, map a pattern
Run DemoRun Demo How do you create a How do you create a
pattern?pattern?
TextureTexture
A color array that holds an imageA color array that holds an image Similar to a framebufferSimilar to a framebuffer gluint buffer[x*y*3]gluint buffer[x*y*3] 255 0 255255 0 255
Procedural TextureProcedural Texture
Calculate pixel values via functionsCalculate pixel values via functions
Image TexturesImage Textures
Load pixel values from a file
Let’s look at some gamesLet’s look at some games
Texture SpaceTexture Space
How would you store this in your How would you store this in your program?program?
How much memory?How much memory?s
t
s = [0…1]
t = [0…1]
Object SpaceObject Space
s
t
(u0,v0)
(u1,v1)
(u2,v2)
(u3,v3)
Texture -> Object
Transformation
s = [0…1]
t = [0…1]
u = [0…1]
v = [0…1]
Going from pixels to Going from pixels to texturestextures
Object -> Texture Transformation Image -> Object Transformation
(s,t) (u,v) (x,y)
What is the question?What is the question? A pixel (x,y) corresponds to A pixel (x,y) corresponds to
what texture element (s,t)?what texture element (s,t)? Q: How do we convert (Q: How do we convert (ss,,tt) )
into texture element into texture element coordinates?coordinates?
TEXture Elements (TEXELS)TEXture Elements (TEXELS) A: Linearly Interpolate A: Linearly Interpolate
texture coordinates!texture coordinates! http://graphics.lcs.mit.edu/http://graphics.lcs.mit.edu/
classes/6.837/F98/classes/6.837/F98/Lecture21/Slide05.htmlLecture21/Slide05.html
TilingTiling
Let’s look at the texture Let’s look at the texture coordinatescoordinates
s
t
(u0,v0)(u1,v1)
(u2,v2)(u3,v3)
Textures built to TileTextures built to Tile Think Windows BackgroundThink Windows Background
Why would you want this? Discuss the Why would you want this? Discuss the Pros and Cons of tiling. Pros and Cons of tiling.
Look at codeLook at code
0,0
1,10,1
1,0 0,0
2,20,2
2,0
FilteringFiltering
Why does this happen?Why does this happen?(u0,v0)
(u1,v1)
(u2,v2)
FilteringFiltering
Why does this happen?Why does this happen?
What are some alternatives?What are some alternatives?
(uj,vj)(ui,vi)
Combining Lighting + Combining Lighting + TexturingTexturing
If you notice there is no lighting If you notice there is no lighting involved with texture mapping!involved with texture mapping!
They are independent operations, They are independent operations, which MAY (you decide) be which MAY (you decide) be combinedcombined
It all depends on how you “apply” It all depends on how you “apply” the texture to the underlying the texture to the underlying triangletriangle
Combining Lighting + Combining Lighting + TexturingTexturing
CCTT = Texture Color = Texture Color
CCC C = Base Triangle = Base Triangle
Replace, CReplace, CFF = C = CTT
Blend, CBlend, CFF = C = CTT * C * CCC
OpenGL:OpenGL:– glTexEnv(GL_TEXTURE_ENV, glTexEnv(GL_TEXTURE_ENV,
GL_TEXTURE_ENV_MODE, GL_BLEND);GL_TEXTURE_ENV_MODE, GL_BLEND);– http://trant.sgi.com/opengl/docs/man_pages/http://trant.sgi.com/opengl/docs/man_pages/
hardcopy/GL/html/gl/texenv.htmlhardcopy/GL/html/gl/texenv.html
Screen space vs. world Screen space vs. world spacespace
P0(x,y,z)
P1(x,y,z)
V0(x,y)
V1(x,y)
Interpolation in Screen Interpolation in Screen SpaceSpace
P0(x,y,z)
P1(x,y,z)
V0(x’,y’)
V1(x’,y’)
0
0
1
1
0
0
010
z
x
z
xt
z
xtP
VVtVtP
z’=1
Interpolation in World Interpolation in World SpaceSpace
P0(x,y,z)
P1(x,y,z)
V0(x’,y’)
V1(x’,y’)
0
0
1
1
0
0
010
z
x
z
xs
z
xtP
PPsPtP
z’=1
Comparing the twoComparing the two
What do we need to interpolate in What do we need to interpolate in screen space now?screen space now?
What happens if we don’t have Z? What happens if we don’t have Z? What have we discussed that What have we discussed that doesn’doesn’t have Z?
Perspectively Correct Z http://graphics.lcs.mit.edu/http://graphics.lcs.mit.edu/
classes/6.837/F98/Lecture21/classes/6.837/F98/Lecture21/Slide14.htmlSlide14.html
0
0
1
1
0
0
010
z
x
z
xs
z
xtP
PPsPtP
0
0
1
1
0
0
010
z
x
z
xt
z
xtP
VVtVtP
)(
)(
)(
)(
)(
010
010
101
0
010
010
0
0
1
1
0
0
vvsvv
uusuu
zztz
tzs
zzsz
xxsx
z
x
z
xt
z
x
Other solutionsOther solutions
Cost of screen space interpolation Cost of screen space interpolation now?now?
Increase # of trianglesIncrease # of triangles
)(
)(
)(
)(
)(
010
010
101
0
010
010
0
0
1
1
0
0
vvsvv
uusuu
zztz
tzs
zzsz
xxsx
z
x
z
xt
z
x
Linear Interpolation is Linear Interpolation is wrong?wrong?
Gouraud is wrong, but why does it Gouraud is wrong, but why does it look okay?look okay?
Q: Why does Texture mapping not Q: Why does Texture mapping not look right even though we are doing look right even though we are doing the same thing?the same thing?
A: All about the slope of the A: All about the slope of the interpolation and the “gradualness” interpolation and the “gradualness” or “abruptness” of the changeor “abruptness” of the change
TransparenciesTransparencies
We will revisit this later, but we We will revisit this later, but we can use the alpha channel to can use the alpha channel to stencil out textures.stencil out textures.
Thus Thus per pixelper pixel, set alpha = 1 or , set alpha = 1 or alpha = 0. Where alpha = 0, alpha = 0. Where alpha = 0,
Let’s Look at some gamesLet’s Look at some games Pick a favorite game from the classPick a favorite game from the class
top related