1 / 18

Blending

MAE152 Computer Graphics for Engineers and Scientists Fall 03. Blending. Outline. Why do we want to blend? What is blending? Math behind blending Blending in OpenGL. Why do we want to blend?. We use triangles to describe surfaces We always assumed opaque surfaces

damita
Download Presentation

Blending

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MAE152Computer Graphics for Engineers and Scientists Fall 03 Blending

  2. Outline • Why do we want to blend? • What is blending? • Math behind blending • Blending in OpenGL

  3. Why do we want to blend? • We use triangles to describe surfaces • We always assumed opaque surfaces • How would we do transparent surfaces? • What are some types of transparent surfaces? • Windows • Saran Wrap • Plastic • Stained Glass • Water

  4. Alpha: the 4th Color Component • Measure of Opacity • simulate translucent objects • glass, water, etc. • composite images • antialiasing • ignored if blending is not enabled glEnable( GL_BLEND )

  5. Blend

  6. Source and Destination • Objects are blended together in a scene in the order in which they are drawn. • An object being drawn it is the "source“. • Any object, over which a source object is drawn is a “destination”.  • Blending functions, along with alpha values control how source and destination colors are mixed together.

  7. Source and Destination Factors • RGBA blending factors • Source Sr, Sg, Sb, Sa • Destination Dr, Dg, Db, Da • “Current” RGBA components • Source Rs, Gs, Bs, As • Destination Rd, Gd, Bd, Ad • Resultant RGBA components (destination) ((Rs x Sr) + (Rd x Dr), (Gs x Sg) + (Gd x Dg), (Bs x Sb) + (Bd x Db), (As x Sa) +(Ad x Da)) • The new destination values are clamped to [0.0-1.0].

  8. Blending in OGL • If a fragment makes it to FB, the pixel is read out and blended with the fragment’s color and then written back to FB • The contributions of fragment and FB pixel is specified: glBlendFunc( src, dst )

  9. We would like to combine the two colors • Fragment or source - incoming color • destination - existing color • How should we combine them? • We use the alpha channel to describe the combination of the source and destination. • ColorFinal = A*ColorSource + B*ColorDestination • Most APIs let you specify A and B • What does A and B mean qualitatively?

  10. Combining Colors • Usually we take the source alpha as a “percentage” of the incoming fragment. • Thus the equation becomes: • ColorFinal=AlphaSource*ColorSource +(1- AlphaSource)*ColorDestination • What is the “default” alpha values for no blending? • What does this mean about the order of objects? • Order DOES MATTER when you have alpha objects!

  11. Order Matters with Alpha!

  12. Setting Alpha Values • Unlit models • Use the fourth parameter of the glColor4f() command to set the alpha value • alpha = 0.0 makes the object completely transparent • alpha = 1.0 makes the object completely opaque • Lit models • The alpha value of an object is specified with the glMaterial*() function when specifying, ambient, diffuse, specular or emissive light parameters • Example: GLfloat mat_transparent[] = { 0.0, 0.8, 0.8, 0.6 }; //init fn glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_transparent);

  13. Setting the Blend Function • Blend Function controls color and alpha values between source and destination objects void glBlendFunc( GLenum sfactor, GLenum dfactor) • Sfactor: source blending factor • Dfactor: destination blending factors • The value of these blending factors and their computed blending factors is tabulated.

  14. Setting the Blend Function

  15. Fragment • Fragment in OGL: after the rasterization stage (including texturing), the data are not yet pixel, but are fragments • Fragment is all the data associated with a pixel, including coordinate, color, depth and texture coordinates.

  16. Demo • Overlapping Triangles

  17. 3D Blending with Depth Buffer • A scene of opaque and translucent objects • Enable depth buffering and depth test • Draw opaque objects • Make the depth buffer read only, with glDepthMask(GL_FALSE) • Draw the translucent objects (sort those triangles still, but which order, FTB or BTF?)

  18. Demo • 3-D blending with depth buffer

More Related