Blending MAE152 Computer Graphics for Engineers and Scientists Fall 03.

Slides:



Advertisements
Similar presentations
Compositing and Blending Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
Advertisements

2IV60 Computer graphics set 8: Illumination Models and Surface-Rendering Methods Jack van Wijk TU/e.
Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
Hank Childs, University of Oregon Nov. 25th, 2014 CIS 441/541: Introduction to Computer Graphics Lecture 15: animation, transparency.
OpenGL Fragment Operations
Graphics Pipeline.
1 Buffers and Processing Fragments 2011 Autumn Animação e Visualização Tridimensional 2011/2012.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Computer Graphics I, Fall 2010 Shading II.
1. 2 Blending: tells you how to specify a blending function that combines color values from a source and a destination. The final effect is that parts.
Compositing and Blending Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Compositing and Blending - Chapter 8 modified by Ray Wisman Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
COMP Advanced Graphics Advanced Graphics - Part 6 The big picture: –Still working on advanced polygonal techniques with a special focus on OpenGL.
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.
Computer Graphics - Class 10
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
Chapter 6. More on Color and Material Presented by Garrett Yeh.
Raster Displays Images are composed of arrays of pixels displayed on a raster device. Two main ways to create images: –Scan and digitize an existing image.
1 Lecture 10 Lighting in OpenGL. 2 Sources of light GLfloat myLightPosition[] = {3.0, 6.0, 5.0, 1.0}; GLLightfv(GL_LIGHT0, GL_POSITION, myLightPosition);
7/2/2006Based on: Angel (4th Edition) & Akeine-Möller & Haines (2nd Edition)1 CSC345: Advanced Graphics & Virtual Environments Lecture 4: Visual Appearance.
Color in OpenGL (Chapter 4) Presented by: Stacy C. Lovell.
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
CS324e - Elements of Graphics and Visualization Compositing.
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Lecture 12 Blending, Anti-aliasing, Fog, Display Lists.
OpenGL Blending Akbar Ali
1 Chapter 6 Blending, Antialiasing, Fog, and Polygon Offset Guihua Yang Jan 14, 2004.
3D Graphics for Game Programming Chapter IV Fragment Processing and Output Merging.
DREAM PLAN IDEA IMPLEMENTATION Introduction to Computer Graphics Dr. Kourosh Kiani
Game Programming 06 The Rendering Engine
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS559: Computer Graphics Lecture 27: Texture Mapping Li Zhang Spring 2008 Many slides from Ravi Ramamoorthi, Columbia Univ, Greg Humphreys, UVA and Rosalee.
Particle Systems (Motion Machines of 2D Objects with Textures) Matthew K. Bowles Advanced Computer Graphics Spring 2004.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
Compositing and Blending
Computer Graphics Blending CO2409 Computer Graphics Week 14.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
Visual Appearance Chapter 4 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
UniS CS297 Graphics with Java and OpenGL Blending.
OpenGL Special Effects Jian-Liang Lin 2002 Blending: Alpha Channel Alpha value can be specify by glColor* When blending is enabled, the alpha value is.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
Chapter 4 -- Color1 Color Open GL Chapter 4. Chapter 4 -- Color2 n The goal of almost all OpenGL applications is to draw color pictures in a window on.
CDS 301 Fall, 2008 From Graphics to Visualization Chap. 2 Sep. 3, 2009 Jie Zhang Copyright ©
OpenGL Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
Computer Graphics Lecture 25 Fasih ur Rehman. Last Class Shading.
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.
CS559: Computer Graphics Lecture 24: Shape Modeling Li Zhang Spring 2010.
Chapter 6. Blending, Antialiasing, Fog, and Polygon Offset Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Draw a Simple Object.
Introduction to Computer Graphics with WebGL
The Graphic PipeLine
Visual Appearance Chapter 4
Rendering Geometric Primitives Reading: HB4, HB8-1 to HB8-6, HK9.7, 11
I = a I + ( ) 1 – a I BLENDING, ANTIALIASING, AND FOG l l 1 l 2 Earth
CSc4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Fog and Transparency.
Making the Applications Interesting
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
blending blending textures reflection fog
UMBC Graphics for Games
Blending CSCI 440 textbook section 7.10
Computer Graphics Practical Lesson 7
Chapter X Output Merger.
Computer Graphics Shading in OpenGL
blending blending textures reflection fog
Presentation transcript:

Blending MAE152 Computer Graphics for Engineers and Scientists Fall 03

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

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

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

Blend

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

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

Blending in OGL n 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 n The contributions of fragment and FB pixel is specified: glBlendFunc( src, dst )

We would like to combine the two colors n 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 What does A and B mean qualitatively?

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

Order Matters with Alpha!

Setting Alpha Values n 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 n 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);

Setting the Blend Function n 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 n The value of these blending factors and their computed blending factors is tabulated.

Setting the Blend Function Constant Value Relevant Factor Computed Blend Factor GL_ZERO Source or destination (0,0,0,0) GL_ONE (1,1,1,1) GL_DST_COLORSource(Rd,Gd,Bd,Ad) GL_SRC_COLORdestination(Rs,Gs,Bs,As) GL_ONE_MINUS_DST_COLORsource(1,1,1,1)-(Rd,Gd,Bd,Ad) GL_ONE_MINUS_SRC_COLORdestination(1,1,1,1)-(Rs,Gs,Bs,As) GL_SRC_ALPHA (As,As,As,As) GL_ONE_MINUS_SRC_ALPHA (1,1,1,1)-(As,As,As,As) GL_DST_ALPHA (Ad,Ad,Ad,Ad) GL_ONE_MINUS_DST_ALPHA (1,1,1,1)-(As,As,As,As) GL_SRC_ALPHA_SATURATESource (f,f,f,1): f-min(As,1-Ad)

OpenGL n glColor4f(1,0,0,0.5); n You must have a framebuffer with alpha: –glutInitDisplayMode(GLUT_RGBA); n Assign colors at the vertices to be a certain alpha. n Other suggestions for combining colors: n Let’s write out the equation n A = 1, B = 1 n A = 1-Alpha Source, B = Alpha Source n A = Alpha Source, B = 1 n glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); n glBlendFunc(GL_ONE, GL_ZERO);

Fragment n 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.

n Demo n Overlapping Triangles

Blending Function n Four choices: –GL_ONE –GL_ZERO –GL_SRC_ALPHA –GL_ONE_MINUS_SRC_ALPHA n Blending is enabled using glEnable(GL_BLEND) n Note: If your OpenGL implementation supports the GL_ARB_imaging extension, you can modify the blending equation as well.

3D Blending with Depth Buffer n 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?)

n Demo n 3-D blending with depth buffer