texture mapping - uppsala university · interactive graphical systems texture mapping interactive...
TRANSCRIPT
Interactive Graphical Systems
Texture Mapping
Interactive Graphical Systems HT2005
Lars [email protected]
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #2Uppsala universitet
This lectureMy researchTexture Mapping• Overview• Image sampling• Applying textures• Advanced texture mapping techniques
Summary
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #3Uppsala universitet
My researchCo-located Visualization• Multiple view dependent perspectives on one
physically co-located computer generated scene.• Ways to accomplish co-located visualization
Augmented RealityVolumetric DisplaysMultiple viewer displays
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #4Uppsala universitet
Texture mapping in my researchTextures based on geospatial data
3D texture mapping
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #5Uppsala universitet
Benefits of using texturesto render 3D scenes (photo) realistic
to provide detail without generating numerous geometric objects
to allow for faster rendering of complex 3D scenes
to accomplish special visual effects(e.g. animations, fog, plasma...) (lecture 4)
to fake lighting and shadow effects (lecture 4)
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #6Uppsala universitet
What to use textures for?Transparency handling• alpha masking• alpha blending
Camera back drop (= scene background texture)Shadow mappingVideo- and picture animationsRendering applications in texture buffer.
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #7Uppsala universitet
Usage of texturesTransparency handling• Alpha blending
• VRT_SetTextureModulationMode( int texture_modulation )
VRT_TEXTURE_MODULATION_DECAL – replaces color of geometryVRT_TEXTURE_MODULATION_MODULATE - multiples color of geometry
• Alpha masking
• In VRT - use DECAL mode set texture alpha value to zero for alpha masking
Texture map Texture mask
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #8Uppsala universitet
Usage of Textures (cont.)Camera Backdrop
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #9Uppsala universitet
Usage of Textures (cont.)Camera Backdrop
Birds eye view on scene Camera view on scene
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #10Uppsala universitet
Usage of Textures (cont.)Shadow mapping (see lecture 4)• Render the scene from the lights point of view and
save the depth values to a textureThe result is a depth map or “shadow map”Every pixel in the map indicates its distance from the light source
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #11Uppsala universitet
Usage of Textures (cont.)Video- and picture animations• Picture animations (see lecture 4)
• Example of video animation in textures is the backdrop
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #12Uppsala universitet
Usage of Textures (cont.)Rendering applications in texture buffer.• Project Looking Glass, Mac OS X, Microsoft Vista
http://wwws.sun.com/software/looking_glass/details.html
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #13Uppsala universitet
What is a texture map?digital image matrix (u,v)(most commonly 2D)
single matrix elements = texels (texture elements) (contains most commonly color information)
spatial resolution sampling
amplitude resolution = texel depth ⇒ quantization
v
u
Texel t (u,v)
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #14Uppsala universitet
Spatial Sampling
600 x 460 300 x 230
150 x 115 75 x 58 38 x 29
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #15Uppsala universitet
Pixel (Texel) quantization
256 gray levels 64 gray levels
16 gray levels 4 gray levels 2 gray levels
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #16Uppsala universitet
Example of Color (Texel) formats8 bit per texel gray scale8 bit per texel color palette16 bit per texel gray scale24 bit per texel RGB32 bit per texel RGBA (used in VRT)
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #17Uppsala universitet
The scene rendering processModeling
World Coordinate System
Geometric ProcessingModel Transformations
Lighting CalculationProjection -> 2D
RasterizationScreen Coordinate System
Drawing Pixels/TexelsDepth Test
Alpha Blending
Display
Frame Buffer
X
Z
YCoordinatesColors, TransparencyTextures
Surface Normal VectorsSpecularity
Lights
Viewing Position
Objects
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #18Uppsala universitet
Applying a texture?For each point in an object we must decide what texel in the texture to use.A common way to describe an object is by a number of polygons. Then we must decide for each point in each polygon what texel to use.
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #19Uppsala universitet
Texturing
p0
p2
p1w
)T(),( w=vu
ux
y
a
b
c
s
What texel value should be used for the pixel at position w at scanline s?
Need to find a mapping.In this case the texture coordinates for p0, p1, p2 is a, b, c.
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #20Uppsala universitet
Texturing
l.right texe theuplook toused becan and texturein the axis base toscorrespond B andA that notingBy
.
: and for sexpression following in the resultsit solving
:upset becan system following The]1,0[,
. and ofn combinatiolinear a as expressed becan then 12
13
βα
α
βαβα
βαβα
xyyx
xyyx
yyx
yxxy
yy
xx
y
x
BABAwAwA, β
BABAwBwB
BABA
ww
x −−
=−−
=
⎥⎦
⎤⎢⎣
⎡⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡
∈+=
−=−=
BAwBAw
ppBppA
p1
p2
p3w
x
y
B
A
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #21Uppsala universitet
Texturing example
triangle. theinside 1718
point for the use to texel theCompute .128
0,
0128
,00
scoordinate texture
ingcorrespond and 2530
,2010
,55
p verticesby the defined trianglea and 128x128 size of textureaGiven 321
⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡⎥⎦
⎤⎢⎣
⎡⎥⎦
⎤⎢⎣
⎡
⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡=
global
pp
w
63128*275135128*
19128*27540128*
at texelupLook
.275135
25*1520*513*1512*5
.27540
25*1520*512*2513*20
.1213
55
1718p
:by spanned space theto Translate2025
55
2530
,155
55
2010
:Solution
1-global
global
1312
≈==
≈==
−−
=−−
=−−
=
−−
=−−
=−−
=
⎥⎦⎤
⎢⎣⎡=⎥⎦
⎤⎢⎣⎡−⎥⎦
⎤⎢⎣⎡=
⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡−⎥
⎦
⎤⎢⎣
⎡=−=⎥
⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡−⎥
⎦
⎤⎢⎣
⎡=−=
=
β
α
β
α
v
u
BABAwAwABABAwBwB
pppp
xyyx
xyyx
xyyx
yxxy
ww
ABw
BA
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #22Uppsala universitet
Addressing texels in a texture mapwidth, height of texture map usually 2n (e.g. 27 = 128)
⇒ texture size: 128 * 128
tu = 127 · 0.775 = 98.425 tv = 127 · 0.725 = 92.075t (u,v) = (98,92) rounded
address (tu,v) = tv · width · bpt + tu · bpt
= (tv · width + tu) · bpt
ex.: (92 · 128 + 98) · 1 = 11874· 3 = 35622
3562335624
u
v
127
1270
(98,92)
if width 2n ·2n <=> shl n
bpt = bytes per texel
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #23Uppsala universitet
Example: Draw on texture
u,v is continuously known from collision detection in the rendered scene.
For each t(u,v) change its RGBA component in memory to black
u,v
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #24Uppsala universitet
The “Texel Footprint”The area in screen pixels covered by a texture element
Texel>Pixel Texel=Pixel Texel<Pixel
It is very uncommon that one texture elements covers exactly one pixel, due to different scale and rotational alignment.
-> How should the color of a pixel then be calculated ?
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #25Uppsala universitet
Practical problems: Texture map is bigger than the rendered polygon
⇒ sub-sampling
Texture map is smaller than the rendered polygon ⇒ super-sampling
texture polygon
texture polygon
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #26Uppsala universitet
Texel neighborhood
2 - point neighborhood
4 - point neighborhood
6 - point neighborhood
8 - point neighborhood
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #27Uppsala universitet
Sub-sampling1. point sampling / nearest-neighbor
⇒ might result in irregular rendered texture due to rounding errors
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #28Uppsala universitet
Sub-sampling (cont.)2. averaging in a defined neighborhood
⇒ improves visual result but does not necessarily eliminate the problem
f x yt u v
n
n n
n
( , )( , )
=∑
1
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #29Uppsala universitet
Super-sampling1. point sampling / multiple nearest-neighbor
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #30Uppsala universitet
Super-sampling2. Bilinear interpolation
includes weighted neighborhood
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #31Uppsala universitet
Mip maps
Problem: Artifacts due to image sub-sampling
Solution: Pre-processing of the texture map with local filters (e.g. smoothing)
original resolution
filtered
filtered
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #32Uppsala universitet
Texture acquisition
• Scanning of photographs or drawings
• Digital drawings
• Digital camera images
• Rendered images
• Procedural Images
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #33Uppsala universitet
ExampleThe source code below creates a fireplace model composed of 3 polygons based on 8 vertices.
geom = VRT_GeometryNew ();VRT_GeometryAddVertex (geom, 0.0,0.0,0.0, 0.0,0.0,0.0, ?, ?);VRT_GeometryAddVertex (geom, 1.0,0.0,0.0, 0.0,0.0,0.0, ?, ?);VRT_GeometryAddVertex (geom, 1.0,1.0,0.0, 0.0,0.0,0.0, ?, ?);VRT_GeometryAddVertex (geom, 0.0,1.0,0.0, 0.0,0.0,0.0, ?, ?);VRT_GeometryAddVertex (geom, 1.0,0.0,-0.25, 0.0,0.0,0.0, ?, ?);VRT_GeometryAddVertex (geom, 1.0,1.0,-0.25, 0.0,0.0,0.0, ?, ?);VRT_GeometryAddVertex (geom, 1.0,1.0,-0.25, 0.0,0.0,0.0, ?, ?);VRT_GeometryAddVertex (geom, 0.0,1.0,-0.25, 0.0,0.0,0.0, ?, ?);
texture = LoadTexture (“c:\\vrlab\\fireplace.bmp”);poly =VRT_GeometryNewQuad (geom, 3, 2, 1, 0);VRT_PolygonSetTexture (poly, texture);poly =VRT_GeometryNewQuad (geom, 7, 6, 2, 3);VRT_PolygonSetTexture (poly, texture);poly =VRT_GeometryNewQuad (geom, 2, 5, 4, 1);VRT_PolygonSetTexture (poly, texture);
node = VRT_NodeNew (root, “a fireplace”);VRT_NodeSetGeometry (node, geom);
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #34Uppsala universitet
Example (cont.)You are given a texture map of size 256 x 256 texels (s. below). This texture is supposed to be mapped onto all three polygons. Give for all vertices vn (n =0..7) the normalized texture coordinates u and v such that the results of the mapping equals to the picture in the lower left corrner of the picture shown below!
X
Y
Z
0,0
255,255
170
170
Discrete Texture Map 256x256
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #35Uppsala universitet
Inverse mapping based on ray tracing
Highly complex 3D shape(10.000 polygons)
Photographic picture of the real 3D object
Question: How can we map the photographic picture upon the 3D shape?
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #36Uppsala universitet
Inverse mapping based on ray tracing
Simulate the photographic scenario:- Suppose a given camera angle- Align 2D picture and 3D shapesuch that 3D shape and picture “match”(rotation, translation, scale)
- Perform ray tracing from polygon verticestowards observers eye
- Calculate u/v coordinates in textured polygon- Assign hit coordinates (u/v) to polygon vertices
Result: - after the inverse mapping procedure 3D shape appears photographically correct for a limitedfield of view/rotations
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #37Uppsala universitet
View-dependent texture mapping
When many photographic texturesof the same object exist one canuse View-dependent texturemapping.
Every triangle has several texturesassociated with it. Before the texturing phase begins a texture is computed from the referencetextures.
This will give better results as some details may not be seen in all views
ab
Reference view 1
Rendered view
Polygon
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #38Uppsala universitet
Most modern graphic cards can in addition to 2D texture mapping alsohandle 3D textures.
The texels has an additonaldinmension ”t”. (u,v,t) .
Interactive Graphical Systems
Informationsteknologi | 2005-09-17 | #39Uppsala universitet
Bump mappingBump mapping is a techniquewhere the texel values don’tcorrespond to a colour butrather a normal. This normal indicates changes in the object surface.
The changes are taken intoaccount when the shadingcalculations are performed, pertubating the object surfacenormal, giving the illusion of a ’bumpy’ surface.
Note that this techniquedoesn’t alter the geometry of the object.