0

I am using openGL and programming on an iPhone.

I am rendering a glowing 'beam' on top of my game scene. I am using a few textures with additive blending to make the glow effect. If the beam is rendered on a pure black background, the beam will look exactly how I want it, however, when the beam is rendered on my ever changing game, it blends with the colors behind it.

Currently, this is my only idea:

1) Render the beam to a texture and draw the texture on the background using normal blending.

Problems - The texture will always be opaque (black is my glClear color). I do not yet know how to remove all of the black from the texture I rendered to.

Any suggestions?

genpfault
  • 51,148
  • 11
  • 85
  • 139
3rdFunkyBot
  • 396
  • 3
  • 8

1 Answers1

1

You could render to an texture with alpha channel and blend that. But this will again change your beam's appearance. Blending will always introduce some change in appearance, you can't get around this.

The blending formula is

Destination = Incoming * Incoming_Blend_Factor + Original * Original_Blend_Factor

If you want your colour to be the same this equates to

Destination = Incoming

which, by comparision of coefficients is

Destination = Incoming * 1 + Original * 0

I.e. by not blending at all.


As an exercise I give you the following: In Photoshop or GIMP but some background image into the background layer and your beam into a layer on top of it. Then try to get the result you desire by tinkering with the available blend modes.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Thank you for the response. What I did was render my glowing beam, using alpha blending to make it appear 'glowy', to a texture. I thought that I could then render that texture to my background using regular blending, but sadly, this isn't the case - the beam still blended to the background. My ultimate goal is to create a luminescent beam that I can draw anywhere without it blending with the background. Any ideas? – 3rdFunkyBot Jul 21 '11 at 01:35
  • Think about this: What if your background is a bright one (maybe a window with the sky visible through)? Especially a luminescent beam always requires blending. It it was some opaque thing then you could use alpha-testing, but that won't let the background shine through. Ultimately your problem is pixel saturation in the framebuffer. You could use HDR rendering, but this would that won't help you with the beam overexposing in the final composition stage. – datenwolf Jul 21 '11 at 07:32