Alpha blending
Alpha blending
Hi all,
i am new to Irrlicht
And soon I got my first problem:
I want to make an isometric game.
I made two pictures, the one is grass and the other shall be a mask with a isometric shape:
And my goal is to lay the mask over the grass so that i get grass in isometric shape
So far so good, ... but how can I do it with Irrlicht?
I guess something like that has been often talked about in this forum,
but my keywords weren't good enough to find a solution =(
Thx for help!
David
i am new to Irrlicht
And soon I got my first problem:
I want to make an isometric game.
I made two pictures, the one is grass and the other shall be a mask with a isometric shape:
And my goal is to lay the mask over the grass so that i get grass in isometric shape
So far so good, ... but how can I do it with Irrlicht?
I guess something like that has been often talked about in this forum,
but my keywords weren't good enough to find a solution =(
Thx for help!
David
-
- Posts: 237
- Joined: Mon Jan 16, 2006 1:18 pm
- Location: Odessa,Russian Federation
One of the ways:
1.Make a texture with alpha channel, tga for example
2.Make a plane and use this texture as the map for desired polygon.
3.Set the MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL_REF
Voila! You got what you wanted
But this is stupid brute force , a fake 2D graphics ))
It is much wiser to set up the camera of the engine, to work as an orthographic one ))
So make any landscape you want, place it on the scene, and make ortho camera - you got what you need in a 3D fashion
1.Make a texture with alpha channel, tga for example
2.Make a plane and use this texture as the map for desired polygon.
3.Set the MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL_REF
Voila! You got what you wanted
But this is stupid brute force , a fake 2D graphics ))
It is much wiser to set up the camera of the engine, to work as an orthographic one ))
So make any landscape you want, place it on the scene, and make ortho camera - you got what you need in a 3D fashion
If you want to do it yourself you can access grass texture loaded in to Irrlicht via lock/unlock function and manually edit pixels alpha based on mask. Or use IImage interface for the same purpose.
Easier way is to load your texture with mask already.
Two ways:
Use tga as suggested since it supports alpha.
Or use makeColorKeyTexture() function from videodriver ...look at description for more info.
Easier way is to load your texture with mask already.
Two ways:
Use tga as suggested since it supports alpha.
Or use makeColorKeyTexture() function from videodriver ...look at description for more info.
-
- Posts: 368
- Joined: Tue Aug 21, 2007 1:43 am
- Location: The Middle of Nowhere
@Bear: Sounds reasonable!
@arras:
I tried this code:
But I get some kind of memory error there =/
@Dark_Kilauea:
I prefer to render it at the start of the application,
because otherwise I would need X*Y images (X=tile sorts, Y=masks)
And that would be really much after some time =)
Thx for your help!!
@arras:
I tried this code:
Code: Select all
void MaskImage(video::ITexture* image,video::ITexture* mask,core::rect<s32> type)
{
s32* ibuf = (s32*)image->lock();
s32* mbuf = (s32*)mask->lock();
for(int x = type.UpperLeftCorner.X;x<type.LowerRightCorner.X;x++)
{
for(int y = type.UpperLeftCorner.Y;y<type.LowerRightCorner.Y;y++)
{
*((u8*)ibuf+image->getPitch()*y+x*4+3)=255; //*((u8*)mbuf+mask->getPitch()*y+x*4+3);
}
}
image->unlock();
mask->unlock();
}
@Dark_Kilauea:
I prefer to render it at the start of the application,
because otherwise I would need X*Y images (X=tile sorts, Y=masks)
And that would be really much after some time =)
Thx for your help!!
You need a pixel shader that does-
Code: Select all
destination = (source1*mask) + (source2*(1-mask));
-
- Posts: 44
- Joined: Wed Dec 26, 2007 11:42 pm
Or you could do it with a multi-texture op.bitplane wrote:You need a pixel shader that does-Code: Select all
destination = (source1*mask) + (source2*(1-mask));
Ok guys,
I got a bit further with my problem:
I just wrote "x*2" instead of "x*4".
The result was a blue version of my grass
So x*2 would mean (because each single pixel is changed),
that my texture has a 8-bit format (4bit*2)
And it seems that
I cant change the alpha value.
So I guess that I have to change the format of the texture?!
And how to do that?!
Edit:
Ok, to change the bit format I have used
driver->setTextureCreationFlag(ETCF_ALWAYS_32_BIT,true);
But it seems that nothing has changed now?!
Well, I think that won't ever work, so new run:
Inspired by Bear_130278 i try this. But do I need now barely a plane or can I make SMaterial into ITexture* ??
I got a bit further with my problem:
I just wrote "x*2" instead of "x*4".
The result was a blue version of my grass
So x*2 would mean (because each single pixel is changed),
that my texture has a 8-bit format (4bit*2)
And it seems that
I cant change the alpha value.
So I guess that I have to change the format of the texture?!
And how to do that?!
Edit:
Ok, to change the bit format I have used
driver->setTextureCreationFlag(ETCF_ALWAYS_32_BIT,true);
But it seems that nothing has changed now?!
Well, I think that won't ever work, so new run:
Code: Select all
void MaskImage(video::ITexture* image,video::ITexture* mask,core::rect<s32> type)
{
SMaterial* mymat = new SMaterial;
mymat->setTexture(1,image);
mymat->setTexture(2,mask);
mymat->MaterialType = EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
// ....
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
Be careful with 'new', this one looks incorrect at this place...
Anyway, there's no way to p a material into a texture, it's the other way round. Still, you cannot use a material to do 2d rendering, because the 2d methods have their own set of parameters. You have to use those, there's no other way. And 2d just uses 1 texture, so no way to use an alpha mask texture. Anyway, Irrlicht doesn't support alpha maps at all.
Ok, final point, try to check the texture format before writing into arbitrary memory positions.
Anyway, there's no way to p a material into a texture, it's the other way round. Still, you cannot use a material to do 2d rendering, because the 2d methods have their own set of parameters. You have to use those, there's no other way. And 2d just uses 1 texture, so no way to use an alpha mask texture. Anyway, Irrlicht doesn't support alpha maps at all.
Ok, final point, try to check the texture format before writing into arbitrary memory positions.
What do we use for transparent textures then? PNGs, TGAs with alpha channel (which after this I assume is a no), or something else?hybrid wrote:Be careful with 'new', this one looks incorrect at this place...
Anyway, there's no way to p a material into a texture, it's the other way round. Still, you cannot use a material to do 2d rendering, because the 2d methods have their own set of parameters. You have to use those, there's no other way. And 2d just uses 1 texture, so no way to use an alpha mask texture. Anyway, Irrlicht doesn't support alpha maps at all.
Ok, final point, try to check the texture format before writing into arbitrary memory positions.