Post on 01-Jan-2021
Computer Graphics
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Blending, Antialiasing, and Fog
December 12, 2005
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Objectives
Blendingcombining color values from a source and a destination
Antialiasingaltering colors so that edges of lines and polygons appear smooth
Fogcreating the illusion of depth by computing the color values of an object based on distance from the viewpoint
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Blending (1)
Transparency : alpha – RGBA color
source – polygon color, destination – background
GL_ZERO, GL_ONE,
GL_DST_COLOR, GL_SRC_COLOR, GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR,
GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA_SATURATE
glEnable(GL_BLEND);glBlendFunc(GLenum source, GLenum destination);
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Blending (2)
Example
source (Rs, Gs, Bs, As), destination (Rc, Bc, Gc, 1)
R: AsRs + (1-As) Rc
G: AsGs + (1-As) Gc
B: AsBs + (1-As) Bc
A: AsAs + (1-As) Ac
Using the depth buffer to keep track of whether a polygon is in front of all polygons
GL_FALSE – read only, GL_TRUE - writeable
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_ALPHA);
glDepthMask(GLboolean flag);
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Display ( ) (1)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Display ( ) (2)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Result – Blending
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Antialiasing
In OpenGL, calculating a coverage value for each fragment
RGBA mode : multiplying the fragment’s alpha value by its coverage
color-index mode : setting the least significant 4 bits of the color index (0000 ~ 1111)
Controlling the trade-off between image and speed
target – behavior to be controlled
hint – GL_FASTEST, GL_INCEST, GL_DONT_CARE
glHint(GLenum target, GLenum hint);
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Display ( ) (1)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Display ( ) (2)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Result – Antialiasing
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Fog
Fog equationsGL_LINEAR
GL_EXP
GL_EXP2
Specifying the variables
pname – GL_FOR_MODE, GL_FOG_DENSITY, GL_FOG_START, GL_FOG_END
glFog{if}{v}(GLenum pname, TYPE param);
startend
zendf
−−
=
( )( )zdensity
zdensitye
ef −−
− ==1
( )( )2
2
1 zdensity
zdensitye
ef −−
−==
z: distance from the viewpoint
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Global Variables
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Display ( ) – Fog (GL_EXP)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Result – Fog (GL_EXP)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Display ( ) – Fog (GL_EXP2)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Result – Fog (GL_EXP2)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Display ( ) – Fog (GL_LINEAR)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2005/cga
Result – Fog (GL_LINEAR)