[EDIT= Jul 19, 2011 23:34]
Feels like I am approaching a final version for this technique. Added a couple more opimizations.
Instructions for usage:
Setup:
For every mesh you want a wireframe rendered on, simply create a child node with the same mesh and the EMF_WIREFRAME MaterialFlag set to true. After that you can set the texture however you like, to any colour. If you want a uniformly coluored wireframe, set the EMF_LIGHTING false. For example:
Code: Select all
// get your mesh
IMesh* sydney_m = smgr->getMesh("./sydney.md2");
// mesh node
IMeshSceneNode* sydney_mn = smgr->addMeshSceneNode( sydney_m );
sydney_mn->setMaterialTexture(0, driver->getTexture("./textures/sydney.bmp"));
sydney_mn->setMaterialFlag (video::EMF_LIGHTING, false);
// wireframe node
IMeshSceneNode* sydney_wrfn = smgr->addMeshSceneNode( sydney_m );
sydney_wrfn->setMaterialFlag (video::EMF_LIGHTING, false);
sydney_wrfn->setMaterialFlag (video::EMF_WIREFRAME, true);
sydney_wrfn->setParent (sydney_mn); // Don't forget to setParent
Then create an array of ISceneNode pointers and push_back all the wireframe nodes you want rendered into it:
Code: Select all
array<ISceneNode*> wrf_array ();
wrf_array.push_back (sydney_wrfn);
Now just call the nudge function from your game loop and pass it the SceneManager and array of wireframe nodes.
All this functino does is iterate through the array, check if the node is culled, nudge wireframe slightly toward camera, and scale. It's quite simple actually and rather effective for creating that solid wireframe look. And useful as a 'prettier' debug tool.
Code: Select all
void nudge (ISceneManager* smgr, array<ISceneNode*>& wrf_array)
{
// nudge wireframes
for (int i=0; i<wrf_array.size(); ++i)
{
ISceneNode* wireframe_node = wrf_array[i];
if (!(smgr->isCulled(wireframe_node)))
{
ISceneNode* mesh_node = wireframe_node->getParent();
ICameraSceneNode* cam = smgr->getActiveCamera ();
// nudge_length is .005 of the extent of the mesh's bounding box
f32 nudge_length = (wireframe_node->getBoundingBox().getExtent()).getLength();
nudge_length *= 0.005;
vector3df nudge_vec (cam->getPosition() - mesh_node->getPosition());
f32 scale_factor = ((nudge_vec.getLength() - nudge_length) / nudge_vec.getLength());
nudge_vec.setLength (nudge_length);
wireframe_node->setPosition (nudge_vec);
wireframe_node->setScale (vector3df (scale_factor, scale_factor, scale_factor));
}
}
}
I still want to develop an even simpler version that operates on the depth bias in the z-buffer, but I'm waiting for v1.8 to try that with PolygonOffsetFactor ala hybrid's suggestion...