Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 91.427 Computer Graphics I, Fall 2008 Compositing and Blending.

Similar presentations


Presentation on theme: "1 91.427 Computer Graphics I, Fall 2008 Compositing and Blending."— Presentation transcript:

1 1 91.427 Computer Graphics I, Fall 2008 Compositing and Blending

2 2 91.427 Computer Graphics I, Fall 2008 Objectives Learn to use the A component in RGBA color for ­Blending for translucent surfaces ­Compositing images ­Antialiasing

3 3 91.427 Computer Graphics I, Fall 2008 Opacity and Transparency Opaque surfaces permit no light to pass through Transparent surfaces permit all light to pass Translucent surfaces pass some light translucency = 1 – opacity (  ) opaque surface  =1

4 4 91.427 Computer Graphics I, Fall 2008 Physical Models Dealing with translucency in physically correct manner difficult due to ­complexity of internal interactions of light and matter ­Using pipeline renderer

5 5 91.427 Computer Graphics I, Fall 2008 Writing Model Use A component of RGBA (or RGB  ) color to store opacity During rendering can expand writing model to use RGBA values Color Buffer destination component blend destination blending factor source blending factor source component

6 6 91.427 Computer Graphics I, Fall 2008 Blending Equation Can define source and destination blending factors for each RGBA component s = [s r, s g, s b, s  ] d = [d r, d g, d b, d  ] Suppose source and destination colors are b = [b r, b g, b b, b  ] c = [c r, c g, c b, c  ] Blend as c’ = [b r s r + c r d r, b g s g + c g d g, b b s b + c b d b, b  s  + c  d  ]

7 7 91.427 Computer Graphics I, Fall 2008 OpenGL Blending and Compositing Must enable blending and pick source and destination factors glEnable(GL_BLEND) glBlendFunc(source_factor, destination_factor) Only certain factors supported ­GL_ZERO, GL_ONE ­GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ­GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA ­See Redbook for complete list

8 8 91.427 Computer Graphics I, Fall 2008 Example Suppose start with opaque background color (R 0,G 0,B 0,1) ­==> initial destination color Now want to blend in translucent polygon with color (R 1,G 1,B 1,  1 ) Select GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA as source and destination blending factors R ’ 1 =  1 R 1 +(1-  1 ) R 0, …… Note this formula correct if polygon either opaque or transparent

9 9 91.427 Computer Graphics I, Fall 2008 Clamping and Accuracy All components (RGBA) clamped and stay in range (0,1) However, in typical system, RGBA values only stored to 8 bits ­Can easily lose accuracy if add many components together ­Example: add together n images Divide all color components by n to avoid clamping Blend with source factor = 1, destination factor = 1 But division by n loses bits

10 10 91.427 Computer Graphics I, Fall 2008 Order Dependency Is this image correct? ­Probably not ­Polygons rendered in order they pass down pipeline ­Blending functions are order dependent

11 11 91.427 Computer Graphics I, Fall 2008 Opaque and Translucent Polygons Suppose have group of polygons some opaque, some translucent How use hidden-surface removal? Opaque polygons block all polygons behind them and affect depth buffer Translucent polygons should not affect depth buffer ­Render with glDepthMask(GL_FALSE) which makes depth buffer read-only Sort polygons first to remove order dependency

12 12 91.427 Computer Graphics I, Fall 2008 Fog Can composite with fixed color and have blending factors depend on depth ­Simulates fog effect Blend source color C s and fog color C f by C s ’=f C s + (1-f) C f f is fog factor ­Exponential ­Gaussian ­Linear (depth cueing)

13 13 91.427 Computer Graphics I, Fall 2008 Fog Functions

14 14 91.427 Computer Graphics I, Fall 2008 OpenGL Fog Functions GLfloat fcolor[4] = {……}: glEnable(GL_FOG); glFogf(GL_FOG_MODE, GL_EXP); glFogf(GL_FOG_DENSITY, 0.5); glFOgv(GL_FOG, fcolor);

15 15 91.427 Computer Graphics I, Fall 2008 Line Aliasing Ideal raster line = one pixel wide All line segments, other than vertical and horizontal segments, partially cover pixels Simple algorithms color only whole pixels Lead to “jaggies” or aliasing Similar issue for polygons

16 16 91.427 Computer Graphics I, Fall 2008 Antialiasing Can try to color pixel by adding fraction of its color to frame buffer ­Fraction depends on percentage of pixel covered by fragment ­Fraction depends on whether there is overlap no overlapoverlap

17 17 91.427 Computer Graphics I, Fall 2008 Area Averaging Use average area  1 +  2 -  1  2 as blending factor

18 18 91.427 Computer Graphics I, Fall 2008 OpenGL Antialiasing Can enable separately for points, lines, or polygons glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); glEnable(GL_POLYGON_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

19 19 91.427 Computer Graphics I, Fall 2008 Accumulation Buffer Compositing and blending limited by resolution of frame buffer ­Typically 8 bits per color component Accumulation buffer = high resolution buffer (16 or more bits per component) ==> avoids this problem Write into it or read from it with scale factor Slower than direct compositing into frame buffer

20 20 91.427 Computer Graphics I, Fall 2008 Applications Compositing Image Filtering (convolution) Whole scene antialiasing Motion effects


Download ppt "1 91.427 Computer Graphics I, Fall 2008 Compositing and Blending."

Similar presentations


Ads by Google