Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Sampling
The relevance of this section and the following two in the context of
a course on computer graphics is mostly due to their significance to
texture mapping. This section discusses how to generate discrete
images from continuous ones; the next section looks at the opposite
process; the third one applies both of the above to texture mapping.
At the end of this section you will have:
encountered aliasing effects resulting from point sampling
understood basic anti-aliasing techniques, including filters, supersampling, and multisampling
learned about alpha blending
183
Sampling (1)
185
Sampling (2)
in animation, crawling jaggies and flickering may result
186
Sampling (3)
anti-aliasing techniques involve averaging or blurring:
Z Z
I[i][j]
187
Sampling (4)
with box filter
(
1
Fi,j (x, y) =
0
this becomes
if |x i| <
otherwise
1
2
and |y j| <
1
2
Z Z
I[i][j]
I(x, y) dx dy
i,j
188
Sampling (5)
Monte-Carlo approximation of the integral:
n
1X
I[i][j]
I(xk , yk )
n
k=1
oversampling
189
Sampling (6)
supersampling places the samples on a regular grid and is accomplished by
1. generating a high-resolution colour and z-buffer image
2. averaging groups of high-resolution pixels
less regular, random patterns can help avoid systematic errors
low-discrepancy sequences result in faster convergence
190
Sampling (7)
in multisampling, OpenGL generates high-resolution colour and zbuffers, but during rasterization invokes the fragment shader only
once per triangle and final resolution pixel
coverage and z values
this works well if colours vary slowly over triangles; textures need to
be dealt with separately
for further information see
https://www.opengl.org/wiki/Multisampling
191
Alpha (1)
suppose we have two discrete images, a foreground image If and a
background image Ib, and we want to superimpose the foreground
on the background
aliasing at the boundary of the foreground
192
Alpha (2)
alpha blending: associate with each pixel in each layer a value
[i][j] [0 . . . 1] describing opacity or coverage
for binary valued coverage function C(x, y):
Z Z
I(x, y)C(x, y) dx dy
I[i][j]
i,j
Z Z
[i][j]
C(x, y) dx dy
i,j
Alpha (3)
non-premultiplied format: store I0 = I/ rather than I
advantages:
improves precision for pixels with small coverage
shrinking the image by a factor of two in each direction only
requires averaging four I0 values
the over operator becomes
1
f
0f
b
0b
f
[i][j]I [i][j] + [i][j]I [i][j](1 [i][j])
I [i][j] c
[i][j]
0c
194
Alpha (4)
in OpenGL, alpha is used as a tool for modelling transparency and
blending colour values
blending is enabled with glEnable(GL_BLEND); the blending calculation is specified using glBlendFuncSeparate
195
Alpha (5)
main issue: noncommutativity of the over operator requires that
layers be drawn in some specific order
for further information see
https://www.opengl.org/wiki/Transparency_Sorting
Assignment 5:
Add either normal mapping or shadow mapping to the cubes from
Assignment 3. The latter is significantly more difficult than the
former.
196