Transluscent filled polygons. Also draw distance.

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
ben
Posts: 18
Joined: Fri May 22, 2009 4:43 pm

Transluscent filled polygons. Also draw distance.

Post by ben »

Hi,
I would like to fill a model with a single semi-transparent colour... how do I go about doing this? I have tried everything I can think of without success.
In addition to this I would like to outline the visible polygons of the model- i.e. use hidden line removal.
I found a solution to this, but I am unable to get it to work!

The solution was:
Ok, just as cassini suggested. Works right away, just render the mesh two times. First with ColorMask set to ECP_NONE, then with wireframe enabled, ZBuffer set to ECF_LESSEQUAL (to avoid missing lines where the mesh is intersecting the wireframe) and Thickness set tom something larger than 1.f for better recognizable effect (the latter only works under OpenGL). Looks terrific
I sorted out the line thickness okay.

I guess that to render twice you call
smgr->drawAll();
twice.

But I can't even find some of the other things like ColorMask :/

And finally, I seem to be having some problems with low draw distance, is there any way to extend this?

Many thanks
Ben.
Lonesome Ducky
Competition winner
Posts: 1123
Joined: Sun Jun 10, 2007 11:14 pm

Post by Lonesome Ducky »

You can go through the mesh buffers of a mesh and change the alpha of the vertex. Here is some code:

Code: Select all

void setMeshTransparent(IAnimatedMeshSceneNode* node, char trans) {

	for (int y = 0; y < node->getMesh()->getMeshBufferCount(); y++) {	
		IMeshBuffer *mb = node->getMesh()->getMeshBuffer(y);
		S3DVertex* v = (S3DVertex*)mb->getVertices();
		for (int x = 0; x < mb->getVertexCount(); x++) {
			v[x].Color.setAlpha(trans);
		}
		node->getMaterial(y).MaterialType = EMT_TRANSPARENT_VERTEX_ALPHA; 		

	}
	


}
ben
Posts: 18
Joined: Fri May 22, 2009 4:43 pm

Post by ben »

Thanks. I have solved all these problems now.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The solution I posted works with Irrlicht SVN/trunk (aka 1.6-SVN). You'd also get better support for material overrides due to the new OverrideMaterial.
ben
Posts: 18
Joined: Fri May 22, 2009 4:43 pm

Post by ben »

Here is my solution, as an alternative method for those interested:

Code: Select all

node->setMaterialFlag(EMF_LIGHTING, true);
node->setMaterialType(EMT_TRANSPARENT_ADD_COLOR);

node->setMaterialFlag(EMF_WIREFRAME, false);
node->getMaterial(0).EmissiveColor.set(255,0,30,0);

smgr->drawAll();

node->setMaterialFlag(EMF_WIREFRAME, true);
node->getMaterial(0).EmissiveColor.set(255,0,255,0);

glLineWidth(1.5);	//Set openGL line width

smgr->drawAll();

The above gives a pretty translucent effect, and if you remove the
node->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR);
line then you get standard hidden line removal

you have to include gl.h to use openGL functions
#include <GL/gl.h>
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Line width can also be set via SMaterial, so you can avoid the OpenGL stuff. It will also be overwritten very easily by the material setup in Irrlicht. Moreover, you need to call the flags for each mesh/meshbuffer, here it's only done for one object. This is all done by the OverrideMaterial in Irrlicht 1.6 - I guess most people can wait for that version :wink:
ben
Posts: 18
Joined: Fri May 22, 2009 4:43 pm

Post by ben »

I was going to create an array of pointers to each object and then just loop through it. I don't know if this will be fast enough, I suspect it will not!

How long 'till 1.6 is out?
cheshirekow
Posts: 105
Joined: Mon Jul 27, 2009 4:06 pm
Location: Cambridge, MA

Post by cheshirekow »

Thanks @Lonesome Ducky. This is exactly what I needed. My mesh was textured so I couldn't simply set the color of the material, and I had some problems with the GUI in 1.6 that I don't really want to figure out. Your solution works copy + paste out of the box with 1.5.
Post Reply