Technische Universität München
Fakultät für Informatik
Computer GraphicsSS 2014
Sampling
Rüdiger WestermannLehrstuhl für Computer Graphik und Visualisierung
Technische Universität München
Computer Graphics
2
Overview
• So far:– Image synthesis
• Ray tracing; models, transformations, shading & lighting, textures, acceleration
• Today– Aliasing and antialiasing techniques
• Prefiltering • Supersampling • Postfiltering• Stochastic and adaptive sampling
Technische Universität München
Computer Graphics
3
Sampling
• Mathematically, point sampling using regularly spaced sample points is the multiplication of the function with a comb function
0 xT 2T
Technische Universität München
Computer Graphics
4
Sampling
• Recall: image synthesis means point sampling of a continuous signal– Image contains samples of a continuous signal at a
discrete set of positions– Pixel spacing determines the frequencies (the size of
details) that can be reconstructed– Undersampling the image (taking too less samples to
allow for the reconstruction of the signal from the samples) causes aliasing artifacts (alias = ghost)
Technische Universität München
Computer Graphics
5
Aliasing
• Original scene and luminosity (brightness) distribution along a scan line
5
Technische Universität München
Computer Graphics
6
Aliasing
• Point sampling the scene at pixel centers
6
Technische Universität München
Computer Graphics
7
Aliasing
• The rendered image
7
Technische Universität München
Computer Graphics
8
Aliasing
• Jagged profiles
8
Technische Universität München
Computer Graphics
9
Aliasing
• Loss of details
9
Technische Universität München
Computer Graphics
10
Aliasing
• Note: the sampling frequency decreases with increasing distance to the viewpoint
d0 d1 d2 d3viewpoint
Technische Universität München
Computer Graphics
11
Aliasing
• With increasing distance to the viewer and slope of the surface, an ever larger surface area falls in-between adjacent rays
Technische Universität München
Computer Graphics
12
Aliasing
• Cause of aliasing– Sampling frequency is not high enough to cover all
details– It is below the Niquist limit
Shannons Sampling Theorem: The signal has to be sampled at a frequency that is equal to or higher than two times the highest frequency in the signal
Technische Universität München
Computer Graphics
13
Aliasing
• Aliasing artefacts– Spatial aliasing
– Temporal aliasing
Technische Universität München
Computer Graphics
14
Antialiasing
• How to avoid aliasing caused by an undersampling of the signal, i.e. the sampling frequency is not high enough to cover all details– Supersampling - increase sampling frequency– Prefiltering - decrease the highest frequency in the
signal, i.e. filter the signal before sampling– Postfiltering – filtering after sampling, but just blurres
the image
Technische Universität München
Computer Graphics
15
Antialiasing
• Supersampling - increase sampling frequency– Use more rays per pixel, i.e. virtually increase the
resolution of the pixel raster– e.g. use 4x4 rays per pixel and compute average of all
16 colors as final pixel color– Sharp edges are washed out– OK, but doesn´t eliminate aliasing because sharp edges
contain infinitely high frequencies
Technische Universität München
Computer Graphics
16
Antialiasing
• Supersampling– Regular supersampling
Technische Universität München
Computer Graphics
17
Antialiasing
• Filtering: average weighted samples
Technische Universität München
Computer Graphics
18
Antialiasing
• Filtering example
Technische Universität München
Computer Graphics
19
Antialiasing
• Filtering - jittered instead of regular sampling
Technische Universität München
Computer Graphics
20
Antialiasing
• Regular sampling– Visibility of aliases also caused by the regular sampling
grid– Human visual system is sensitive against regular
structures, but rather insensitive against high frequency noise
• Stochastic supersampling– Place samples randomly within pixel– Alias frequencies are converted to noise– But can result in clusters of sample
Technische Universität München
Computer Graphics
21
Antialiasing
• Poisson-disk sampling– Random generation of samples with
limit for the minimum distance between samples
• Jittered sampling– Random jittering from regular grid points
• Stratified random sampling– Regular partitioning of pixel region– One random sample per partition
Technische Universität München
Computer Graphics
22
Antialiasing
• Comparison– Regular, 1x1
Regular 3x3
Regular, 7x7
Jittered, 3x3
Jittered, 7x7
22
Technische Universität München
Computer Graphics
23
Antialiasing
• Example:
23
Technische Universität München
Computer Graphics
24
Antialiasing
• Example:
24
Technische Universität München
Computer Graphics
25
Antialiasing
• Example:
25
Technische Universität München
Computer Graphics
26
Antialiasing
• Example:
26
Technische Universität München
Computer Graphics
27
Antialiasing
• Prefiltering – Antialiasing before sampling (mainly used in texture
mapping)• Filtering (smoothing) a signal to remove details below the
frequency which is used to sample the signal
Technische Universität München
Computer Graphics
28
Antialiasing
• Prefiltering combines color contributions into a pixel
Technische Universität München
Computer Graphics
Antialiasing in texture mapping
• Many texels fall onto one pixels
29
Technische Universität München
Computer Graphics
Antialiasing in texture mapping
• Mip-Mapping:prefiltered levels of detail (LOD) in a pyramid
• At every level:average 2x2texels from thefiner levelinto one texel30
Technische Universität München
Computer Graphics
Antialiasing in texture mapping
31
Technische Universität München
Computer Graphics
Antialiasing in texture mapping
32
Technische Universität München
Computer Graphics
Antialiasing in texture mapping
• Mip-Mapping: how does it work?– When a fragment is texture mapped, the mip-map level
at which the texel size is equal to the pixel size is computed
– From this level the texture is then sampled
– It remains to be answered how the level is computed
33
Technische Universität München
Computer Graphics
Antialiasing in texture mapping
• We want to know what the size of one texel wrt the size of one pixel is – this allows estimating how many texels fall into one pixel
34
Technische Universität München
Computer Graphics
Antialiasing in texture mapping
• Computing the mip-map level:Check screen pixel “size” in texture coordinates
35less than one texel per pixelwe call this magnification
more than one texel per pixelwe call this minification
u,v: fragments texture coordinatesx,y: pixel coordinates
Technische Universität München
Computer Graphics
Antialiasing in texture mapping
36
Technische Universität München
Computer Graphics
Antialiasing in texture mapping
37 without MipMapping with MipMapping
Technische Universität München
Computer Graphics
Antialiasing in texture mapping
38Isotropic filtering
(mipmapping)Anisotropic filtering
Technische Universität München
Computer Graphics
Antialiasing in texture mapping
• Mip-Mapping– The mip-map only stores a discrete set of levels – If pixel size matches texel size at a level in between, it
is interpolated between the two adjacent levels
39
Sample 0
Sample 1
interpolateassignSelect
resolution
Bilinear in texture + linear between levels
= trilinear
Technische Universität München
Computer Graphics
40
Summary
• Quality of rendering strongly depends on antialiasing algorithms used– Typically, supersampling in combination with
prefiltering is used• Supersampling and mipmapping
• We are now ready to implement a high quality and efficient ray tracing algorithm
• What comes next is an alternative image synthesis approach based on the projection of geometry onto the image plane