grFogMode() and grAlphaBlendFunction() parameters
|
simple two pass blending
a·Fog(c1) + (1-a)·Fog(c2)
|
additive blending
Fog(Sci)
|
modulated blending
Fog(Pci)
|
1
|
mode
|
mode
|
mode
|
(mode | GR_FOG_ADD2)
|
|
rgbSrcFactor
|
GR_BLEND_ONE
|
GR_BLEND_ONE
|
GR_BLEND_ONE
|
|
rgbDstFactor
|
GR_BLEND_ZERO
|
GR_BLEND_ZERO
|
GR_BLEND_ZERO
|
2
|
mode
|
|
(mode | GR_FOG_ADD2)
|
GR_FOG_DISABLE
|
thru
|
rgbSrcFactor
|
n/a
|
GR_BLEND_ONE
|
GR_BLEND_DST_COLOR
|
n-1
|
rgbDstFactor
|
|
GR_BLEND_ONE
|
GR_BLEND_ZERO
|
n
|
mode
|
mode
|
(mode | GR_FOG_ADD2)
|
(mode | GR_FOG_MULT2)
|
|
rgbSrcFactor
|
GR_BLEND_SRC_ALPHA
|
GR_BLEND_ONE
|
GR_BLEND_ONE
|
|
rgbDstFactor
|
GR_BLEND_ONE_MINUS_SRC_ALPHA
|
GR_BLEND_ONE
|
GR_BLEND_PREFOG_COLOR
|
1Simple Blends
Simple two-pass blending using a and 1-a can be used to produce translucent fog and requires no special actions. The goal here is to produce
cdst = a·Fog(c2) + (1-a)·Fog(c1)
where ci is the color entering the fog unit from the color combine unit on pass i, Fog(ci) is the color output by the fog unit on pass i, and cdst is the color that is stored in the frame buffer. The first pass will generate and store Fog(c1). The second pass will generate Fog(c2) and blend it with the result of the first pass.
For the first pass, set the fog mode to GR_FOG_WITH_TABLE and the source and destination factors for alpha blending to GR_BLEND_ONE and GR_BLEND_ZERO, respectively, as shown in Table Special Effects.2 and demonstrated in Example Special Effects.4. After pass one is complete,
cdst = 1·Fog(c1) + 0·cdst
= Fog(c1)
For the second pass, specify the source and destination factors for alpha blending as GR_BLEND_SRC_ALPHA and GR_BLEND_ONE_MINUS_SRC_ALPHA, respectively. Thus,
cdst = a·cin + (1-a)·cdst
= a·Fog(c2) + (1-a)·Fog(c1)
Note that there is nothing special about using GR_BLEND_SRC_ALPHA and GR_BLEND_ONE_MINUS_SRC_ALPHA as the blending factors. Any of the blending factors listed in Table Using the Alpha Component.4 can be used.
Example Special Effects.4 Simple two-pass blending.
The code segment below assumes that a fog table has been defined. It loads the table, then sets a fog color. For the first pass, the fog mode is set to use the fog table and the alpha blending function to write fogged colors into the frame buffer. For the second pass, the fog mode and color remain the same, but the blending factors change blending the newly-generated fogged colors with the previous ones.
const GrFog_t fog[GR_TABLE_SIZE];
int i;
/* load the fog table */
grFogTable(fog);
/* set a fog color - how about smoke? */
grFogColorValue(0);
/* set mode to fog table */
grFogMode(GR_FOG_WITH_TABLE);
grAlphaBlendFunction(GR_BLEND_ONE, GR_BLEND_ZERO, GR_BLEND_ONE, GR_BLEND_ZERO);
/* draw the first pass */
…
/* reconfigure alpha blending for the second pass */
grAlphaBlendFunction(GR_BLEND_SRC_ALPHA, GR_BLEND_ONE_MINUS_SRC_ALPHA, GR_BLEND_ONE, GR_BLEND_ZERO);
/* draw the second pass */
…
Share with your friends: |