ALPHA blending.

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

ALPHA blending.

Post by agamemnus »

I would like to use the following function to blend, but I don't understand the parameters of pack_texureBlendFunc()...

b_r = blend func r value
s_r = source r value
d_r = dst r value

b_r = d_r*(1-s_a) + s_a*s_r
b_g = d_g*(1-s_a) + s_a*s_g
b_b = d_b*(1-s_a) + s_a*s_b
b_a = d_a + s_a

if b_r > 255 b_r = 255, and the same for the rest...

Basically, just a regular texture blend on alpha. (hopefully I got the above formulas right.) I can't think of any combination in which the source, if its alpha is lower, does not overwrite the higher-alpha destination (b_a = d_a + s_a)

What are the equivalent parameters for texureBlendFunc()? (or, how could I do this some other way?) =)

PS: why isn't it called textureBlendFunc? :wink:
Last edited by agamemnus on Thu Jun 24, 2010 1:45 pm, edited 1 time in total.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Beep. I changed the thread title..
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Ok, it looks like what I need is d_material.MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL;

Is this correct?
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I'm not sure if that mode will handle the alpha value as stated, but for the color blending it's the correct one, yes.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Edit: false alarm.

Still does not handle alpha correctly.

Any ideas?
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

That is the same thing I was talking about in this other thread. There were several suggestions on how to fix it, but I haven't had time to try them out. I tried several blending modes with OpenGL and DirectX in Irrlicht's source, but it seems it isn't possible to get the alpha and colors blended with separate methods other than a shader (one of the suggestions in the topic.)

Good luck!

~David
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Hmm, well.... manual pre-multiplied alpha seems slow, and the hardware version seems complicated.
although it would be nice if there was a better way to do it >.<
I heard you can do it in Ogre very easily.. does this not sound like something that should come with Irrlicht pre-made? (eg: I am begging for a pre-made function) :D
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

Hmm, if you are sure that it is possible to do in Ogre, it might be worth looking at their source to see how they did it. I wouldn't be surprised if it is a shader, however.

EDIT: If you know the method of doing it in Ogre, post it here and someone else or I can dig into the Ogre source.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

From what I understand from a bit of code here, Ogre has it built into "._setTextureBlendMode".. one of 4 values for the color blend mode, and one of 4 values for the alpha blend mode.
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

agamemnus wrote:Ok, it looks like what I need is d_material.MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL;

Is this correct?
Actually, it's not. At least not if you want to use the packed texture blend mode. For that you have to use EMT_ONE_TEXTURE_BLEND
We do indeed not support all combinations of the underlying gfx API. Simply because you cannot make them available in a simple manner. And instead of just placing them im the SMaterial, we use additional materials instead. Writing your own material is a matter of a few lines additional code. Just copy the two best matching versions for OpenGL and DirectX and adapt to your needs.
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

hybrid wrote:
agamemnus wrote:Ok, it looks like what I need is d_material.MaterialType = irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL;

Is this correct?
Actually, it's not. At least not if you want to use the packed texture blend mode. For that you have to use EMT_ONE_TEXTURE_BLEND
We do indeed not support all combinations of the underlying gfx API. Simply because you cannot make them available in a simple manner. And instead of just placing them im the SMaterial, we use additional materials instead. Writing your own material is a matter of a few lines additional code. Just copy the two best matching versions for OpenGL and DirectX and adapt to your needs.
A similar argument is given as a reason for not implementing a custom material in CEGUI: "it's not our job to do it (it's the graphic engine's job), so we won't do it!"

Anyway... can you please tell me how I could do this, then, in DirectX?
agamemnus
Posts: 283
Joined: Sun Jan 31, 2010 6:06 pm

Post by agamemnus »

Any new info on this? Perhaps someone can help with the "few lines of additional code", because I have no idea what to do.
Post Reply