lecture 12 blending, anti-aliasing, fog, display lists

20
Lecture 12 Blending, Anti-aliasing, Fog, Display Lists

Upload: kerrie-greene

Post on 31-Dec-2015

223 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists

Lecture 12

Blending, Anti-aliasing, Fog, Display Lists

Page 2: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists

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

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

Blending Coefficients Table

Page 5: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists

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

Anti-aliasing

Page 7: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists

SolutionUse Coverage values and Alpha

Page 8: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists

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

Anti-aliasing Polygons

Page 10: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists

Anti-aliasing Polygons

Page 11: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists

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

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

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

Using Fog

Page 15: Lecture 12 Blending, Anti-aliasing, Fog, Display Lists

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

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

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

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

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

END