Page 1 of 1

Sorting Polygons on CustomSceneNode

Posted: Tue Mar 09, 2010 2:25 am
by pwierz
I created my own custom scene node and it works properly but the problem with it is that it always draws the polygons in the same order and disregards the z-buffer. Is there a way I can fix this? Obviously I could just do an algorithm to sort per frame based on distance to the camera but my node can have several thousand polys and sorting every frame seems horribly inefficient. Is there a better way of handling this? Thanks for any help.

Posted: Tue Mar 09, 2010 8:52 am
by hybrid
Well, sounds like your registration of the scene node is wrong, or the material setup. Maybe show the code for those two methods, or the whole scene node code.
What's the actual purpose on having a custom scene node btw?

Posted: Tue Mar 09, 2010 2:26 pm
by pwierz
Thanks, hybrid. Here is where I set up the materials:

Code: Select all

	Material.Wireframe = false;
	Material.Lighting = false;   
	Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;

	setMaterialFlag(video::EMF_BILINEAR_FILTER,false);
	setMaterialFlag(video::EMF_ANISOTROPIC_FILTER,true);
	setMaterialFlag(video::EMF_ZBUFFER,true);
	setMaterialFlag(video::EMF_ZWRITE_ENABLE,true);
	setMaterialFlag(video::EMF_BACK_FACE_CULLING,true);

	AutomaticCullingState = scene::EAC_OFF;
And

Code: Select all

void CCustomNode::OnRegisterSceneNode()
{
	if (IsVisible)
		SceneManager->registerNodeForRendering(this);

	ISceneNode::OnRegisterSceneNode();
}
The reason I have a custom node is because I created a class that turns a point cloud into a surface, which none of the existing nodes could do for me.

Posted: Tue Mar 09, 2010 2:32 pm
by hybrid
You need to enable the scene paramater ZWRITE_ON_TRANSPARENT (or very near to this). As a default, all transparent materials have zwrite forcedly turned off. This is usually ok for transparent materials, because the blending will take care of overlaps.

Posted: Wed Mar 10, 2010 4:33 am
by pwierz
That was it. Thanks, hybrid.