Sort-Independent Alpha Blending Houman Meshkin

Slides:



Advertisements
Similar presentations
Visible-Surface Detection(identification)
Advertisements

Compositing and Blending Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
03/12/02 (c) 2002 University of Wisconsin, CS559 Last Time Some Visibility (Hidden Surface Removal) algorithms –Painter’s Draw in some order Things drawn.
Compositing and Blending Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Compositing and Blending - Chapter 8 modified by Ray Wisman Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Image Compositing Angel 8.11 Angel: Interactive Computer Graphics5E © Addison-Wesley
CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.
Computational Methods in Physics PHYS 3437
Lecture 2: Numerical Differentiation. Derivative as a gradient
Mr Barton’s Maths Notes
7/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 4: Visual Appearance.
By : Frison Colored Pencil Honors Art, Studio Painting and Drawing.
Relationships Among Variables
Computer Graphics Shadows
Solving a System of Equations using Multiplication
Photoshop Evaluation Kristy Ma 10E. DEVELOPMENT Step One I first found a picture of me that I wanted to use as my album cover. I chose this one because.
Computer Graphics Mirror and Shadows
Spreadsheets and Microsoft Excel. Introduction n A spreadsheet (called a worksheet in Excel) is a two-dimensional array of cells containing data to be.
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Multiscale Moment-Based Painterly Rendering Diego Nehab and Luiz Velho
Filtering and Color To filter a color image, simply filter each of R,G and B separately Re-scaling and truncating are more difficult to implement: –Adjusting.
Factoring Tutorial.
Advanced Computer Graphics Depth & Stencil Buffers / Rendering to Textures CO2409 Computer Graphics Week 19.
4th Grade Math Multiplying 2-digit by 2-digit Numbers Using the Area Model / Box Method.
Numbers Working with negative numbers. Numbers There are many different ways of adding and subtracting negative numbers; we all have different methods.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
CSC 2535 Lecture 8 Products of Experts Geoffrey Hinton.
1 Chapter 1 Infinite series, Power series ( 무한급수, 멱급수 ) Mathematical methods in the physical sciences 3rd edition Mary L. Boas Lecture 1 Infinite series,
Digital Image Compositing. Compositing for volume rendering c1 c2 c3 The initial pixel color = Black opaque Back-to-Front compositing: use ‘under’ operator.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Realtime NPR Toon and Pencil Shading Joel Jorgensen May 4, 2010.
Math 104 Calculus I Part 6 INFINITE SERIES. Series of Constants We’ve looked at limits and sequences. Now, we look at a specific kind of sequential limit,
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Duy & Piotr. How to reconstruct a high quality image with the least amount of samples per pixel the least amount of resources And preserving the image.
Compositing and Blending
Distributive Property with Partial Products Method of Multiplication Multiplying 2-digit by 2-digit Numbers.
Emerging Technologies for Games Deferred Rendering CO3303 Week 22.
Computer Graphics Blending CO2409 Computer Graphics Week 14.
Solving Systems of Equations Algebraically Chapter 3.2.
An Overview of the Objectives, Approach, and Components of ComET™ Mr. Paul Price The LifeLine Group All slides and material Copyright protected.
Visual Appearance Chapter 4 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
Single Pass Point Rendering and Transparent Shading Paper by Yanci Zhang and Renato Pajarola Presentation by Harmen de Weerd and Hedde Bosman.
Chris Covington CSCI263 – Final Project May 3, 2005 Changes and Additions: Further implemented the illumination model. Illumination is now calculated in.
Shell Sort. Invented by Donald Shell in 1959, the shell sort is the most efficient of the O(n²) class of sorting algorithms. Of course, the shell sort.
Chapter 3 Whole Numbers Section 3.5 Algorithms for Whole-Number Addition and Subtraction.
CIE Centre A-level Further Pure Maths
Unpacking each and every strategy! THE MATHEMATICIAN’S TOOLBOX.
Things may appear very different in here because every one of my students are different. If you take a look at a “standard classroom” every student works.
Compositing and Blending Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Visible-Surface Detection Methods. To identify those parts of a scene that are visible from a chosen viewing position. Surfaces which are obscured by.
Algebra The greatest mathematical tool of all!!. This is a course in basic introductory algebra. Essential Prerequisites: Ability to work with directed.
Computer Graphics I, Fall 2008 Compositing and Blending.
Week 1 Real Numbers and Their Properties (Section 1.6, 1.7, 1.8)
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
Multiplication and Division basics
Week 7 - Monday CS361.
Introduction to Computer Graphics with WebGL
The greatest mathematical tool of all!!
Chapter 10 Computer Graphics
Visual Appearance Chapter 4
Deferred Lighting.
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
UMBC Graphics for Games
Ordering fractions We can order numbers fairly easily. E.g
What role does place value have in whole number operations?
Ordering fractions We can order numbers fairly easily. E.g
Ordering fractions We can order numbers fairly easily. E.g
Good presentation is a matter of individual style
Presentation transcript:

Sort-Independent Alpha Blending Houman Meshkin

Alpha blending  Alpha blending is used to show translucent objects  Translucent objects render by blending with the background  Opaque objects just cover the background

Varying alpha

Blending order  The color of a translucent pixel depends on the color of the pixel beneath it  it will blend with that pixel, partially showing its color, and partially showing the color of the pixel beneath it  Translucent objects must be rendered from far to near

Challenge  It’s very complex and complicated to render pixels from far to near  Object-center sorting is common  still can be time consuming  Object sorting doesn’t guarantee pixel sorting  objects can intersect each other  objects can be concave  pixel sorting is required for correctness

The Formula  C0: foreground RGB color  A0: alpha representing foreground’s translucency  D0: background RGB color  FinalColor = A0 * C0 + (1 – A0) * D0  as A0 varies between 0 and 1, FinalColor varies between D0 and C0

Multiple translucent layers

Formula for multiple translucent layers  Cn: RGB from n th layer  An: Alpha from n th layer  D0: background  D1 = A0*C0 + (1 - A0)*D0  D2 = A1*C1 + (1 - A1)*D1  D3 = A2*C2 + (1 - A2)*D2  D4 = A3*C3 + (1 - A3)*D3

Expanding the formula  D4 = A3*C3  + A2*C2*(1 - A3)  + A1*C1*(1 - A3)*(1 - A2)  + A0*C0*(1 - A3)*(1 - A2)*(1 - A1)  + D0*(1 - A3)*(1 - A2)*(1 - A1)*(1 - A0)

Further expanding…  D4 = A3*C3  + A2*C2 - A2*A3*C2  + A1*C1 - A1*A3*C1 - A1*A2*C1 + A1*A2*A3*C1  + A0*C0 - A0*A3*C0 - A0*A2*C0 + A0*A2*A3*C0  - A0*A1*C0 + A0*A1*A3*C0 + A0*A1*A2*C0 - A0*A1*A2*A3*C0  + D0 - A3*D0 - A2*D0 + A2*A3*D0 - A1*D0  + A1*A3*D0 + A1*A2*D0 - A1*A2*A3*D0 - A0*D0  + A0*A3*D0 + A0*A2*D0 - A0*A2*A3*D0 + A0*A1*D0  - A0*A1*A3*D0 - A0*A1*A2*D0 + A0*A1*A2*A3*D0

Rearranging…  D4 = D0  + A0*C0 + A1*C1 + A2*C2 + A3*C3  - A0*D0 - A1*D0 - A2*D0 - A3*D0  + A0*A3*D0 + A0*A2*D0 + A0*A1*D0  + A1*A3*D0 + A1*A2*D0 + A2*A3*D0  - A0*A3*C0 - A0*A2*C0 - A0*A1*C0  - A1*A3*C1 - A1*A2*C1 - A2*A3*C2  + A0*A1*A2*C0 + A0*A1*A3*C0 + A0*A2*A3*C0 + A1*A2*A3*C1  - A0*A1*A2*D0 - A0*A1*A3*D0 - A0*A2*A3*D0 - A1*A2*A3*D0  + A0*A1*A2*A3*D0  - A0*A1*A2*A3*C0

Sanity check  Let’s make sure the expanded formula is still correct  case where all alpha = 0  D4 = D0  only background color shows (D0)  case where all alpha = 1  D4 = C3  last layer’s color shows (C3)

Pattern recognition  D4 = D0  + A0*C0 + A1*C1 + A2*C2 + A3*C3  - A0*D0 - A1*D0 - A2*D0 - A3*D0  + A0*A3*D0 + A0*A2*D0 + A0*A1*D0  + A1*A3*D0 + A1*A2*D0 + A2*A3*D0  - A0*A3*C0 - A0*A2*C0 - A0*A1*C0  - A1*A3*C1 - A1*A2*C1 - A2*A3*C2  + A0*A1*A2*C0 + A0*A1*A3*C0 + A0*A2*A3*C0 + A1*A2*A3*C1  - A0*A1*A2*D0 - A0*A1*A3*D0 - A0*A2*A3*D0 - A1*A2*A3*D0  + A0*A1*A2*A3*D0  - A0*A1*A2*A3*C0  There’s clearly a pattern here  we can easily extrapolate this for any number of layers  There is also a balance of additions and subtractions with layer colors and background color

Order dependence  D4 = D0  + A0*C0 + A1*C1 + A2*C2 + A3*C3  - A0*D0 - A1*D0 - A2*D0 - A3*D0  - A0*A1*A2*D0 - A0*A1*A3*D0 - A0*A2*A3*D0 - A1*A2*A3*D0  + A0*A1*A2*A3*D0  - A0*A3*C0 - A0*A2*C0 - A0*A1*C0  - A1*A3*C1 - A1*A2*C1 - A2*A3*C2  + A0*A3*D0 + A0*A2*D0 + A0*A1*D0  + A1*A3*D0 + A1*A2*D0 + A2*A3*D0  + A0*A1*A2*C0 + A0*A1*A3*C0 + A0*A2*A3*C0 + A1*A2*A3*C1  - A0*A1*A2*A3*C0  order independent part  order dependent part

Order independent Part  D4 = D0  + A0*C0 + A1*C1 + A2*C2 + A3*C3  - A0*D0 - A1*D0 - A2*D0 - A3*D0  - A0*A1*A2*D0 - A0*A1*A3*D0 - A0*A2*A3*D0 - A1*A2*A3*D0  + A0*A1*A2*A3*D0  …  Summation and multiplication are both commutative operations  i.e. order doesn’t matter  A0 + A1 = A1 + A0  A0 * A1 = A1 * A0  A0*C0 + A1*C1 = A1*C1 + A0*C0

Order independent Part  D4 = D0  + A0*C0 + A1*C1 + A2*C2 + A3*C3  - A0*D0 - A1*D0 - A2*D0 - A3*D0  - A0*A1*A2*D0 - A0*A1*A3*D0 - A0*A2*A3*D0 - A1*A2*A3*D0  + A0*A1*A2*A3*D0  …  Highlighted part may not be obvious, but here’s the simple proof:  - A0*A1*A2*D0 - A0*A1*A3*D0 - A0*A2*A3*D0 - A1*A2*A3*D0  =  - D0*A0*A1*A2*A3 * (1/A0 + 1/A1 + 1/A2 + 1/A3)

Order dependent Part  D4 = …  - A0*A3*C0 - A0*A2*C0 - A0*A1*C0  - A1*A3*C1 - A1*A2*C1 - A2*A3*C2  + A0*A3*D0 + A0*A2*D0 + A0*A1*D0  + A1*A3*D0 + A1*A2*D0 + A2*A3*D0  + A0*A1*A2*C0 + A0*A1*A3*C0 + A0*A2*A3*C0 + A1*A2*A3*C1  - A0*A1*A2*A3*C0  These operations depend on order  results will vary if transparent layers are reordered  proof that proper alpha blending requires sorting

Can we ignore the order dependent part?  Do these contribute a lot to the final result of the formula?  not if the alpha values are relatively low  they’re all multiplying alpha values < 1 together  even with just 2 layers each with alpha = 0.25  0.25 * 0.25 = which can be relatively insignificant  more layers also makes them less important  as do darker colors

Error analysis  Let’s analyze the ignored order dependent part (error) in some easy scenarios  all alphas = 0  error = 0  all alphas = 0.25  error = 0.375*D *C *C *C2  all alphas = 0.5  error = 1.5*D *C *C *C2  all alphas = 0.75  error = 3.375*D *C *C *C2  all alphas = 1  error = 6*D0 - C0 - C1 - C2

Simpler is better  A smaller part of the formula works much better in practice  = D0  + A0*C0 + A1*C1 + A2*C2 + A3*C3  - A0*D0 - A1*D0 - A2*D0 - A3*D0  The balance in the formula is important  it maintains the weight of the formula  This is much simpler and requires only 2 passes and a single render target  1 less pass and 2 less render targets  This formula is also exactly correct when blending a single translucent layer

Error analysis  Let’s analyze the simpler formula in some easy scenarios  all alphas = 0  error simple = 0  error prev = 0  all alphas = 0.25  error simple = *D *C *C *C2  error prev = 0.375*D *C *C *C2  all alphas = 0.5  error simple = *D *C *C *C2  error prev = 1.5*D *C *C *C2  all alphas = 0.75  error simple = *D *C *C *C2  error prev = 3.375*D *C *C *C2  all alphas = 1  error simple = 3*D0 - C0 - C1 - C2  error prev = 6*D0 - C0 - C1 - C2

Error comparison  Simpler formula actually has less error  explains why it looks better  This is mainly because of the more balanced formula  positives cancelling out negatives  source colors cancelling out background color

Does it really work?  Little error with relatively low alpha values  good approximation  Completely inaccurate with higher alpha values  Demo can show it much better than text

Sorted, alpha = 0.25

Approx, alpha = 0.25

Sorted, alpha = 0.5

Approx, alpha = 0.5

Implementation  We want to implement the order independent part and just ignore the order dependent part  D4 = D0  + A0*C0 + A1*C1 + A2*C2 + A3*C3  - A0*D0 - A1*D0 - A2*D0 - A3*D0  - A0*A1*A2*D0 - A0*A1*A3*D0 - A0*A2*A3*D0 - A1*A2*A3*D0  + A0*A1*A2*A3*D0  8 bits per component is not sufficient  not enough range or accuracy  Use 16 bits per component (64 bits per pixel for RGBA)  newer hardware support alpha blending with 64 bpp buffers  We can use multiple render targets to compute multiple parts of the equation simultaneously

1 st pass  Use additive blending  SrcAlphaBlend = 1  DstAlphaBlend = 1  FinalRGBA = SrcRGBA + DstRGBA  render target #1, n th layer  RGB = An * Cn  Alpha = An  render target #2, n th layer  RGB = 1 / An  Alpha = An

1 st pass results  After n translucent layers have been blended we get:  render target #1:  RGB1 = A0 * C0 + A1 * C1 + … + An * Cn  Alpha1 = A0 + A1 + … + An  render target #2:  RGB2 = 1 / A0 + 1 / A1 + … + 1 / An  Alpha2 = A0 + A1 + … + An

2 nd pass  Use multiplicative blending  SrcAlphaBlend = 0  DstAlphaBlend = SrcRGBA  FinalRGBA = SrcRGBA * DstRGBA  render target #3, n th layer  RGB = Cn  Alpha = An

2 nd pass results  After n translucent layers have been blended we get:  render target #3:  RGB3 = C0 * C1 * … * Cn  Alpha3 = A0 * A1 * … * An  This pass isn’t really necessary for the better and simpler formula  just for completeness

Results  We now have the following  background  D0  render target #1:  RGB1 = A0 * C0 + A1 * C1 + … + An * Cn  Alpha1 = A0 + A1 + … + An  render target #2:  RGB2 = 1 / A0 + 1 / A1 + … + 1 / An  Alpha2 = A0 + A1 + … + An  render target #3:  RGB3 = C0 * C1 * … * Cn  Alpha3 = A0 * A1 * … * An

Final pass  Blend results in a pixel shader  RGB1 - D0 * Alpha1  = A0*C0 + A1*C1 + A2*C2 + A3*C3  - D0 * (A0 + A1 + A2 + A3)  D0 * Alpha3  = D0 * (A0*A1*A2*A3)  D0 * RGB2 * Alpha3  = D0 * (1/A0 + 1/A1 + 1/A2 + 1/A3) * (A0*A1*A2*A3)  = D0 * (A1*A2*A3 + A0*A2*A3 + A0*A1*A3 + A0*A1*A2)  Sum results with background color (D0) and we get:  = D0  + A0*C0 + A1*C1 + A2*C2 + A3*C3  - D0 * (A0 + A1 + A2 + A3)  + D0 * (A0*A1*A2*A3)  - D0 * (A1*A2*A3 + A0*A2*A3 + A0*A1*A3 + A0*A1*A2)  That’s the whole sort independent part of the blend formula

Application  This technique is best suited for particles  too many to sort  slight inaccuracy in their color shouldn’t matter too much  Not so good for very general case, with all ranges of alpha values  For general case, works best with highly translucent objects  i.e. low alpha values

Can we do better?  I hope so…  Keep looking at the order dependent part of the formula to see if we can find more order independent parts out of it  D4 = D0  + A0*C0 + A1*C1 + A2*C2 + A3*C3  - A0*D0 - A1*D0 - A2*D0 - A3*D0  - A0*A1*A2*D0 - A0*A1*A3*D0 - A0*A2*A3*D0 - A1*A2*A3*D0  + A0*A1*A2*A3*D0  - A0*A3*C0 - A0*A2*C0 - A0*A1*C0  - A1*A3*C1 - A1*A2*C1 - A2*A3*C2  + A0*A3*D0 + A0*A2*D0 + A0*A1*D0  + A1*A3*D0 + A1*A2*D0 + A2*A3*D0  + A0*A1*A2*C0 + A0*A1*A3*C0 + A0*A2*A3*C0 + A1*A2*A3*C1  - A0*A1*A2*A3*C0  Or use a completely different algorithm

Q&A  If you have any other ideas or suggestions I’d love to hear them 