Blending, Antialiasing, and Fog, and Polygon Offset
  • A mixed bag of topics:
    • Blending of colors to achieve transulcency
    • Smooting jagged edges of lines and polygons
    • Producing realistic atmospheric effects
    • Rendering co-planar geometry

     
  •  We've covered the basics of geometry - let's get a little fancy 

  • (image of advanced rendering)

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Blending
  • Up to this point the alpha component (A of RGBA) has been ignored
  • Alpha values are specified with glColor() and glClearColor()

  •  
  •  When blending is enabled alpha value determines the fraction that a pixel's color contributes to the value already in the framebuffer
  • Without blending polygons are considred opaque
    • With blending objects can appear transparent
  • NOTE!  No alpha blending in color-index mode
  •  

     

     
     
     
     
     
     
     
     
     


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 

  Source andDestination Factors 
 
 
  • During blending, the  incoming fragment (source) is added to the existing framebuffer value (the destination) 

  • Final Pixel = 
        (R s S r +R d D r , G s S g +G d D g , B s S b +B d D b , A s S a +A d D a )

    • All values are clamped to 1.0

    •  

       
       
       
       
       
       
       
       
       


     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

      Generating blending factors
    • Blending must be enabled with glEnable(GL_BLEND)

    •  
    • glBlendFunc() defines two constraints:
      • How the source factor should be computed
      • How the destination factor should be computed
    void glBlendFunc(GLenum sfactor, GLenum dfactor); 
      Controls how color values in the fragment being processed (the source) are combined with those already stored in the framebuffer (the destination). 
      The argument sfactor indicates how to compute a source blending factor; dfactor indicates how to compute a destination blending factor. 

      The blend factors are assumed to lie in the range [0,1]; 

      Values are clamped to the range [0,1].


     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

      Parameters for glBlend()

       
       
       
       
       
       
       

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

      Sample uses of Blending
    • Not all combinations make sense
      • Sometimes there's more than one way to do something



       

    •  Mixing polygons of two different transparencies
      • Source = GL_ONE  Dest = GL_ZERO
      • Set alpha = 0.25
      • Draw first object
      • Source = GL_SOURCE_ALPHA Dest = GL_ONE_MINUS_SRC_ALPHA
      • Set alpha = 0.75
      • Draw second object

       

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

      Sample uses of Blending (cont)
    • Two blend 3 objects equally:
      • Set the destination = GL_ONE
      • Set the source = GL_ALPHA
      • Draw each of the objects with alpha = 0.33333

       
       
       
       
       
       
       

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

      Sample uses of Blending (cont)
    • Billboarding


    •  
       
       
       
       
       
       
       
       


     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

      Three-Dimensional Blending 
    • The ORDER in which polygons are drawn greatly affects the final outcome
      • F->B vs B->F can greatly affect the final image

       
       
    •  This is especially important for volume rendering

    •  

       
       
       
       
       
       
       
       
       
       
       


     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

     

      Use of the Depth Buffer for Translucency
    • For a static viewpoint, just sort the objects B->F
      • Lots of ways (calc distance, then quicksort)
    • For a dynamic viewpoint:
      • Draw all opaque objects w/Z-buffer
      • Make the Z-buffer read only
      • Draw the translucent objects
        • Objects behind opaque objects (won't be drawn)
        • Objects in front of opaque objects will be blended