views:

106

answers:

3

Hi,

I'm a complete beginner with openGL, and I'm trying to see if what I want to do is feasible before I get started. I'd like to know if it's possible to perform blending with one alpha channel per component (one for red, one for green and one for blue) with openGL? If not, what are some possible workarounds?

Thanks!

+1  A: 

This isn't something that's directly supported. It's fairly easy to achieve on your own though:

  • Render your triangle (or whatever) using the 3-channel "alpha" texture and glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR)
  • Enable multitexture and set the "alpha" texture to modulate your rgb texture
  • Render your triangle with glBlendFunc(GL_ONE, GL_ONE)
Andreas Brinck
hum, that does not work with any overdraw, I think ? It's the usual problem with multi-pass algorithms...
Bahbar
@Bahbar Ordinary alpha blend doesn't work with any overdraw either. You'll have to sort the fragments on depth to get the correct result.
Andreas Brinck
right, you do have to sort with single pass. Your solution still works if you do the multi-pass at the same sorting granularity, though. I had not realized it at first.
Bahbar
Thanks a lot! That's very helpful.
static_rtti
A: 

What you're describing is not possible with OpenGL.

That said, considering that you're new to OpenGL, maybe what you're describing is not exactly what you're after ?

Blending is the step that happens once you decided what color your current fragment (usually coming from a triangle) is supposed to have. That color needs to be merged with the previous color in the frame-buffer. Are you sure that's what you're after ?

Bahbar
There are perfectly valid reasons to want to do this, in the real world most objects doesn't have equal transparency over the full color spectrum (consider a stained glass window).
Andreas Brinck
@Andreas Brinck: Yes, there are. But the OP clearly states he's completely new to OpenGL. Maybe he's not aware of exactly what blending means (I've seen it confused with fragment color computation many times before).
Bahbar
+1  A: 

You could do this with a pixel shader, but you'd need to find a way to store/access per component alpha values. You could store them in a texture and treat the normal color components as the alpha values for the corresponding color.

What effect/output are you trying to achieve?

basszero