Shadow model z-fighting

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
squisher
Competition winner
Posts: 91
Joined: Sat May 17, 2008 2:23 am
Contact:

Shadow model z-fighting

Post by squisher »

Hi, I get z-fighting when I rotate my ship around with shadows enabled:

Image

Relevant code is:

Code: Select all

        smgr->getMeshManipulator()->setVertexColors(smgr->getMesh("bird.irrmesh"), SColor(0, 0, 0, 0));
        auto shadowNode = smgr->addAnimatedMeshSceneNode(smgr->getMesh("bird.irrmesh"), impl->node);
        shadowNode->setID(0);
        shadowNode->setMaterialFlag(irr::video::EMF_LIGHTING, false);
        shadowNode->setMaterialFlag(irr::video::EMF_ZWRITE_ENABLE, false);
        shadowNode->setMaterialFlag(irr::video::EMF_BACK_FACE_CULLING, false);
        shadowNode->setMaterialType(irr::video::EMT_TRANSPARENT_VERTEX_ALPHA);
        shadowNode->addShadowVolumeSceneNode()->setID(0);
        smgr->setShadowColor(SColor(150,0,0,0));
Here's the bird.irrmesh

Workaround is to use a copy of bird.irrmesh that's scaled by 0.99f:

Code: Select all

        auto smesh = smgr->getMeshManipulator()->createMeshCopy(smgr->getMesh("bird.irrmesh")->getMesh(0));
        smgr->getMeshManipulator()->scale(smesh, vector3df(.99f, .99f, .99f));
        smgr->getMeshManipulator()->setVertexColors(smesh, SColor(0, 0, 0, 0));
        auto mesh = smgr->getMeshManipulator()->createAnimatedMesh(smesh);
        smesh->drop();
 
        auto shadowNode = smgr->addAnimatedMeshSceneNode(mesh, impl->node);
        mesh->drop();
Had same issue in 1.7 and 1.8.
Current project: StarDust. A single player galactic conquest game.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Shadow model z-fighting

Post by CuteAlien »

You can try if you can work different near and far-plane values. The ratio of those 2 affects the z-fighting. Also check for model errors, like having 2 polygons in the same place accidentally.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply