3 aliasing and alpha - ucl · aliasing and alpha 2011 introduction to graphics, lecture 3 ©anthony...

32
ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012

Upload: others

Post on 23-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

ALIASING AND ALPHA

2011 Introduction to Graphics, Lecture 3

©Anthony Steed 2000-2006, Jan Kautz 2007–2012

Page 2: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Overview

¨  Plotting Pixels ¤ Aliasing ¤ Anti-aliasing

¨  Alpha Values ¨  Image Composition Rules

¤ Porter-Duff

¨  Super-Sampling

Page 3: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Plotting Pixels (1)

¨  Choosing the pixels on an array that depict a shape is hard.

¤ All pixels that are totally inside

¤ All pixels that touch the shape?

Page 4: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Plotting Pixels (2)

¨  One compromise is to

plot all pixels that overlap the shape by more than 50%

Page 5: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Consider Aliasing

¨  Principle features of the display are the horizontal and vertical edges of the pixels drawn

Page 6: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Examples From Wikimedia

Page 7: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Aliasing (1)

¨  Intensity of pixel determined by area overlap. % overlap determines gray level.

90% overlap

50% overlap

10% overlap

Page 8: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Aliasing (2)

¨  Works fine, but not simple when drawing shapes over existing image

problem pixels

Page 9: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Aliasing (3)

¨  Line appears to have a “halo” around it and appears to be in front of the previous line

¨  To solve this we work with alpha values

Pixels like this one are now lighter

Page 10: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Alpha Values

¨  0 (transparent) and 1 (opaque) ¨  Incorporated into colour model

¤ e.g. 8bit value ¤ RGBA = 32 bits

¨  So semi-transparent red will be ¤  (1,0,0,0.5)

¨  Think of the analogy of stacking up OHP slides

Page 11: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Drawing With Alpha

¨  Solution is to calculate alpha as a percentage overlap of the source image (the grey line in this case)

¨  Pixels around the edge are transparent and the old colour “shows through

Page 12: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Image Composition Rules

¨  Consider we have two (partial) screens in memory, dest and source

¨  We want to combine source into dest to update it with our new pixels

?

dest (old)

dest (new)

source

Page 13: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Common Composition

¨  source over destination (dest) ¤ Default mode for most APIs

dest

+ =

source dest

Page 14: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Porter Duff Composition Rules

¨  12 rules in total ¤ “source over destination”

n  is most common

¤ “dest over source”

¤ “clear”

Page 15: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

General Porter Duff Rule

¨  Colour

¨  Alpha

¨  cs,cd: colour, αs,αd: alpha-value, fs,fd: parameter ¨  fs and fd are functions in αs and αd

dddsssd cfcfc ⋅⋅+⋅⋅= αα'

ddssd ff ⋅+⋅= ααα '

Page 16: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Operation Diagram fa fb Clear 0 0

A 1 0

B 0 1

A over B 1 1-αA

B over A 1-αB 1

A in B αB 0

B in A 0 αA

A held out by B 1-αB 0

B held out by A 0 1-αA

A atop B αB 1-αA

B atop A 1-αB αA

A xor B 1-αB 1-αA

Page 17: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

A Little Exercise

¨  For which of the Porter Duff rules can you think of common uses?

¨  What types of composition rules do you think are used when creating film sequences that combine live action and digital effects?

Page 18: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Answer – Sort of

“Road to Point Reyes” – T. Cook (Pixar) 1982

Page 19: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing
Page 20: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Source Over Destination

¨  The source over destination is defined by fs = 1.0 and fd=1.0-αs:

¨  Note that when αd reaches 1.0, then it always remains 1.0

( )( )sdsd

dsdssd cccαααα

ααα

−⋅+⋅=

⋅−⋅+⋅⋅=

1111

'

'

( )( )sdsd

dsdssd cccαααα

ααα

−⋅+=

⋅−⋅+⋅=

11

'

'

ð

Page 21: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Src-Over-Dst Compositing Example

http://www.fxguide.com/fxtips-242.html

Page 22: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Background Colours

¨  Display devices do not display alpha, only RGB, therefore the final colour must be opaque

¨  Typically the screen is filled with an opaque background colour is a solid opaque colour such as ¤ White (1,1,1,1) ¤ Black (0,0,0,1)

Page 23: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Background Colour

¨  If dest is totally opaque (i.e. αd =1), the composition rule simplifies to

( )0.1

0.1=

⋅−+⋅=

new

dsssnew cccα

αα

Page 24: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Example

¨  Fill a black triangle (0,0,0,1) over a solid grey background (0.5, 0.5, 0.5, 1)

Page 25: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Source Over Destination

a) α=90% b) α=10%

c) α=100%

a) cd is (0.5, 0.5, 0.5)

cs is (0, 0, 0), αs is (0.9)

cnew = 0.9*(0,0,0) + 0.1*(0.5,0.5,0.5)

= (0.05,0.05,0.05)

Page 26: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Source Over Destination

a) α=90% b) α=10%

c) α=100%

b) cnew = 0.1*(0,0,0) + 0.9*(0.5,0.5,0.5)

= (0.45,0.45,0.45)

c) cnew = 1*(0,0,0) + 0*(0.5,0.5,0.5) = (0,0,0)

Page 27: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

A Little Exercise

¨  Do alpha-values produce accurate results for anti-aliasing?

¨  Why?

Page 28: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Super-Sampling (1)

¨  Recall the aliasing problem

¨  In super-sampling, render into a into larger image (2x)

¨  Average pixels to produce reduce aliasing

Page 29: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Super-Sampling (2)

¨  B(i,j) = (A(2i,2j) + A(2i+1,2j) + A(2i+1, 2j+1) + A(2i, 2j+1)) / 4

¨  Note how the result is smoother, but different than using overlap % contribution ¤  It is faster to compute though

Page 30: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Example

Page 31: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Alpha-Values vs. Super-Sampling

¨  Alpha-Values ¤ Accurate results for a single shape ¤ Multiple overlapping shapes: approximate anti-aliasing

¨  Super-sampling ¤ For 2x2: only 5 different grey values! ¤ Multiple overlapping shapes: handled (more)

accurately

Page 32: 3 Aliasing and Alpha - UCL · ALIASING AND ALPHA 2011 Introduction to Graphics, Lecture 3 ©Anthony Steed 2000-2006, Jan Kautz 2007–2012 . Overview ! Plotting Pixels ! Aliasing

Summary

¨  Plotting pixels ¤ Aliasing ¤ Anti-aliasing

¨  Alpha values ¨  Image Composition Rules

¤ Porter-Duff

¨  Super-sampling