Wireframe (backfacing edges only) on top of solid render

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
BobTheFish
Posts: 10
Joined: Mon Oct 13, 2008 6:21 am

Wireframe (backfacing edges only) on top of solid render

Post by BobTheFish »

I know how to get Irrlicht to render something in wireframe instead of the usual solid, but I'm trying to figure out how to render black lines for the backfaces edges on top (see bottom of post for screenshot of effect).

It can be done easily with straight GL commands but I'd like to use Irrlicht commands and so retain Irrlicht's ability to use multiple renders.

Example code from a demo called "Loony".

Code: Select all

		// Do the silhouette lines if desired
		if (m_Silhouette)
		{
			glEnable(GL_BLEND);
			glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

			glColor3fv(&m_SilhouetteColor.r);	// Set Line Color
			glLineWidth(m_SilhouetteWidth);		// Give it some beef
			glDepthFunc(GL_LEQUAL);			// Draw shared edges
			glPolygonMode(GL_BACK,GL_LINE);	// Draw Lines
			glCullFace(GL_FRONT);			// Draw backfacing edges only

			glInterleavedArrays(model->dataFormat,0,(GLvoid *)model->vertexData);
			glDrawArrays(GL_TRIANGLES,0,model->faceCnt * 3);

			// Set Everything Back to original settings
			glDepthFunc(GL_LESS);
			glColor3f(1.0f, 1.0f, 1.0f);
			glCullFace(GL_BACK);
		}
Screenshot of Loony demo:
Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Most of what you're looking for appears to be supported in the SMaterial structure defined in SMaterial.h. Specifically, you probably want to use the BackFaceCulling, FrontFaceCulling, ZBuffer, WireFrame, Thickness and MaterialType flags.
BobTheFish
Posts: 10
Joined: Mon Oct 13, 2008 6:21 am

Post by BobTheFish »

Thanks, that helps a lot!

It seems you can't set the node to do both at once?

I found a thread that suggests a way to do this (http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=23639) by calling the scene manager's DrawAll and then rendering each node again (modifying the material out and back).

How efficient is it to render, modify, render and modify back each frame? From my testing it seems very inefficient (1/3 of framerate with the edges drawn compared to without). This is not good since I'd like to draw the edges for all models in my scene.

Code for "modify, 2nd render, and modify back" included below:

Code: Select all

//! Renders the backface wireframe of a specified node
/** Can be used to draw contours for toon shading, etc. (just use RenderBFWF() after you've drawn the node). */
void RenderBFWF(irr::scene::ISceneNode* oNode,irr::f32 fThickness=3, irr::video::SColor cColor=irr::video::SColor(255,0,0,0))
{
	if(!oNode) return;
	irr::video::SMaterial tmat[irr::video::MATERIAL_MAX_TEXTURES],lmat;
	lmat.DiffuseColor=lmat.SpecularColor=lmat.AmbientColor=lmat.EmissiveColor=cColor;
	lmat.BackfaceCulling=false;
	lmat.FrontfaceCulling=true;
	lmat.Lighting=true;
	lmat.Thickness=fThickness;
	lmat.Wireframe=true;
	
	for(u32 i=0;i<oNode->getMaterialCount();i++)
	{
		tmat[i]=oNode->getMaterial(i);
		oNode->getMaterial(i)=lmat;
	}
	oNode->render();
	for(u32 i=0;i<oNode->getMaterialCount();i++)
		oNode->getMaterial(i)=tmat[i];
}
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The SVN version of Irrlicht has an override material, which allows to define material properties which will be used for all nodes instead of those set in each material. This should allow for very efficient changes.
Post Reply