• No results found

Blending

In document glspec31.20090324.pdf (Page 187-192)

3.11 Multisample Point Fade

4.1.7 Blending

Blending combines the incomingsource fragment’s R, G, B, and A values with thedestinationR, G, B, and A values stored in the framebuffer at the fragment’s

(xw, yw)location.

Source and destination values are combined according to theblend equation, quadruplets of source and destination weighting factors determined by theblend functions, and a constantblend colorto obtain a new set of R, G, B, and A values, as described below.

If the color buffer is fixed-point, the components of the source and destination values and blend factors are clamped to[0,1]prior to evaluating the blend equation. If the color buffer is floating-point, no clamping occurs. The resulting four values are sent to the next operation.

Blending applies only if the color buffer has a fixed-point or floating-point format. If the color buffer has an integer format, proceed to the next operation.

4.1. PER-FRAGMENT OPERATIONS 175

Blending is enabled or disabled for an individual draw buffer with the com- mands

void Enablei(enumtarget, uintindex); void Disablei(enumtarget, uintindex);

target is the symbolic constant BLEND and index is an integer i specifying the draw buffer associated with the symbolic constant DRAW BUFFERi. If the color buffer associated withDRAW BUFFERi is one of FRONT, BACK, LEFT,RIGHT, or

FRONT AND BACK(specifying multiple color buffers), then the state enabled or dis- abled is applicable for all of the buffers. Blending can be enabled or disabled for all draw buffers using Enable orDisable with the symbolic constant BLEND. If blending is disabled for a particular draw buffer, or if logical operation on color values is enabled (section4.1.10), proceed to the next operation.

An INVALID VALUE error is generated if index is greater than the value of

MAX DRAW BUFFERSminus one.

If multiple fragment colors are being written to multiple buffers (see sec- tion4.2.1), blending is computed and applied separately for each fragment color and the corresponding buffer.

Blend Equation

Blending is controlled by theblend equations, defined by the commands

void BlendEquation(enummode);

void BlendEquationSeparate(enummodeRGB, enummodeAlpha);

BlendEquationSeparate argument modeRGB determines the RGB blend func- tion while modeAlpha determines the alpha blend equation. BlendEqua- tion argument mode determines both the RGB and alpha blend equations.

modeRGB and modeAlpha must each be one of FUNC ADD, FUNC SUBTRACT,

FUNC REVERSE SUBTRACT,MIN, orMAX.

Signed or unsigned normalized fixed-point destination (framebuffer) compo- nents are represented as described in section 2.1.5. Constant color compo- nents, floating-point destination components, and source (fragment) components are taken to be floating point values. If source components are represented in- ternally by the GL as fixed-point values, they are also interpreted according to section2.1.5.

Prior to blending, signed and unsigned normalized fixed-point color compo- nents undergo an implied conversion to floating-point using equations2.1and2.3,

4.1. PER-FRAGMENT OPERATIONS 176

respectively. This conversion must leave the values 0 and 1 invariant. Blending computations are treated as if carried out in floating-point.

If FRAMEBUFFER SRGB is enabled and the

value of FRAMEBUFFER ATTACHMENT COLOR ENCODING for the framebuffer at- tachment corresponding to the destination buffer isSRGB(see section 6.1.3), the R, G, and B destination color values (after conversion from fixed-point to floating- point) are considered to be encoded for the sRGB color space and hence must be linearized prior to their use in blending. Each R, G, and B component is converted in the same fashion described for sRGB texture components in section3.8.15.

If FRAMEBUFFER SRGB is disabled or the value

ofFRAMEBUFFER ATTACHMENT COLOR ENCODINGis not SRGB, no linearization is performed.

The resulting linearized R, G, and B and unmodified A values are recombined as the destination color used in blending computations.

Table4.1provides the corresponding per-component blend equations for each mode, whether acting on RGB components formodeRGBor the alpha component formodeAlpha.

In the table, the ssubscript on a color component abbreviation (R, G, B, or A) refers to the source color component for an incoming fragment, thedsubscript on a color component abbreviation refers to the destination color component at the corresponding framebuffer location, and thecsubscript on a color component abbreviation refers to the constant blend color component. A color component ab- breviation without a subscript refers to the new color component resulting from blending. Additionally,Sr,Sg,Sb, andSaare the red, green, blue, and alpha com-

ponents of the source weighting factors determined by the source blend function, andDr, Dg, Db, and Da are the red, green, blue, and alpha components of the

destination weighting factors determined by the destination blend function. Blend functions are described below.

Blend Functions

The weighting factors used by the blend equation are determined by the blend functions. Blend functions are specified with the commands

void BlendFuncSeparate(enumsrcRGB, enumdstRGB, enumsrcAlpha, enumdstAlpha);

void BlendFunc(enumsrc, enumdst);

BlendFuncSeparateargumentssrcRGBanddstRGBdetermine the source and destination RGB blend functions, respectively, whilesrcAlphaanddstAlphadeter- mine the source and destination alpha blend functions. BlendFunc argumentsrc

4.1. PER-FRAGMENT OPERATIONS 177

Mode RGB Components Alpha Component

FUNC ADD R=Rs∗Sr+Rd∗Dr A=As∗Sa+Ad∗Da G=Gs∗Sg+Gd∗Dg B =Bs∗Sb+Bd∗Db FUNC SUBTRACT R=Rs∗Sr−Rd∗Dr A=As∗Sa−Ad∗Da G=Gs∗Sg−Gd∗Dg B =Bs∗Sb−Bd∗Db

FUNC REVERSE SUBTRACT R=Rd∗Dr−Rs∗Sr A=Ad∗Da−As∗Sa

G=Gd∗Dg−Gs∗Sg

B =Bd∗Db−Bs∗Sb

MIN R= min(Rs, Rd) A= min(As, Ad)

G= min(Gs, Gd)

B = min(Bs, Bd)

MAX R= max(Rs, Rd) A= max(As, Ad)

G= max(Gs, Gd)

B = max(Bs, Bd)

Table 4.1: RGB and alpha blend equations.

determines both RGB and alpha source functions, whiledstdetermines both RGB and alpha destination functions.

The possible source and destination blend functions and their corresponding computed blend factors are summarized in table4.2.

Blend Color

The constant colorCcto be used in blending is specified with the command

void BlendColor(clampfred, clampfgreen, clampfblue,

clampfalpha);

The constant color can be used in both the source and destination blending functions

The state required for blending is two integers for the RGB and alpha blend equations, four integers indicating the source and destination RGB and alpha blending functions, four floating-point values to store the RGBA constant blend color, and a bit indicating whether blending is enabled or disabled for each of the

MAX DRAW BUFFERSdraw buffers.

The initial blend equations for RGB and alpha are bothFUNC ADD. The initial blending functions are ONE for the source RGB and alpha functions and ZERO

4.1. PER-FRAGMENT OPERATIONS 178

Function RGB Blend Factors Alpha Blend Factor

(Sr, Sg, Sb)or(Dr, Dg, Db) SaorDa

ZERO (0,0,0) 0

ONE (1,1,1) 1

SRC COLOR (Rs, Gs, Bs) As

ONE MINUS SRC COLOR (1,1,1)−(Rs, Gs, Bs) 1−As

DST COLOR (Rd, Gd, Bd) Ad

ONE MINUS DST COLOR (1,1,1)−(Rd, Gd, Bd) 1−Ad

SRC ALPHA (As, As, As) As

ONE MINUS SRC ALPHA (1,1,1)−(As, As, As) 1−As

DST ALPHA (Ad, Ad, Ad) Ad

ONE MINUS DST ALPHA (1,1,1)−(Ad, Ad, Ad) 1−Ad

CONSTANT COLOR (Rc, Gc, Bc) Ac

ONE MINUS CONSTANT COLOR (1,1,1)−(Rc, Gc, Bc) 1−Ac

CONSTANT ALPHA (Ac, Ac, Ac) Ac

ONE MINUS CONSTANT ALPHA (1,1,1)−(Ac, Ac, Ac) 1−Ac

SRC ALPHA SATURATE1 (f, f, f)2 1

Table 4.2: RGB and ALPHA source and destination blending functions and the corresponding blend factors. Addition and subtraction of triplets is performed component-wise.

1 SRC ALPHA SATURATEis valid only for source RGB and alpha blending func-

tions.

2f = min(A

4.1. PER-FRAGMENT OPERATIONS 179

for the destination RGB and alpha functions. The initial constant blend color is

(R,G,B,A) = (0,0,0,0). Initially, blending is disabled for all draw buffers. The value of the blend enable for draw bufferican be queried by callingIsEn- abledi with target BLEND and index i. The value of the blend enable for draw buffer zero may also be queried by callingIsEnabledwithvalueBLEND.

Blending occurs once for each color buffer currently enabled for blending and for writing (section4.2.1) using each buffer’s color forCd. If a color buffer has no

A value, thenAdis taken to be1.

In document glspec31.20090324.pdf (Page 187-192)