Sei sulla pagina 1di 14

Chapter 16

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 and Reconstruction


images are discrete or continuous
a continuous image is a bivariate function
I : D R
where D = [0.5 . . . (W 0.5)] [0.5 . . . (H 0.5)] R2 and R
is some colour space
a discrete image is an array I[i][j] of colour values, where i is in
{0, 1, . . . , W 1} and j is in {0, 1, . . . , H 1}
discrete images are obtained from continuous ones through sampling
continuous images are obtained from discrete ones through reconstruction
digital images are discrete images that have been quantized
184

Sampling (1)

point sampling obtains the value of a pixel


through I[i][j] I(i, j)
jaggies, Moire patterns
top: point sampled image
middle: OpenGL multisampling
bottom: offline supersampling
aliasing artifacts arise when there is too
much visual complexity to fit in a single pixel

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]

I(x, y)Fi,j (x, y) dx dy

with filter function Fi,j (x, y)

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

where i,j = [(i 0.5) . . . (i + 0.5)] [(j 0.5) . . . (j + 0.5)]

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

to compose If[i][j] over Ib[i][j] compute


Ic[i][j] If[i][j] + Ib[i][j](1 f[i][j])
c[i][j] f[i][j] + b[i][j](1 f[i][j])
over operator; associative but not commutative
193

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

c[i][j] f[i][j] + b[i][j](1 f[i][j])

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

fur is drawn as a series


of shells, each textured with an image representing a slice of fur
spaces between the fur
are semi-transparent

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

Potrebbero piacerti anche