1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.

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.
Hank Childs, University of Oregon Nov. 25th, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 15: animation, transparency.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Week 7 - Monday.  What did we talk about last time?  Specular shading  Aliasing and antialiasing.
Compositing and Blending Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Blending MAE152 Computer Graphics for Engineers and Scientists Fall 03.
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
Objectives Introduce OpenGL buffers and read/write Introduce OpenGL buffers and read/write Introduce texture mapping Introduce texture mapping Introduce.
Chapter 6: Vertices to Fragments Part 2 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley Mohan Sridharan Based on Slides.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Introduction to Computer Graphics Ed Angel Professor of Computer Science, Electrical and.
7/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 4: Visual Appearance.
CSE (Notre Dame) Computer Graphics Lecture 16 A Simple Draw Image Example More Texture Mapping Simple OpenGL Image Library (SOIL) Transparency &
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Lecture 12 Blending, Anti-aliasing, Fog, Display Lists.
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Angel and Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Introduction to Computer Graphics Ed Angel Professor Emeritus of Computer.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
Implementation II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Compositing and Blending
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
UniS CS297 Graphics with Java and OpenGL Blending.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Compositing and Blending Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Computer Graphics I, Fall 2008 Compositing and Blending.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Buffers Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
I = a I + ( ) 1 – a I BLENDING, ANTIALIASING, AND FOG l l 1 l 2 Earth
Introduction to Computer Graphics with WebGL
CSc4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Fog and Transparency.
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 4: Color and Attributes
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Introduction to Computer Graphics with WebGL
Implementation II Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Buffers Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 4: Color and Attributes
Implementation II Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science Laboratory University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Compositing and Blending Ed Angel Professor Emeritus of Computer Science University of New Mexico 2 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

3 Objectives Learn to use the A component in RGBA color for ­Blending for translucent surfaces ­Compositing images ­Antialiasing Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

4 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 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

5 Physical Models Dealing with translucency in a physically correct manner is difficult due to ­the complexity of the internal interactions of light and matter ­Using a pipeline renderer Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

6 Writing Model Use A component of RGBA (or RGB  ) color to store opacity During rendering we can expand our writing model to use RGBA values Color Buffer destination component blend destination blending factor source blending factor source component Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

7 Blending Equation We 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 that the 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  ] Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

8 OpenGL Blending and Compositing Must enable blending and pick source and destination factors gl.enable(gl.BLEND) gl.blendFunc(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 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

9 Example Suppose that we start with the opaque background color (R 0,G 0,B 0,1) ­This color becomes the initial destination color We now want to blend in a translucent polygon with color (R 1,G 1,B 1,  1 ) Select GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA as the source and destination blending factors R ’ 1 =  1 R 1 +(1-  1 ) R 0, G ’ 1 =  1 G 1 …… Note this formula is correct if polygon is either opaque or transparent Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

10 Clamping and Accuracy All the components (RGBA) are clamped and stay in the range (0,1) However, in a typical system, RGBA values are only stored to 8 bits ­Can easily loose accuracy if we 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 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

11 Order Dependency Is this image correct? ­Probably not ­Polygons are rendered in the order they pass down the pipeline ­Blending functions are order dependent Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

12 Opaque and Translucent Polygons Suppose that we have a group of polygons, some of which are opaque and some translucent How do we use hidden-surface removal? Opaque polygons block all polygons behind them and affect the depth buffer Translucent polygons should not affect depth buffer ­Render with gl.depthMask(false) which makes depth buffer read-only Sort polygons first to remove order dependency ­Always draw opaque objects first (translucent objects last) Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

13 Examples See texture-cube-translucent.html + texture- cube-translucent.jstexture-cube-translucent.htmltexture- cube-translucent.js Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

14 Fog We can composite with a fixed color and have the blending factors depend on depth ­Simulates a fog effect Blend source color C s and fog color C f by C s ’=f C s + (1-f) C f f is the fog factor ­Exponential ­Gaussian ­Linear (depth cueing) Deprecated but can recreate the effect in fragment shader Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

15 Fog Functions Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

(Compositing and HTML) In desktop OpenGL, the A component has no effect unless blending is enabled In WebGL, an A other than 1.0 has an effect because WebGL works with the HTML5 Canvas element ­A = 0.5 will cut the RGB values by ½ when the pixel is displayed ­Allows other applications to be blended into the canvas along with the graphics 16 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

17 (Line Aliasing) Ideal raster line is one pixel wide All line segments, other than vertical and horizontal segments, partially cover pixels Simple algorithms color only whole pixels Lead to the “jaggies” or aliasing Similar issue for polygons Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

18 (Antialiasing ) Can try to color a pixel by adding a fraction of its color to the frame buffer ­Fraction depends on percentage of pixel covered by fragment ­Fraction depends on whether there is overlap no overlapoverlap Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

19 (Area Averaging) Use average area  1 +  2 -  1  2 as blending factor Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

20 (OpenGL Antialiasing) Not (yet) supported in WebGL Can enable separately for points, lines, or polygons Note most hardware will automatically antialias glEnable(GL_POINT_SMOOTH); glEnable(GL_LINE_SMOOTH); glEnable(GL_POLYGON_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015