Solid color and alpha questions
Solid color and alpha questions
I have three quick questions I can't find the answers to anywhere in the Irrlicht documentation or here on the forums:
1. Is there a simple way to assign a solid color as the texture of an ISceneNode?
2. I have a texture with a gradual alpha; it is a circle that is solid at the edge, and fades to transparent in the middle. When I use it in Irrlicht, however, it is solid up to the point where the alpha<128, at which point it goes totally transparent. Is there any way to keep the gradual alpha change in Irrlicht?
3. Is there any way to adjust the overall alpha for a texture, for instance if I want a scene node to slowly fade out to total transparency?
Thanks in advance for the help!
1. Is there a simple way to assign a solid color as the texture of an ISceneNode?
2. I have a texture with a gradual alpha; it is a circle that is solid at the edge, and fades to transparent in the middle. When I use it in Irrlicht, however, it is solid up to the point where the alpha<128, at which point it goes totally transparent. Is there any way to keep the gradual alpha change in Irrlicht?
3. Is there any way to adjust the overall alpha for a texture, for instance if I want a scene node to slowly fade out to total transparency?
Thanks in advance for the help!
Adjusting that would only change how much of the texture is completely transparent or completely solid. It doesn't have anything to do with the "gradual transparency" effect that I'm after. Thanks for trying.vitek wrote:Hava a look at SMaterial::MaterialTypeParam.
At this point it looks like I'll probably need to switch to a different 3D engine, like Ogre3D, especially since I'm handling all of the gameplay code myself and not using any of Irrlicht's gameplay functions.
Oh well.
Well, I figured out #1 and #3: They can both be done with an IMeshManipulator, as in the following code snippet:
the API says NOT to use this to make adjustments in your main program loop, and that it's only to be used to fix meshes before you use them, but it worked just fine when I used it within my main loop, and I can't find anything better that I'm supposed to use in my main loop.
I still have not found an answer to question #2. Any help would be greatly appreciated.
Code: Select all
IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
IMeshManipulator *manipulator = smgr->getMeshManipulator();
manipulator->setVertexColors(mesh->getMesh(0),SColor(128,255,0,0));
/*
this sets the alpha for the whole mesh to 128, and colors it red. If the mesh already has a texture, it will "dye" the texture red, otherwise it will just color the whole thing red
*/
int alpha=128;
manipulator->setVertexColorAlpha(mesh->getMesh(0),alpha);
I still have not found an answer to question #2. Any help would be greatly appreciated.
-
- Posts: 6
- Joined: Sat Jul 08, 2006 8:39 am
I have exactly the same problem as your problem #2.
I want to have a texture that gradually fades out towards the edges but Irrlicht just does a hard cut after a certain alpha value, so everything above a certain alpha value is completely transparent and below that value it's completely opaque.
Can you post how exactly you solved that problem?
I want to have a texture that gradually fades out towards the edges but Irrlicht just does a hard cut after a certain alpha value, so everything above a certain alpha value is completely transparent and below that value it's completely opaque.
Can you post how exactly you solved that problem?
-
- Posts: 518
- Joined: Tue Mar 29, 2005 9:02 pm
- Location: Alex,Egypt
- Contact:
Re: Solid color and alpha questions
see Magic3D library here is a base class of Magic3D libraryluvcraft wrote: 3. Is there any way to adjust the overall alpha for a texture, for instance if I want a scene node to slowly fade out to total transparency?
Code: Select all
/******************************************************
base Magic class
part of Magic Library
By Emil Halim
******************************************************/
#ifndef __I_base_Magic_H_INCLUDED__
#define __I_base_Magic_H_INCLUDED__
/// Base class for doing color and alpha blending effectes,
/// fade in and out effectes, by using Shader Language.
class CBaseMagicSceneNode : public scene::ISceneNode // public IMagic3DObject
{
protected:
IShaderProgram* Sprogram; ///< pointer to a shader program
f32 col[4]; ///< hold the current color component and alpha as float value
u8 red; ///< holds the current color red component as integer value
u8 green; ///< holds the current color green component as integer value
u8 blue; ///< holds the current color blue component as integer value
f32 alpha; ///< holds the current alpha value
f32 factor; ///< using in fading system
u32 oldtick; ///< using in fading system
u32 flag; ///< using in fading system
public:
/// constructor
CBaseMagicSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id);
/// distructor
~CBaseMagicSceneNode();
/// attach a shader program to this scene node
void setShaderProgram(IShaderProgram* Sp);
/// set the color component red,green,blue
void setColor(u8 r,u8 g, u8 b);
/// set the aplha value
void setAlpha(f32 a);
/// fade in function
void FadeIn(f32 time);
/// fade out function
void FadeOut(f32 time);
/// cycle fading function
void FadeInOut(f32 in,u32 sty,f32 out,bool flg = false);
/// return fade factor
f32 getFadeFactor();
/// set fade factor
void setFadeFactor(f32 fctr);
};
//==============================================================================
/// constructor of the class
/// set the defulte value for each members
CBaseMagicSceneNode::CBaseMagicSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id) : ISceneNode(parent, mgr, id)
{
Sprogram = 0;
red =255;
green =255;
blue =255;
alpha =1.0f;
flag = 1;
setAutomaticCulling(false);
}
/// distructor of the class
CBaseMagicSceneNode::~CBaseMagicSceneNode()
{
}
/// allows you to create your own shader program then attach it to this node
/// or attach the program created in IniMagic Function
void CBaseMagicSceneNode::setShaderProgram(IShaderProgram* Sp)
{
Sprogram = Sp;
}
/// set the color component red,green,blue
void CBaseMagicSceneNode::setColor(u8 r,u8 g, u8 b)
{
red =r;
green =g;
blue =b;
}
/// set the aplha value
void CBaseMagicSceneNode::setAlpha(f32 a)
{
alpha=a;
}
/// fade in our scene node
/// time is the time of fading operation
/// it changes 50 times per second
void CBaseMagicSceneNode::FadeIn(f32 time)
{
u32 tick = GetTickCount();
if(tick-oldtick > 20)
{
oldtick = tick;
factor += 20.0/time;
if(factor>1.0)factor=1.0;
}
setAlpha(factor);
}
/// fade out our scene node
void CBaseMagicSceneNode::FadeOut(f32 time)
{
u32 tick = GetTickCount();
if(tick-oldtick > 20)
{
oldtick = tick;
factor -= 20.0/time;
if(factor<0.0)factor=0.0;
}
setAlpha(factor);
}
/// cycle fading of our scene node
/// in is the time to fade in
/// sty is the time befor it start to fade out
/// in is the time to fade out
/// flg true to cycle fading operation
void CBaseMagicSceneNode::FadeInOut(f32 in,u32 sty,f32 out,bool flg)
{
u32 tick = GetTickCount();
if((tick-oldtick > 20) && flag == 1)
{
oldtick = tick;
factor += 20.0/in;
if(factor>1.0){factor=1.0; flag = 2;}
}
if((tick-oldtick > sty) && flag == 2)
{
oldtick = tick;
flag = 3;
}
if((tick-oldtick > 20) && flag == 3)
{
oldtick = tick;
factor -= 20.0/out;
if(factor<0.0)
{
factor=0.0;
if(flg)flag=4;
}
}
if((tick-oldtick > sty) && flag == 4)
{
oldtick = tick;
flag = 1;
}
setAlpha(factor);
}
/// return fade factor
f32 CBaseMagicSceneNode::getFadeFactor()
{
return factor;
}
/// set fade factor
void CBaseMagicSceneNode::setFadeFactor(f32 fctr)
{
factor= fctr;
}
#endif
alpha value,and fading in and out it.
here is the link of Magic3D library
http://irrlicht.sourceforge.net/phpBB2/ ... &start=225
Magic 2d Library For Irrlicht : http://www.freewebs.com/bcxgl/index.htm
http://www.freewebs.com/bcxdx/index.htm
http://groups.yahoo.com/group/bcxdxc/
http://www.freewebs.com/bcxdx/index.htm
http://groups.yahoo.com/group/bcxdxc/
-
- Posts: 518
- Joined: Tue Mar 29, 2005 9:02 pm
- Location: Alex,Egypt
- Contact:
Hi vitekvitek wrote:Emil,
You posted all that code, and all it does is show how to set a flag to different values over time. It doesn't solve his problem because you don't show how you are rendering the node using the alpha value.
Travis
yes , i post only part of magic3D library, it is not good idea to post all the code here, so if he see this part is usful he could download the library and see all the classes, and if he not like it , no problem no big code have posted.
Magic 2d Library For Irrlicht : http://www.freewebs.com/bcxgl/index.htm
http://www.freewebs.com/bcxdx/index.htm
http://groups.yahoo.com/group/bcxdxc/
http://www.freewebs.com/bcxdx/index.htm
http://groups.yahoo.com/group/bcxdxc/
For #2 it is very easy... I alredy post it in forum somewhere:
You can find it in my atmosphere source code.
0.01f is very small number,so texture has nice smooth edge, you can try to animate this value (rise it) to get sharp edge until texture disappere.
Code: Select all
bill->setMaterialTexture(0, driver->getTexture("sun.tga"));
bill->getMaterial(0).MaterialTypeParam = 0.01f; //this
bill->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);//and this line
0.01f is very small number,so texture has nice smooth edge, you can try to animate this value (rise it) to get sharp edge until texture disappere.
My project in forum- ATMOsphere - new dynamic sky dome for Irrlicht
-
- Posts: 6
- Joined: Sat Jul 08, 2006 8:39 am
Well, it seems to work for the edges, but if I make the alpha channel all grey, it doesn't look transparent. Until now I've been using EMT_TRANSPARENT_ADD_COLOR which looks a lot better than any of my alpha channel experiments. However EMT_TRANSPARENT_ADD_COLOR doesn't work very well if the background is very bright...Pazystamo wrote:For #2 it is very easy... I alredy post it in forum somewhere:You can find it in my atmosphere source code.Code: Select all
bill->setMaterialTexture(0, driver->getTexture("sun.tga")); bill->getMaterial(0).MaterialTypeParam = 0.01f; //this bill->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);//and this line
0.01f is very small number,so texture has nice smooth edge, you can try to animate this value (rise it) to get sharp edge until texture disappere.
Everything is working, maybe your textures are bad?counter123 wrote:Well, it seems to work for the edges, but if I make the alpha channel all grey, it doesn't look transparent. Until now I've been using EMT_TRANSPARENT_ADD_COLOR which looks a lot better than any of my alpha channel experiments. However EMT_TRANSPARENT_ADD_COLOR doesn't work very well if the background is very bright...
My project in forum- ATMOsphere - new dynamic sky dome for Irrlicht