Alpha Problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
spike314
Posts: 27
Joined: Sun Nov 19, 2006 11:51 am
Location: Shropshire (UK)
Contact:

Alpha Problem

Post by spike314 »

Hi all

Ive been trying to setup a alpha mesh using EMT_TRANSPARENT_ADD_COLOR and EMT_TRANSPARENT_VERTEX_ALPHA which looks great from 1 place. but if i move the camera closer to 0,0,0 the alpha channel changes.

Image

if i set my alpha to 0 it still has the same effect but the node goes black.

here is how im setting up the alpha

Code: Select all

        MyAlpha = 0.5;
	int IntAlpha = (int)(MyAlpha*255);
	int swpAlpha = IntAlpha-255;


	int MaterialCount =  node->getMaterialCount();
	for(int i=0; i<MaterialCount; i++)
	{		
		video::SMaterial &mat = node->getMaterial(i);
		mat.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;//video::EMT_TRANSPARENT_ADD_COLOR;
		mat.Lighting = false;
		mat.DiffuseColor.setAlpha(IntAlpha);
		mat.AmbientColor.setAlpha(IntAlpha);
	}

			 Anode = (scene::IAnimatedMeshSceneNode*)node;
			 Amesh = Anode->getMesh();
			for(u32 i=0; i<Amesh->getMeshBufferCount(); i++)
			{
				scene::IMeshBuffer* buffer = Amesh->getMeshBuffer(i);
				video::S3DVertex* vertex = (video::S3DVertex*)buffer->getVertices();
				for(u32 j=0; j<buffer->getVertexCount(); j++)
				{					
					vertex[j].Color = video::SColor(IntAlpha,IntAlpha,IntAlpha,IntAlpha);
				}
			}	
any would be great Thanks
You can have all the power in the world but if you have no one to follow you what good is the power?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Better use the MeshManipulator method to set the alpha value. At least it does not change the vertex colors and hence does not corrupt the proper texturing.
spike314
Posts: 27
Joined: Sun Nov 19, 2006 11:51 am
Location: Shropshire (UK)
Contact:

Post by spike314 »

Ive just tryed that but still has the same effect.
You can have all the power in the world but if you have no one to follow you what good is the power?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Re: Alpha Problem

Post by Acki »

spike314 wrote:if i set my alpha to 0 it still has the same effect but the node goes black.

Code: Select all

vertex[j].Color = video::SColor(IntAlpha,IntAlpha,IntAlpha,IntAlpha);
that's because you set the vertex colors to black then !!! :lol:
try this:

Code: Select all

vertex[j].Color = video::SColor(IntAlpha,255,255,255);
remember only the 1st parameter is the alpha channel !!! ;)

because of the transparency I'm not sure, but I had a similar problem when I used transparent textures...
after I used makeColorKeyTexture I forgot to recalculate the mipmap levels...
well, you don't use makeColorKeyTexture here, so I'm not sure about that...

EDIT: I just tested your code and the Ninja stays transparent, regardless of the distance to the camera...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
spike314
Posts: 27
Joined: Sun Nov 19, 2006 11:51 am
Location: Shropshire (UK)
Contact:

Post by spike314 »

So could that be a problem with my camera settings you think?
You can have all the power in the world but if you have no one to follow you what good is the power?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

spike314 wrote:So could that be a problem with my camera settings you think?
I doubt...
maybe you can make a small, full working example that shows the problem ???
bc with the posted snippet I can't reproduce this...
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
spike314
Posts: 27
Joined: Sun Nov 19, 2006 11:51 am
Location: Shropshire (UK)
Contact:

Post by spike314 »

I did have driver->setAllowZWriteOnTransparent(true); which was making the node black if disabled the node just disapears. it seems to be a Zorder problem bc if i remove the room i can see the node from every side. I am using irrlicht 1.6 but ive made that many changes to it, it will be very hard to convert.
You can have all the power in the world but if you have no one to follow you what good is the power?
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

sorry, can't reproduce it, neither with setAllowZWriteOnTransparent(true); nor with Irrlicht 1.6 !!!
and such informations like Irrlicht version and using functions like setAllowZWriteOnTransparent can be very important so you always should mention them... ;)

you realy should make a minimalistic test program, at least for yourself for testing !!!
for testing I used the quake map from the sdk, maybe try this too to see if the error depends on your level mesh...
spike314 wrote:I am using irrlicht 1.6 but ive made that many changes to it, it will be very hard to convert.
yeah, I know this problem, that's the reason why I created my IrrExtensions so I can make all changes with a few mouse klicks and a little bit of patience while compiling... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
feelthat
Posts: 194
Joined: Sat Feb 02, 2013 5:27 am

EMT_TRANSPARENT_ALPHA_CHANNEL, EMT_TRANSPARENT_ADD_COLOR

Post by feelthat »

//follow code test good in b3d obj 3ds
//demo here
https://plus.google.com/photos/10618554 ... 8774360364

////////////////////////////////////////////////////////////////
IAnimatedMesh* mesh;
IAnimatedMeshSceneNode* node;
.
.
.
mesh = smgr->getMesh( memfile );
node = smgr->addAnimatedMeshSceneNode( mesh );
node->setMaterialFlag(EMF_LIGHTING, true); // use light is ok~~~
node->setMaterialFlag(EMF_NORMALIZE_NORMALS, true);

u32 MyAlpha = 150; //0~255
u32 MaterialCount = node->getMaterialCount();
for(u32 i=0; i<MaterialCount; i++)
{
video::SMaterial& tex_mat = node->getMaterial(i);
tex_mat.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
tex_mat.AmbientColor.setAlpha(MyAlpha);
tex_mat.DiffuseColor.setAlpha(MyAlpha);
tex_mat.SpecularColor.setAlpha(MyAlpha);
tex_mat.EmissiveColor.setAlpha(MyAlpha);
}


//this can do or not by ur choice
for(u32 i=0; i<mesh->getMeshBufferCount(); i++)
{
scene::IMeshBuffer* buffer = mesh->getMeshBuffer(i);
video::S3DVertex* vertex = (video::S3DVertex*)buffer->getVertices();
for(u32 j=0; j<buffer->getVertexCount(); j++)
{
vertex[j].Color.setAlpha(MyAlpha);
}
}

spike314 wrote:So could that be a problem with my camera settings you think?
Post Reply