Render Artifacts

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
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Render Artifacts

Post by kklouzal »

Hey guys I'm getting some rendering artifacts on my .obj model created in Blender. Not sure if it has something to do with the way I created the model or the way I'm using Irrlicht to render the model. Any ideas would be great!
Image
You can see where two objects meet it creates a sort of line that flickers and then finally goes away as you get closer.
It happens everywhere two objects are touching.

Code: Select all

#include <irrlicht.h>
#include <iostream>
 
using namespace irr;
 
int main()
{
    IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(640, 480));
 
    if (device == 0)
        return 1;
 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
 
    scene::IAnimatedMesh* mesh = smgr->getMesh("BasicBuilding.obj");
    scene::ISceneNode* node = 0;
 
    if (mesh)
        node = smgr->addMeshSceneNode(mesh->getMesh(0));
 
    node->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_LIGHTING, false);
    node->setScale(core::vector3df(10, 10, 10));
 
    smgr->addCameraSceneNodeFPS();
 
    device->getCursorControl()->setVisible(false);
 
    int lastFPS = -1;
 
    while (device->run())
    {
        if (device->isWindowActive())
        {
            driver->beginScene(true, true, video::SColor(255, 200, 200, 200));
            smgr->drawAll();
            driver->endScene();
 
            int fps = driver->getFPS();
 
            if (lastFPS != fps)
            {
                core::stringw str = L"Irrlicht Engine [";
                str += driver->getName();
                str += "] FPS:";
                str += fps;
 
                device->setWindowCaption(str.c_str());
                lastFPS = fps;
            }
        }
        else
            device->yield();
    }
 
    device->drop();
    return 0;
}
You can download the model here to test (included the .blend file)
https://drive.google.com/open?id=10ir-E ... z4y53zHphP
Dream Big Or Go Home.
Help Me Help You.
CuteAlien
Admin
Posts: 9628
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Render Artifacts

Post by CuteAlien »

Not 100% certain, but looks to me like z-buffer troubles. You have 2 polygons at the exact same distance from camera, then the graphic-card can't decide which one is in front.
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
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Render Artifacts

Post by kklouzal »

Does anyone have suggestions for things I can do to improve the situation? It's very visually displeasing.
The further up I scale the model the more pronounced the issue gets:
Image
You can see here at 100x scale it happens at every edge, even the ceilings which sit on top of the walls. The walls themselves just butt up against each other.

EDIT:
I have a feeling I might not be creating the model properly; after playing around with lighting and shadows the model doesn't seem to be effected by anything other than ambient light. Regular lights barely light it up compared to a CubeSceneNode placed within the 'room'.
Image
You can see only an extremely faint red glow on the walls compared to the cube which is lit up like a christmas tree :P
Dream Big Or Go Home.
Help Me Help You.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Render Artifacts

Post by Mel »

On the materials you could enable the normalize normals flag, and try again the lighting. As for the small gaps, the z fights use to be produced because the near plane of the camera is less than 1, or degenerate surfaces. Try setting the near value to 1, which is the most recomendable setup. Also, Blender has a workflow which is very friendly to real time applications, unless you're duplicating faces unnecesarily, it shouldn't produce any visible artifacts. Check the triangles it produces are the triangles you're expecting, and don't overlap surfaces, i.e. try that you don't create any coplanar faces in your models... unless you know what you're doing ^^U
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
kklouzal
Posts: 343
Joined: Sun Mar 28, 2010 8:14 pm
Location: USA - Arizona

Re: Render Artifacts

Post by kklouzal »

I stumbled upon NormalizeNormals and that fixes the lighting issues, I recreated a simpler model and am now testing with that, the issue seems to have gone away so maybe I did something funky in Blender with my old model. Now after enabling the stencil buffer I get all kinds of crazy stuff happening.. :(
Image
Image
These futile attempts at shadows flash in and out whenever the camera moves or the angle changes. It was orders of magnitude worse before I added camera->setFarValue(10000.0f);
Changing the near value to 1 in this instance has no visible effect.

What the heck :P I just want some decent lighting and shadows haha

Code: Select all

#include <irrlicht.h>
#include <iostream>
 
using namespace irr;
 
int main()
{
    IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<u32>(640, 480), 32, false, true);
 
    if (device == 0)
        return 1;
 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
    driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
    smgr->setAmbientLight(video::SColorf(0.3f, 0.3f, 0.3f, 0.3f));
 
    scene::IAnimatedMesh* mesh = smgr->getMesh("BasicBuilding.obj");
    scene::IAnimatedMeshSceneNode* node = 0;
 
    if (mesh)
    {
        node = smgr->addAnimatedMeshSceneNode(mesh);
        node->addShadowVolumeSceneNode();
        //node->setMaterialFlag(video::E_MATERIAL_FLAG::EMF_LIGHTING, false);
        node->setScale(core::vector3df(10, 10, 10));
        node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
    }
 
    scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS();
    camera->setPosition(core::vector3df(0, 100, 0));
    camera->setNearValue(1.0f);
    camera->setFarValue(10000.0f); // this increase a shadow visible range
    scene::ILightSceneNode* light1 = smgr->addLightSceneNode(camera, core::vector3df(0, 0, 0),
            video::SColorf(1.0f, 1.0f, 1.0f, 1.0f), 300.0f);
 
    scene::ISceneNode* light2 =
        smgr->addLightSceneNode(0, core::vector3df(0, 100, 0),
            video::SColorf(1.0f, 0.0f, 0.0f, 1.0f), 300.0f);
 
    scene::ISceneNode* node2 = 0;
    node2 = smgr->addCubeSceneNode();
    node2->setPosition(core::vector3df(0, 20, 0));
 
    device->getCursorControl()->setVisible(false);
 
    int lastFPS = -1;
 
    while (device->run())
    {
        if (device->isWindowActive())
        {
            driver->beginScene(true, true, video::SColor(255, 200, 200, 200));
            smgr->drawAll();
            driver->endScene();
 
            int fps = driver->getFPS();
 
            if (lastFPS != fps)
            {
                core::stringw str = L"Irrlicht Engine [";
                str += driver->getName();
                str += "] FPS:";
                str += fps;
 
                device->setWindowCaption(str.c_str());
                lastFPS = fps;
            }
        }
        else
            device->yield();
    }
 
    device->drop();
    return 0;
}
Current testing model:
https://drive.google.com/open?id=1ihAzS ... ryAnZ7FDlg

Here's a video showing after I made the light move in a circle:
https://youtu.be/HKRILrVCU3A
Dream Big Or Go Home.
Help Me Help You.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Render Artifacts

Post by Mel »

Do not use stencil shadows to project shadows of rooms within themselves. Eventhough it shouldn't pose really a problem, the code used to generate the extrusion of the shadow volumes for the stencil buffer has still some issues, which aren't easy to address without rewritting some complex parts. Take notice that the stencil shadows are oriented towards animated meshes, moving objects, not stages. In the current stage of things, the stencil shadows have still a road ahead, so those z fights are still an issue. There is a flag in the shadow volume addition that tells Irrlicth to use another method for the shadow projection, for when the camera enters the volumes, i don't recall its name now, but you've stumbled upon it if you're using the shadows for sure :D
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Re: Render Artifacts

Post by devsh »

You could use geometry shaders to extrude convex hulls for every triangle and have dynamic stencil shadows with no CPU cost
Post Reply