lecture 12 blending, anti-aliasing, fog, display lists
TRANSCRIPT
![Page 1: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/1.jpg)
Lecture 12
Blending, Anti-aliasing, Fog, Display Lists
![Page 2: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/2.jpg)
Blending
• Alpha value: It’s been ignored so far.• We use alpha value for blending.• Fragments: After the rasterization stage (including
texturing and fog), the data are not yet pixels. At this stage, they are called fragments.(These are called source)
• Pixels: Then each fragment undergoes a series of tests and operations after which, it is called a pixel.(These are called destination)
• Blending: Specifies a blending function that combines color values from a source and a destination
![Page 3: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/3.jpg)
Blending Function
• Blending Function: Specifies how source and destination are blended together.
• Final result of combination for each pixel is calculated from the following formula:
(Rs.Sr+Rd.Dr, Gs.Sg+Gd.Dg, Bs.Sb+Bd.Db, As.Sa+Ad.Da)
• glBlendFunc(Glenum sfactor, Glenum dfactor)
![Page 4: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/4.jpg)
Blending Coefficients Table
![Page 5: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/5.jpg)
Samples of Blending
• Draw two images blending together equally:– Source: GL_SRC_ALPHA– Destination: GL_ONE_MINUS_SRC_ALPHA– Draw the source with alpha=0.5
• Draw three images blending together equally:– Set the destination factor to GL_ONE – Set the source factor to GL_SRC_ALPHA– Draw each of the images with an alpha equal to 0.3333333
• Need more? Refer to the RedBook, Chapter 6, “Sample Uses of Blending”
![Page 6: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/6.jpg)
Anti-aliasing
![Page 7: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/7.jpg)
SolutionUse Coverage values and Alpha
![Page 8: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/8.jpg)
Enabling Anti-alias
• glEnable(GL_POINT_SMOOTH)• glEnable(GL_LINE_SMOOTH)• You may want to optimize anti-aliasing:– Use glHint() along with the parameters.– Use blending when two lines cross each other– Use GL_SRC_ALPHA (source) and
GL_ONE_MINUS_SRC_ALPHA (destination). – You can use GL_ONE for the destination factor to make
lines a little brighter where they intersect
![Page 9: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/9.jpg)
Anti-aliasing Polygons
![Page 10: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/10.jpg)
Anti-aliasing Polygons
![Page 11: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/11.jpg)
Anti-aliasing Polygons
• Use glEnable(GL_POLYGON_SMOOTH ): This will cause pixels on the edges of the polygon to be assigned fractional alpha values based on their coverage.
• Turn off the depth buffer• set the blending factors to
GL_SRC_ALPHA_SATURATE (source) and GL_ONE (destination)
• Sort all the polygons in your scene so that they're ordered from front to back before drawing them
![Page 12: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/12.jpg)
Fog
• Makes objects fade into the distance.• Fog is a general term that describes forms of
atmospheric effects.• Fog can be used to simulate haze, mist,
smoke, or pollution.
![Page 13: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/13.jpg)
Using Fog
• glEnable(GL_FOG)• Use Fog equation• Use Fog color• glFog{if}(GLenum pname, TYPE param)
![Page 14: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/14.jpg)
Using Fog
![Page 15: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/15.jpg)
Display Lists
• Advantages of using Display Lists: – Store OpenGL commands for later execution– Using display lists, you can define the geometry
and/or state changes once and execute them multiple times.
– Saves lots of resources when an OpenGL program is running over a network.(Saves lots of back and forth communications)
![Page 16: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/16.jpg)
Using Display Lists
• Use glGenLists(size) to create names.• Use glNewList(name,
GL_COMPILE/GL_EXECUTE/GL_COMPILE_ANDEXECUTE), glEndList() to define a list
• Use glCallList(list_name) to recall a list.
![Page 17: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/17.jpg)
Limitations
• Only the values for expressions are stored in the list Not the expressions.
• Example: GLfloat color_vector[3] = {0.0, 0.0, 0.0};
glNewList(1, GL_COMPILE); glColor3fv(color_vector); glEndList(); color_vector[0] = 1.0;
• The color is not changed in the list after the last line is executed.
![Page 18: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/18.jpg)
Limitations
• The following commands are not stored in a display list:
• Commands that set client state.• Commands that retrieve state values aren't
stored in a display list.
![Page 19: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/19.jpg)
Hierarchical Display Lists
• A hierarchical display list is allowed in OpenGL, which is a display list that executes another display list.
• Example: glNewList(listIndex,GL_COMPILE);
glCallList(handlebars); glCallList(frame); glTranslatef(1.0,0.0,0.0); glCallList(wheel); glTranslatef(3.0,0.0,0.0); glCallList(wheel); glEndList();
![Page 20: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022082414/56649eb05503460f94bb5d8d/html5/thumbnails/20.jpg)
END