100 likes | 404 Vues
CAP4730: Computational Structures in Computer Graphics. 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
E N D
CAP4730: Computational Structures in Computer Graphics 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 • How would we do transparent surfaces? • What are some types of transparent surfaces? • Windows • Saran Wrap • Plastic (like my cup) • Stained Glass • Water
Blend Let’s recall what happens per pixel
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?
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!
OpenGL • glColor4f(1,0,0,0.5); • You must have a framebuffer with alpha: • glutInitDisplayMode(GLUT_RGBA); • Assign colors at the vertices to be a certain alpha. • Other suggestions for combining colors: • Let’s write out the equation • A = 1, B = 1 • A = 1-AlphaSource , B = AlphaSource • A = AlphaSource , B = 1 • glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); • glBlendFunc(GL_ONE, GL_ZERO);
Decals/Other Blending Uses • Example from http://fly.srk.fer.hr/~unreal/theredbook/chapter07.html