Looking for a specific 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
VeeZed
Posts: 14
Joined: Wed Oct 27, 2010 8:04 pm
Location: Novosibirsk, Russia

Looking for a specific Alpha blending

Post by VeeZed »

Hello everyone,

It looks like I'm a bit stuck with the material types/alpha blending. So I would really appreciate if anyone can help me a bit.

First of all, let me describe what I'm trying to achieve. I have some RGBA texture, which alpha values are mostly 0.0 or 1.0 (and some areas in between). Therefore, I would like to use AlphaFunc (or Alpha test) to eliminate "mostly-transparent" pixels from the output to save z-buffer. This is perfectly done by EMT_TRANSPARENT_ALPHA_CHANNEL_REF.

Additionally, I need to be able to "fade out" the object when needed. I thought that I would be able to use per-vertex alpha values (or material alpha values), that would be combined with the texture alpha values. However, it seems that I checked all possible E_MATERIAL_TYPE options, and there is no appropriate type that will let me COMBINE (D3D) or MODULATE (OpenGL) the vertex alpha value with the texture alpha value. It looks like any E_MATERIAL_TYPE will either stick to texture alpha, or vertex alpha.

Could anyone indicate what I missed? Thanks in advance!

PS: I already see that I can implement custom IMaterialRenderer (and get to the "actual" driver from there), but I'm really hope that I there is no need to re-invent the wheel.
VeeZed
Posts: 14
Joined: Wed Oct 27, 2010 8:04 pm
Location: Novosibirsk, Russia

Post by VeeZed »

OK. Looks like I solved this using a generic Material plus one small "low-level Hack" (grr... :( ).

---------------

The DIRTY solution is the following:

1. Use EMT_ONETEXTURE_BLEND as a base Material.

2. Use pack_texureBlendFunc function to setup Material. Use (ONE, ONE_MINUS_SRC_ALPHA) blending, and (EAS_VERTEX_COLOR | EAS_TEXTURE) option to mix the alpha from both vertex and texture.

[By the way, there is no good description of this function and no indications within EMT_ONETEXTURE_BLEND description how to use it. Actually, I missed this in the documentation and found only when I started a piece-by-piece review of the inner engine logic (CD3D9MaterialRenderer.h)]

3. Unfortunately, it seems that this method turns off the AlphaTest. Luckily, I have a vertex shader to be used for this Material, so I can put my small *hack* within OnSetConstants() of my IShaderConstantSetCallBack class. All I need to do is call getExposedVideoData and then activate AlphaTest. This leads to the nasty dependency from the "low-level driver" (<d3d9.h> in my case), but I just don't see any other options right now.

---------------

One may ask - why do you need such complex approach? Honestly, the "vertex alpha" in my case is adjusted in vertex shader, so I can have static VBO (efficiency), but don't use pixel shader for the small auxiliary FX (again, efficiency).

---------------

Actually, I think that it would be nice to be able to control the AlphaTest within the "packed" settings of EMT_ONETEXTURE_BLEND. Of course, this isn't a widely-used case, but it can be helpful sometimes. Can anyone tell me where the "wish-list" for the irrLicht engine development is located? :)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, you're right. Alpha test cannot be configured so far. The wish list(s) can be found inthe Open Discussion forum.
Post Reply