0% found this document useful (0 votes)
9 views

11+ +mapping

Uploaded by

Benoni Tang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

11+ +mapping

Uploaded by

Benoni Tang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Mapping Techniques

Christoph Garth
Scientific Visualization Lab
Motivation
Up until now all objects we considered and modeled were more or less smooth and had
few surface details - in contrast to real world surfaces.

Computer Graphics – Mapping Techniques– Motivation 1–1


An explicit representation of surface details is computational as well as in modeling too
expensive.

In the beginning, only texture mapping was used to display surface details. By using
shader-based rendering, nearly arbitrary techniques can be employed.

General goals: modeling and rendering surface details

• without costly computation of geometry


• without costly representation
• without costly rendering

“All it takes is for the rendered image to look right.”


– Jim Blinn (SIGGRAPH’84)

Computer Graphics – Mapping Techniques– Motivation 1–2


Texture Mapping
A texture map is a discrete, multidimensional mapping that describes material properties
such as e.g. color.

Example: 2D image as texture map


Tu = 64
Tu × Tv samples (texels = texture elements) are given
on a discrete grid of coordinates in texture
coordinates (texture domain).

Tv = 64
In general, texels are sampled over the interval [0, 1] in
texture coordinates. Thus, the query is independent of
texture resolution.
Multiplication with the width/height yields the v
coordinates of the pixel in the texture grid.
u

Computer Graphics – Mapping Techniques– Texture Mapping 1–3


The texture values / colors are used in the rendering, in order to modify the appearance
of objects.

General Idea: During shading of a pixel, surface properties (color, but also other
properties) are read from the texture and used in calculating fragment color

Computer Graphics – Mapping Techniques– Texture Mapping 1–4


In order to map a two-dimensional image (texture) onto the boundary of a
three-dimensional object, the mapping has to be explicitly specified.

The texture itself is a map from the unit square into colors:

T(u, v) : [0, 1]2 → R3

The mapping of surface points into the texture domain (texture space) is specified by
assigning each point on the surface (u, v) coordinates in [0, 1]2 .

So in a sense, we obtain a mapping of the form

(x, y, z) → (u, v) → (R, G, B)

as the texture map.

Computer Graphics – Mapping Techniques– Texture Mapping 1–5


Example: texture map

A (u, v)-tuple is assigned to each surface point of the table, and from this, the color can
be read from the texture at the (u, v) position.

Computer Graphics – Mapping Techniques– Texture Mapping 1–6


Standard mappings: sphere, cylinder, plane, cube

Computer Graphics – Mapping Techniques– Texture Mapping 1–7


Example: parametric sphere (centered at origin)
(φ : [0, 2π] azimuth, θ : [0, π] elevation)
θ
x = cos(φ) sin(θ)
y = sin(φ) sin(θ)
z = cos(θ)

Texture coordinates from 3D coordinates: φ

z
θ = cos−1
r
(
x
cos−1

r y≥0
φ = atan2(x, y) =
−1 x

− cos r y<0

⇒ u = θ/π, v = φ/(2π)

Computer Graphics – Mapping Techniques– Texture Mapping 1–8


Example: cylinder coordinates (φ, h)

Computer Graphics – Mapping Techniques– Texture Mapping 1–9


Typically: Explicit specification of the mapping as per-vertex texture coordinates as an
additional vertex attribute.
float float float float float float float float float

attribute position V0,x V0,y V0,z V1,x V1,y V1,z V2,x V2,y V2,z

attribute normal N0,x N0,y N0,z N1,x N1,y N1,z N2,x N2,y N2,z

attribute texture coordinate T0,u T0,v T1,u T1,v T2,u T2,v

index buffer
0 1 2

uint uint uint

Computer Graphics – Mapping Techniques– Texture Mapping 1–10


Illustration: What is the color at p?
p2
v

(u1 , v1 ) p1

(u2 , v2 )

(u0 , v0 )
p0
u

If p = β0 p0 + β1 p1 + β2 p2 , then the color of p is


C(p) = T(β0 u0 + β1 u1 + β2 u2 , β0 v0 + β1 v1 + β2 v2 ).

Computer Graphics – Mapping Techniques– Texture Mapping 1–11


The data (e.g. colors) stored in a texture must to be evaluated at arbitrary texture
coordinates (u, v). This normally is done via interpolation, in one of two modes:

• nearest neighbor
• bilinear

texel
v

u
sample point (u, v)

Computer Graphics – Mapping Techniques– Texture Mapping 1–12


Nearest-neighbor interpolation:
interpolated value → value at the nearest point (texel)

interpolation region in yellow,


=
value constant over the whole region

= texels used for interpolation


= texel midpoint
= interpolation point

The interpolated texture is piece-wise constant.

Computer Graphics – Mapping Techniques– Texture Mapping 1–13


Bilinear interpolation on a rectangle:

f (x, y) = (1 − β) fj + β fj+1
= (1 − β) ((1 − α) fi,j + α fi+1,j ) + β ((1 − α) fi,j+1 + α fi+1,j+1 )

with local coordinates fi,j+1 fj+1 fi+1,j+1

x − xi
α= ∈ [0, 1]

1−β
xi+1 − xi

y − yi
β= ∈ [0, 1]
yi+1 − yi

β
α 1−α
fi,j fj fi+1,j

Computer Graphics – Mapping Techniques– Texture Mapping 1–14


Bilinear interpolation is applied over the rectangle formed by a 2 × 2 set of texels.

= interpolation region in yellow


= texels used for interpolation
= texel
= interpolation point

The interpolated texture is piece-wise bilinear.

Computer Graphics – Mapping Techniques– Texture Mapping 1–15


Texture atlas:
different components / pieces of one or more objects are stored inside a texture.

This enables mapping textures onto objects without large distortion


(→ piecewise parametrization, unwrapping).

Example: alternative mapping for spheres from two hemispheres.

Computer Graphics – Mapping Techniques– Texture Mapping 1–16


Example: texture atlas

atlas with texture parts for model with textures


different objects parts, stored in one texture

Computer Graphics – Mapping Techniques– Texture Mapping 1–17


Example: very simple texture mapping fragment shader (GLSL)

// texture "variable"
uniform sampler2D imageTex;
// texture coordinate varying, interpolated automatically
in vec2 uv;
// output color
out vec4 fragColor;

void main()
{
fragColor = texture(imageTex, uv);
}

The per-vertex texture coordinate uv is emitted by the vertex shader and automatically
interpolated across the primitives. The texture function automatically interpolates the
texture in a mode set by the application.

Computer Graphics – Mapping Techniques– Texture Mapping 1–18


Bump Mapping
Which other properties of surfaces can be modeled through textures?

Observe:

B B B B D B B D

a flat, smooth surface on a curved surface, the


appears uniformly bright (B) away-facing parts appear
darkened (D)

Computer Graphics – Mapping Techniques– Bump Mapping 1–19


Bump mapping

• Goal: represent small surface height variations, make the surface look “more” 3D.
• Idea: do not change the geometry of the surface, but manipulate the normal vectors
during evaluation of the illumination model.
• Simulation of surface irregularities on actual even/“simple” surfaces is created only
by changing the normal vectors of the geometry

Computer Graphics – Mapping Techniques– Bump Mapping 1–20


Approach: The original (smooth) surface is visualized, but the normals are manipulated.

• Reminder: The Phong lighting model does not use any information about the
geometry aside from the normals

The actual surface geometry is left unchanged.


Computer Graphics – Mapping Techniques– Bump Mapping 1–21
Basic techniques for surface normal variation:
• Bump mapping (height mapping)
• Height texture as gray-scale image
• Similar to a relief map
• Higher points are assigned a brighter color,
lower points receive a darker color.
color texture + height map
• Normal deformation is computed on-the-fly
(in fragment shader).
• Normal mapping
• Surface normals (in local coordinates) are
directly read from a texture.
• Typically stored as colors
1 1
C = N + ∈ [0, 1]3
2 2 color texture + normal map

Computer Graphics – Mapping Techniques– Bump Mapping 1–22


Examples: regular structures (e. g. golf balls) as well as irregular structures (e. g. bark) can
be simulated.

The surface deformation is generally assumed to be very small relative to the object size.

Computer Graphics – Mapping Techniques– Bump Mapping 1–23


Displacement Mapping
Disadvantage of bump mapping: the silhouette of an object does not change, which can
be noticed if one looks closely

Displacement mapping:

• A height field is mapped onto a surface which displaces points into the direction of
the surface normal at that point (e. g. in the vertex shader)
• Silhouette looks correct but the amount of polygons has to be high in order to
appropriately approximate the details.

Computer Graphics – Mapping Techniques– Displacement Mapping 1–24


Illustration: bump & displacement mapping

Computer Graphics – Mapping Techniques– Displacement Mapping 1–25


Comparison:
bump mapping vs.
displacement mapping

Computer Graphics – Mapping Techniques– Displacement Mapping 1–26


Note: Modern GPUs allow on-the-fly tesselation of geometries (→ tesselation shader);
this is ideal for displacement mapping.

base mesh tesselated mesh displaced mesh final result


sent to GPU computed on GPU computed on GPU

Only the base mesh and displacement texture are stored and sent to the GPU; mesh
subdivision (tesselation) and displacement are computed on-the-fly, during rendering.

Computer Graphics – Mapping Techniques– Displacement Mapping 1–27


3D Texture mapping
3D/Solid textures

Instead of a 2D image, a texture is used that is defined at each point in 3D.

Via procedural approaches and appropriate mathematical functions, several realistic


patterns can be created.

Computer Graphics – Mapping Techniques– 3D Texture mapping 1–28


Discrete solid textures:

• Three-dimensional array / image of colors.


• Local coordinates at the surface index the texture:

(r, g, b) = Ctex (s, t, r)

• Boundary description “carves” the object out of the texture volume

Procedural textures:

• Compute color from mathematical functions or fractal algorithms


• Advantages: low memory cost, high precision, defined over the whole domain.
• Disadvantages: functions are not intuitive and hard to create, computational
overhead can be prohibitive.

Computer Graphics – Mapping Techniques– 3D Texture mapping 1–29


Example: procedural wood texture

procedural 3D texture 3D texture mapping

Computer Graphics – Mapping Techniques– 3D Texture mapping 1–30


Environment Mapping
To render scenes with reflecting objects realistically, a sufficient approximation of surface
reflections is needed.

With ray tracing this is easy to achieve, how about rasterization pipelines?

Environment mapping:
Rendering of reflections with the help of textures

Idea: render environment of a reflecting object onto one or more textures, from which the
reflecting surface appearance can be rendererd

Computer Graphics – Mapping Techniques– Environment Mapping 1–31


Historically the oldest method: sphere mapping

Computer Graphics – Mapping Techniques– Environment Mapping 1–32


Sphere mapping

• Mapping of the environment of an object onto a single texture


• Derive texture coordinates from reflection ray direction on the fly to determine the
reflected light (in fragment shader, complex)
• Dependent on the position of the viewer

Assumption: viewer is far away, sphere is very small


Computer Graphics – Mapping Techniques– Environment Mapping 1–33
Example: Sphere Mapping

Computer Graphics – Mapping Techniques– Environment Mapping 1–34


Example: Sphere Mapping

Computer Graphics – Mapping Techniques– Environment Mapping 1–35


Note: The sphere map is only valid for one viewpoint; dynamic re-computation of the
sphere map must be done whenever position / view point changes.

Improvements:

• Cube mapping
• Dual-paraboloid mapping (complete environment stored in two textures)

The reflection directions are those of two paraboloids, which induces less distortion
than (hemi-)spheres.
Computer Graphics – Mapping Techniques– Environment Mapping 1–36
Cube maps
• From the center of a
(virtual) cube, six images
are computed, one for the
view through each face
• Cube map textures are
directly supported by
OpenGL
• Higher costs:
6 textures are needed

Computer Graphics – Mapping Techniques– Environment Mapping 1–37


Environment cube mapping
• Reflecting object is “placed” inside
the cube
• Mapping of the scene from the
objects viewpoint
• Center of projection coincides
with the cubes center
• Faces of the cube are projection
planes
• For the computation of the
“reflection” (meaning texture
coordinates) the respective
reflection vector is used

Computer Graphics – Mapping Techniques– Environment Mapping 1–38


Environment cube mapping

• Games: Environment (dynamic . . . ) should reflect in real time


• Therefore: dynamic cube mapping
• All faces of the cube have to render in their respective textures each frame.
(The reflecting object is not drawn itself.)
• Rendering of the textures has a high cost and can thus only be used scarcely.

Computer Graphics – Mapping Techniques– Environment Mapping 1–39


Illustration: environment map

Computer Graphics – Mapping Techniques– Environment Mapping 1–40


Example: dynamic cube environment mapping.

Note: Environment mapping can only reproduce paths of the form LDSE; multiple
reflections are not possible.
Computer Graphics – Mapping Techniques– Environment Mapping 1–41
Recap
Mapping techniques provide flexibility in modeling detailed surface appearance and form
the basis for practically all commercially used computer graphic techniques (games, FX).

Different types of mapping techniques can be combined and used on the same object:
texture mapping, bump mapping, displacement mapping, environment mapping, . . .

Care must be taken when determining the mapping from object coordinates to texture
space (assigning texture coordinates).

(All mapping techniques are prone to aliasing.)

Next: Anti-aliasing (samplign & filtering)

Computer Graphics – Mapping Techniques– Recap 1–42

You might also like