Computer Graphics Blending Why do we want to
Computer Graphics Blending
Why do we want to blend? n n 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 Stained Glass Water
Blend Let’s recall what happens per pixel
We would like to combine the two colors Fragment or source - incoming color n Destination - existing color n How should we combine them? n We use the alpha channel to describe the combination of the source and destination. n Color. Final = A*Color. Source + B*Color. Destination n Most APIs let you specify A and B n
Combining Colors n n n Usually we take the source alpha as a “percentage” of the incoming fragment. Thus the equation becomes: Color. Final=Alpha. Source*Color. Source+(1 Alpha. Source)*Color. Destination 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!
Rendering Order Matters with Alpha! Transparent tri rendered last Transparent tri rendered first ( even before background quad)
Open. GL n n n n n gl. Color 4 f(1, 0, 0, 0. 5); You must have a framebuffer with alpha: – glut. Init. Display. Mode(GLUT_RGBA); gl. Enable(GL_BLEND); Other suggestions for combining colors: Let’s write out the equation A = 1, B = 1 A = 1 -Alpha. Source , B = Alpha. Source A = Alpha. Source , B = 1 gl. Blend. Func(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl. Blend. Func(GL_ONE, GL_ZERO); //default
- Slides: 7