Upload
dorthy-kennedy
View
240
Download
0
Tags:
Embed Size (px)
Citation preview
Computer Graphics Inf4/MSc
Computer Graphics
Lecture 11
Texture Mapping
Computer Graphics Inf4/MSc
The Problem:
• We don't want to represent all this detail with geometry
3
Computer Graphics Inf4/MSc
Today
• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,
• Common texture coordinates mapping
• Bump mapping
• Environment mapping
4
Computer Graphics Inf4/MSc
Texture mapping.
• Method of improving surface appearance by adding details on surface.
5
Computer Graphics Inf4/MSc
Texture mapping.
• Image is ‘pasted’ onto a polygon.• Image is called a Texture map, it’s pixels are often
referred as a Texels and have coordinates (u,v)• Texture coordinates are defined for each vertex of
the polygon and interpolated across the polygon.
v
u
v
u
y
x
Computer Graphics Inf4/MSc
Photo-textures
7
Computer Graphics Inf4/MSc Finding the texture coords of
arbitrary pixels inside the triangle
y
• Use the barycentric coordinates explained in Lecture 9
Computer Graphics Inf4/MSc
Texture Interpolation• Specify a texture coordinate (u,v) at each vertex• Can we just linearly interpolate the values in screen
space?
(0,0) (1,0)
(0,1)
Computer Graphics Inf4/MSc Interpolation - What Goes
Wrong?
texture source what we get| what we want
• Linear interpolation in screen space:
Computer Graphics Inf4/MSc
Why does it happen?
• Uniform steps on the image plane does not correspond to uniform steps along the edge
Computer Graphics Inf4/MSc
• Use a rectangular mesh instead of a triangular mesh or
• Increase the number of polygons
How do we deal with it?
12
Computer Graphics Inf4/MSc
Today
• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,
• Common texture coordinates mapping
• Bump mapping
• Environment mapping
13
Computer Graphics Inf4/MSc
Aliasing
• Happens when – The camera is zoomed too much into the textured
surface (magnification)– Several texels covering a pixel’s cell (minification)
14
Computer Graphics Inf4/MSc
Texture Magnification
• Zooming into a surface with a texture• Methods to determine the color of each pixel
– Nearest neighbour – Bilinear interpolation
15
Computer Graphics Inf4/MSc
Texture Minification • Multiple textures in a single pixel• Solution:
– Nearest neighbour (using the color at the center of the pixel)– Bilinear blending – Mipmapping
Computer Graphics Inf4/MSc
Nyquist Limit
• The texture frequency (ft) should be no greater than half the sample frequency (fs)
• ft <= 0.5 fs• Say it is a 2x2 texture :
– Wavelength 2 texels wide– Frequency ft = 1 / 2 – 1 / 2 x 2 <= fs , i.e., – To properly display this texture on a screen, the
frequency must then be at least 2x 1/2, i.e., at least one pixel per texel
17
Computer Graphics Inf4/MSc
MIP mapMultum In Parvo = Many things in a small place
Produce a texture of multiple resolutionsUse the resolution according to the number of texels in one pixel
18
Computer Graphics Inf4/MSc
Today
• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,
• Common texture coordinates mapping
• Bump mapping
• Environment mapping
Computer Graphics Inf4/MSc Common Texture Coordinate
Mappings
• Orthogonal• Cylindrical• Spherical • Perspective
Projection• Texture
Chart
Computer Graphics Inf4/MSc
Demo movie
Computer Graphics Inf4/MSc
Texture Mapping & Illumination
• Texture mapping can be used to alter some or all of the constants in the illumination equation: – pixel color, diffuse color, alter the normal, ….
Phong’s Illumination Model
Constant Diffuse Color Diffuse Texture Color Texture used as Label Texture used as Diffuse Color
22
Computer Graphics Inf4/MSc
Today
• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,
• Common texture coordinates mapping
• Bump mapping
• Environment mapping
Computer Graphics Inf4/MSc
What's Missing?• What's the difference between a real
brick wall and a photograph of the wall texture-mapped onto a plane?
• What happens if we change the lighting or the camera position?
Computer Graphics Inf4/MSc
Bump Mapping• Use textures to alter the surface normal
– Does not change the actual shape of the surface– Just shaded as if it were a different shape
Sphere w/Diffuse Texture Swirly Bump Map Sphere w/Diffuse Texture & Bump Map
Computer Graphics Inf4/MSc
Bump Mapping
• Treat the texture as a single-valued height function• Compute the normal from the partial derivatives in
the texture
Computer Graphics Inf4/MSc
Another Bump Map Example
Cylinder w/Diffuse Texture Map
Bump Map
Cylinder w/Texture Map & Bump Map
Computer Graphics Inf4/MSc
What's Missing?
• There are no bumps on the silhouette of a bump-mapped object
Computer Graphics Inf4/MSc
Displacement Mapping
• Use the texture map to actually move the surface point
• The geometry must be displaced before visibility is determined
29
Computer Graphics Inf4/MSc
Today
• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,
• Common texture coordinates mapping
• Bump mapping
• Environment mapping
Computer Graphics Inf4/MSc
Environment Maps
• We can simulate reflections by using the direction of the reflected ray to index a spherical texture map at "infinity".
• Assumes that all reflected rays begin from the same point.
Computer Graphics Inf4/MSc
Example
Computer Graphics Inf4/MSc
Environment Mapping Example
Terminator II
Computer Graphics Inf4/MSc Cubic Mapping
• The map resides on the surfaces of a cube around the object– align the faces of the cube with the
coordinate axes
• To generate the map:• Using methods such as ray tracing
– Or, take 6 photos of a real environment with a camera in the object’s position : much easier
Computer Graphics Inf4/MSc
Calculating the reflection vector
• Normal vector of the surface : N• Incident Ray : I• Reflection Ray: R
R = I -2 N ( N . I )
• The texture coordinate is based on the reflection vector
• Assuming the origin of the vector is always in the center of the cube environment map
Computer Graphics Inf4/MSc
Indexing Cubic Maps• Assume you have R and the cube’s faces
are aligned with the coordinate axes, and have texture coordinates in [0,1]x[0,1]– How do you decide which face to use?
• The reflection vector coordinate with the largest magnitude
• (0.8, 0.3, 0.2) face in +x direction
– How do you decide which texture coordinates to use?
• Divide by the coordinate with the largest magnitude
• Remapped to a value between 0 and 1.
(0.8,0.3,0.2) ((0.3/0.8 +1)*0.5, ((0.2/0.8 +1)*0.5) = (0.6875, 0.625)
Computer Graphics Inf4/MSc
A Sphere Map
Computer Graphics Inf4/MSc
Sphere Mapping• To generate the map:
– Take a photograph of a shiny sphere – For synthetic scenes, you can use ray tracing, or
warping a cubic environment map
Computer Graphics Inf4/MSc
Indexing Sphere Maps• Given the reflection vector R
• (s,t) on the spherical map
• Problems:– Highly non-uniform sampling
– Highly non-linear mapping
21
222 12
2
1 ,
2
1
zyx
yx
RRRm
m
Rt
m
Rs
Computer Graphics Inf4/MSc
Non-linear Mapping
• Linear interpolation of texture coordinates picks up the wrong texture pixels– Use small polygons!
Correct Linear
Computer Graphics Inf4/MSc
Example
Computer Graphics Inf4/MSc
Refractive Environment Mapping
• When simulating effects mapping the refracted environment onto translucent materials such as ice or glass, we must use Refractive Environment Mapping
Computer Graphics Inf4/MSc
Snell’s Law
• When light passes through a boundary between two materials of different density (air and water, for example), the light’s direction changes.
• The direction follows Snell’s Law
• We can do environment mapping using the refracted vector T
43
Computer Graphics Inf4/MSc
Summary
• Texture mapping – Texture interpolation– Antialiasing : bilinear interpoation, Mipmaps,
• Common texture coordinates mapping
• Bump mapping
• Environment mapping
44
Computer Graphics Inf4/MSc Assignment
• Rendering a head / teapot
• You may use the 3D rendering function of OpenGL, but better marks are given if you do the illumination by yourself
• Extra marks given for – Textures,
– Environment mapping,
– Shadows, mirrors (extra objects)
– Global illumination (ray tracing, etc)
– Make sure the program runs on DICE