Page 1 of 1

Render Artifacts

Posted: Tue Dec 12, 2017 4:45 pm
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

Re: Render Artifacts

Posted: Tue Dec 12, 2017 7:43 pm
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.

Re: Render Artifacts

Posted: Tue Dec 12, 2017 9:15 pm
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

Re: Render Artifacts

Posted: Wed Dec 13, 2017 3:52 pm
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

Re: Render Artifacts

Posted: Wed Dec 13, 2017 4:45 pm
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

Re: Render Artifacts

Posted: Thu Dec 14, 2017 1:20 am
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

Re: Render Artifacts

Posted: Wed Jan 31, 2018 7:30 pm
by devsh
You could use geometry shaders to extrude convex hulls for every triangle and have dynamic stencil shadows with no CPU cost