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!
I know I can set the transparency of a mesh with the types EMT_TRANSPARENT_VERTEX_ALPHA or EMT_TRANSPARENT_ADD_COLOR. But I like to set the alpha value userdefined (for example to 200 or 50). So I wrote that function for that:
Additionally I set m_pDriver ->setTextureCreationFlag(irr::video::ETCF_ALWAYS_32_BIT, true); and the materialtype to EMT_TRANSPARENT_ALPHA_CHANNEL. I know that the API says that this type is not implemented but one guy in the bug forum says that the type is fine except of one little bug. So I set this to things to make sure to get the texture with 32bit and the Material works with the texture and its alphachannel.
I tried my function and it seems as it sets the alphabits right but nothing seems to happen to the mesh. Any ideas??
Thank you in advance
EMT_TRANSPARENT_ALPHA_CHANNEL is implemented in DX8/9 but not OpenGL.
Maybe (as a test) create a texture with alpha channel (TGA 32 bit) and see if it works. This might help determining if the problem is in your function or in rendering the mesh.
I created a tga 32 bit . And still the mesh seems solid. But when I go throw the debug mode it seems as it sets the alpha value to the value I want. It seems as the result is not displayed though.
I work with these i. because I have a struct where I "save" my attributes.
The other modes seem to work. The EMT_Transparent_ADD_COLOR for example sets the dark colors to transparent and the bright colors get a little bit transparent. They seem to get white but still transparent... But as I guess it works alright.
joy wrote:
I created a tga 32 bit . And still the mesh seems solid.
Did the tga that you created really have some greyscale alpha channel that would make certain areas transparent in your mesh? For example like the texture I used here:
You are so right, although it seems as he does the right thing in the debug modus there is no differences when I change the R as I tried it with the alpha value. Mmmh, So I do something wrong... What the heck is it?
And I always was wondering how you created the two pictures of the shadow. I am not able to have the alpha channel as a different layer. How did you do that?
Maybe take a look at CVideoNull::makeColorKeyTexture(). This function is modifying the alpha channel of a texture.
I created the texture in Photoshop (6.0). First I create a regular image. Then in the Channels tab (Kanäle) (next to Layers (Ebenen)) I create a new channel (with the create button at the bottom nect to the trash bin) which is called "Alpha 1" by default. There I define the greyscale alpha info (white=solid to black = transparent). If I save it as TGA in 32 bit (important) then the alpha channel is included and also recognized by irrlicht.
But I tried to create a tga as you described it, and in Photoshop it looks quite good, but in Irrlicht it does not have the transparency I created in Photoshop. Anything else I need to consider?
Thank you very much for your answers. As you see it helps even though I don't know how
Oh I see...
Where did you explicit difine that black is transparent and white is solid? By just putting black and white over the image it is not done yet , is it?
Ok next problem with that. Now I know why it didn't work before. If I use a tga 32bit which is solid from the beginning, my function works fine. But if I use this function on a tga 32bit with already transparent parts in it (I just have a transparent working space in Photoshop and erase some parts of the texture, so that it is transparent at certain spots), the function doesn't work at all. I couldn't set the transparency like you did, jox, so I couldn't try it with these textures.
So anyone has a guess why it won't work if there are some transparent parts in the texture already?
in gfx, my field, I'd say...a tga can't save transparency, only alpha channel. A png does save transparency.
If you are seing the parts of image transparent in adobe before saving...does not mean it's gonna be saved in tga. reopen the tga in adobe and surely u'll see the supposedly now transparent parts as solid white.
PNG does allow it. In java is widely used as is supported. Ppl there just delete a part, and as it's seen in adobe will be seen in java code.
But for tga, the proccess in adobe (traslate the knowledge to Gimp is just the same concept) is save th eselection , selecting previously the part u want transparent, so it becomes a new channel.
U can modify it painting in quick mask mode, or modify with selection tools (lasso , etc) and save it again with same name -the selection(channel, really)-
ok, in adobe, several different ways to create a TGA 32 bits with alpha channel :
a) as I explained, just doing a lasso, marquee, circle, whatever selection (you can create in quick mask mode, but is more complex to explain) and go to selection top menu, save selection. That'd be then a saved selection u can recover, but also becomes and alpha channel.
or
b) top menu Window. Channels (in window menu you set the windows/pallettes u wanna see in adobe) . So u now see the channels pallete/dialog. There u press the tiny top left triangle and choose "new channel".Or click on the tiny "new" icon in the bottom of the channels window. Now u see a black screen. Now if u paint with white, white is what would be "protected" I think. Black is transparent in the future tga. Greys are for partially transparent stuff. If u for example do a circle selection here (do not save selection with this method; ur actually working directly on the channel), fill it with white, and apply a big feather, u'll see a feathered circle, useful fo rexample for glows sprites ingame.
To see the channel content as ur doing, two ways: when u creat a new channel, u see that u're put automatically in that alpha channel editing. but in case u reopen this file again, u'll be as u start, in rgb channels model, seeing only the standard texture, not the alpha channel.Then , way to switch to channels mode is, in channels window/pallete, click on the chanel icon/name that u know is ur alpha chanel("alphal 1", usually). Ok? capici?
At time to save, as always, 32 bits with alpha channel.
I told you that the function I wrote is working? Ok it is not. I thought it would but I didn't test it so I always saw just one side of the mesh and that looked transparent. But all other sides of the mesh were not transparent at all!!!
The red one is my object, the grey around it is my background.
the second picture is my object when I set alpha = 100 and the last picture is rotated. You can see all other sides of the mesh is not transparent but the front looks like it would be transparent.