Correct blend mode for alpha multiplication?

Started by
2 comments, last by OrangyTang 20 years, 8 months ago
My knowledge of the blend modes is shaky at best, and i can't seem to figure out the correct mode to use for my lighting. I'm trying to use the alpha channel in the framebuffer as the light intensity, and then multiply all the geometry by the alpha in the framebuffer for each pass (one pass per light). So the equation should be something like: framebufferColour = (newPrimativeRGB * framebufferAlpha) + framebufferColour So first I have a circle in the middle of the screen, it is rendered as a triangle fan with the center colour of RGBA(0,0,0, 1) and the edges of (0,0,0,0). This should i think correctly load the framebuffer with the alpha values. (blending is disabled, as is depth testing for now). Then i render the geometry with blending enabled. I had thought i wanted glBlendFunc(DST_ALPHA, ONE_MINUS_DST_ALPHA); but that gives me odd results. Instead of altering the intensity across the geometry, it acts like a mask - anything not under the circle is not drawn, anything under it is drawn full intensity Edit: and yes i've checked my framebuffer creation - glGet returns 8 bits of framebuffer alpha avalible so thats not a problem. Anyone know how to set the correct blend equation up? Any help gratefully appreciated. [edited by - OrangyTang on August 6, 2003 3:24:21 PM]
Advertisement
You want :

FinalColor = SourceColor * DestinationAlpha + 1 * DestinationColor

So it should be DST_ALPHA for source op, and ONE for destination op...

(I don't really know if it's called "ONE" in OGL, but in DirectX that's how I would do it).

But I do it like this, usually:

FinalColor = 0 * SourceColor + SourceColor * DestinationColor...

That's ZERO, SRC_COLOR I think... It modulates source and destination.

EDIT: in my method, I draw all light intensities using (ONE, ONE) to the pixel color, and then draw the texture over them.

ToohrVyk



[edited by - ToohrVyk on August 6, 2003 3:33:22 PM]
Thanks for the quick reply The mode of DST_ALPHA and ONE sounds right, judging by what i''ve been reading on the web, but it still produces funny results

Where theres no circle/alpha poly, i still get no rendering - again its acting like a mask. Yet at the edges it still looks like its not being modulated by the alpha at all, it just draws it full bright. Near the center of the ''light'' it seems to be drawing properly (adding onto the existing framebuffer).

I''m getting a sneeky feeling that my light rendering is off, but don''t see where. I''ve tryed experimenting with the colour mask and such, but it still gives the same result. Whats the best way to load the alpha into the framebuffer in the first place? I can''t use your trick of using the colour buffer to store intensity, since this won''t work when i multipass (gotta compose the intensities for each light first which would nuke the others).
heh, golden rule of debuging: trust nothing.

Turns out i was using some old code to render the alpha circle - while it happily accepted my own Colour4f structure, the damn thing ignored the alpha since it was using glColor3f() :S I guess that would leave the alpha defaulting to 1f, which would explain things.

It works great now, many thanks!

This topic is closed to new replies.

Advertisement