Game Development Reference
In-Depth Information
Each of the above variables is a 4D color vector ( r, g, b, a ), and the
symbol denotes component-wise multiplication.
OutputPixel —The resulting blended pixel
SourcePixel —The pixel currently being computed that is to be
blended with the pixel on the back buffer
SourceBlendFactor —A value in the interval [0, 1] that specifies the
percent of the source pixel to use in the blend
DestPixel —The pixel currently on the back buffer
DestBlendFactor —A value in the interval [0, 1] that specifies the
percent of the destination pixel to use in the blend
The source and destination blend factors let us modify the original
source and destination pixels in a variety of ways, allowing for different
effects to be achieved. Section 7.2 covers the predefined values that can
be used.
Blending is disabled by default; you can enable it by setting the
D3DRS_ALPHABLENDENABLE render state to true:
Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
Tip: Blending is not a cheap operation and should only be enabled
for the geometry that needs it. When you are done rendering that
geometry, you should disable alpha blending. Also try to batch trian-
gles that use blending and render them at once so that you can avoid
turning blending on and off multiple times per frame.
7.2 Blend Factors
By setting different combinations of source and destination blend fac-
tors, you can create dozens of different blending effects. Experiment
with different combinations to see what they do. You can set the source
blend factor and the destination blend factor by setting the D3DRS_
SRCBLEND and D3DRS_DESTBLEND render states, respectively. For
example, we can write:
Device->SetRenderState(D3DRS_SRCBLEND, Source);
Device->SetRenderState(D3DRS_DESTBLEND, Destination);
where Source and Destination can be one of the following blend
factors:
D3DBLEND_ZERO blendFactor =(0, 0, 0, 0)
D3DBLEND_ONE blendFactor =(1, 1, 1, 1)
D3DBLEND_SRCCOLOR blendFactor =( r s , g s , b s , a s )
Search WWH ::




Custom Search