computer graphics inf4/msc computer graphics lecture 9 antialiasing, texture mapping
TRANSCRIPT
Computer Graphics Inf4/MSc
2
Today
• Texture mapping– Common texture coordinates mapping– Texture coordinates
• Antialiasing
• Antialiasing-textures
Computer Graphics Inf4/MSc
Texture Mapping : Why needed?
• We don't want to represent all this detail with colour / geometry
Computer Graphics Inf4/MSc
4
Texture mapping.
• Method of improving surface appearance by adding details on surface.
• Done at the rasterization stage
Computer Graphics Inf4/MSc
Interpolating the uv coordinates
Again, we use baricentric Coordinates
u= α u1 + β u2 + γ u3
v = α v1 + β v2 + γ v3
Or scan conversion
u3 v3
u2 v2
u1 v1
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
How do we deal with it?• Use hyperbolic interpolation
– (u,v) cannot be linearly interpolated, but 1/w and (u/w, v/w) can
– w is the last component after the canonical view transformation
– A w is computed for every 3D point
10100
200
02
0
002
z
y
x
nf
fn
nf
nfbt
bt
bt
nlr
lr
lr
n
w
wz
wy
wx
p
p
p
Computer Graphics Inf4/MScTexture Mapping Examples
• Linear interpolation vs. Hyperbolic interpolation• Two triangles per square
Computer Graphics Inf4/MScTexture Mapping & Illumination
Texture mapping can be used to alter some or all of the constants in the illumination equation:
– pixel color, diffuse color
Computer Graphics Inf4/MSc
15
Today
• Texture mapping• Common texture coordinates mapping• Texture coordinates
• Antialiasing
• Antialiasing textures
Computer Graphics Inf4/MSc
16
Anti-aliasing • Aliasing: distortion artifacts produced when representing a
high-resolution signal at a lower resolution.• Anti-aliasing : techniques to remove aliasing
Aliased polygons(jagged edges)
Anti-aliased polygons
Computer Graphics Inf4/MSc
Nyquist Limit
• The signal frequency (fsignal) should be no greater than half the sample frequency (fsample)
• fsignal < 0.5 fsample • In the top, fsignal = 0.8 fsample -> cannot reconstruct the original signal• In the bottom fsignal =0.5 fsample -> the original signal can be reconstructed
by slightly increasing the sampling rate
Computer Graphics Inf4/MSc
18
Each pixel is subdivided (sub-sampled) into n regions, and each sub-pixel has a color;Compute the average color value
Screen-based Anti-aliasing
weight:
color sample:),,(
y)(x,at color pixel:),(
),,(),(1
i
n
ii
w
yxi
yx
yxiwyx
c
p
cp
Computer Graphics Inf4/MSc
Accumulation Buffer (A-Buffer)• Use a buffer that has the same resolution as
the original image• To obtain a 2x2 sampling of a scene, 4
images are made by shifting the buffer horizontally/vertically for half a pixel
• The results are accumulated and the final results are obtained by averaging
• Various sampling schemes are available
Pixel center
Subsampled point
Computer Graphics Inf4/MSc
Accumulation Buffer (A-Buffer)• The lighting computation is usually done
only once per vertex• Not doing the lighting computation at each
sample point• The A-buffer’s focus is on the edge anti-
aliasing • Also useful for rendering transparent
objects, motion blur (will be covered later in the course)
Edges
Computer Graphics Inf4/MSc Stochastic Sampling• A scene can be produced of objects that are
arbitrarily small• A regular pattern of sampling will always
exhibit some sort of aliasing• By irregular sampling, the higher frequencies
appear in the image as noise rather than aliases• Humans are more sensitive to aliases than noise
Computer Graphics Inf4/MSc
Stochastic SamplingOne approach to solve this is to randomly sample over the pixelsJittering : subdivide into n regions of equal size and randomly sample inside each regionCompute the colour at the sample and averageCan precompute a table and recycle it or simply jitter on the fly
Computer Graphics Inf4/MSc
26
Today
• Texture mapping• Common texture coordinates mapping• Texture coordinates
• Antialiasing
• Antialiasing textures
Computer Graphics Inf4/MSc
27
Aliasing of texturesHappens when the camera is zoomed too much into the textured surface (magnification)Several texels (pixels of the texture) covering a pixel’s cell (minification)
Computer Graphics Inf4/MSc
28
Texture Magnification • Zooming too much into a surface with a texture • One texel covering many pixels
Computer Graphics Inf4/MSc
29
Bilinear Interpolation
• Mapping the pixel centre to the uv coordinates• Computing the pixel colour by interpolating
the surrounding texel values
Computer Graphics Inf4/MSc
Bilinear Interpolation - 2• For (pu, pv), compute its (u,v) coordinates
by barycentric coordinates• u = pu – (int)pu, v = pv - (int)pv • xl = pu, xr = pu +1, yb = pv, yt = pv +1,
– (pu, pv) : the pixel centre mapped into the texture space
– b(pu,pv) : the colour at point pu, pv
– t(x,y) : the texel colour at (x,y)
– u = pu – (int)pu, v = pv - (int)pv
Computer Graphics Inf4/MSc
Texture MinificationWhich texture will cause more aliasing when mapped onto the
floor?
Computer Graphics Inf4/MSc
32
Texture Minification• Many texels covering a pixel’s cell• Results in aliasing (remember Nyquist limit)• The artifacts are even more noticeable when the
surface moves • Solution
• Mipmapping
Computer Graphics Inf4/MSc
33
MIP mapMultum In Parvo = Many things in a small place
Produce a texture of multiple resolutionsSwitch the resolution according to the number of texels in one pixel Select a level that the ratio of the texture and the pixel is 1:1
Computer Graphics Inf4/MSc
34
Selecting the resolution in Mipmap
Map the pixel corners to the texture space Find the resolution that roughly covers the mapped quadrilateral
Apply a bilinear interpolation in that resolution, Or find the two surrounding resolutions and apply a trilinear
interpolation (also along the resolution axis)
Computer Graphics Inf4/MSc
35
Texture Minification • Multiple textures in a single pixel• Solution:
• Nearest neighbour Bilinear blending Mipmapping
Computer Graphics Inf4/MSc
Readings
• Chapter 5.1-2 of Real-Time Rendering Second edition – http://books.google.co.uk/books?id=mOKEfBT
w4x0C&printsec=frontcover&source=gbs_v2_summary_r&cad=0#v=onepage&q=&f=false
• “Hyperbolic Interpolation” IEEE Computer Graphics and Applications, vol12, no.4, 89-94, 1992