Loading an OBJ coming out black

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.
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Loading an OBJ coming out black

Post by Asimov »

Hi,
I am trying out a model which I didn't build for test purposes.
It is in obj format.

Now I have lighting in my scene obviously so I set the model to receive light with
node->setMaterialFlag(EMF_LIGHTING, true);

However when I do this the model comes out black.
If I do the settings like this
node->setMaterialFlag(EMF_LIGHTING, false);
Then I can see the diffuse map clearly.

You can clearly see that there is light in the scene from my image so I am wondeirng why the model should be black.
I have other models in the scene which are not black. Any ideas?
Image

There is clearly light in the scene, and you can even see the shadow, but I don't understand why the model comes out black.
Normally I build all my models but i am using this model as a test piece until I have time to build my own models.

My other models in the scene were exported in x format, but sometimes obj is more convenient.

Really wish irrlicht supported FBX as that works well in Unity.
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Loading an OBJ coming out black

Post by CuteAlien »

Load the model in the modelviewer for a test. Otherwise - send it to me so I can check. I can't see from your scene if rest is using light btw - maybe it has light disabled?
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
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Loading an OBJ coming out black

Post by Asimov »

When I load it into the modelviewer(example 9) I can see the model and texture fine.
All my other models have the EMF_LIGHTING set to true and they show up in the scene ok.

Here are my light settings.

Code: Select all

////////////////
  /// Lighting ///
 ////////////////
    smgr->setAmbientLight(SColor(0, 255, 255, 255));
 
    ILightSceneNode* Light = smgr->addLightSceneNode();
    Light->setPosition(vector3df(0.0f, 250.0f, 0.0f));
    SLight lightData;
    lightData.Type= ELT_POINT;
    Light->setLightData(lightData);
    Light->setRadius(150);
    Light->getLightData().Attenuation = vector3df(0,0,.001);
 
    ILightSceneNode* mySpotLight = smgr->addLightSceneNode();
    mySpotLight->setPosition(vector3df(0.0f, 145.0f, 0.0f));
    mySpotLight->setRotation(vector3df(-90.0f, 0.0f, 0.0f));
    SLight spotLightData;
    spotLightData.Type = ELT_SPOT;
    spotLightData.OuterCone = 300;
    spotLightData.InnerCone = 100;
    mySpotLight->setLightData(spotLightData);
As you can see I have two lights in my scene. A point light to light up the room and a spot light to light up the table.
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Loading an OBJ coming out black

Post by CuteAlien »

As you have ambient light turned up to full white the other lights shouldn't even matter anymore.
Meshviewer has a hidden feature (which should be made more visisble, but that's another topic) - press the L-key to switch between light disabled/enabled. By default it seem to be off - please try what happens after pressing L.
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
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Loading an OBJ coming out black

Post by Asimov »

Hi Cutealien,

I tried the cat again in meshviewer and I pressed L. As expected there was colour on one side and dark on the other side, like you would expect with one light source.
So in meshviewer the model was fine.

Which leads me to believe somehow my light settings cannot be right.
The reason I put the ambient light in my scene is because a couple of my models came out black no matter how much I increased light levels.

Can you see any problems with my light settings?
If the settings are fine what else could be the cause?

I am really invested in getting my player class written next, but I am worried my game will look rubbish unless I can get the models looking right, which is a little disheartening.
I like programming, but I am not an expert, so it takes me time to work stuff out.

I am trying the scene without the ambient light but the trouble with the normal lights is that there seems to be no way to make them brighter apart from adjusting their radius.
In most game engines you can set a brightness level of the light. Perhaps there is a way and I just haven't found it yet.
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Loading an OBJ coming out black

Post by CuteAlien »

You can set the light-color (which is intensity per color-channel), but it's probably max-brightness by default. Also if you work with directional light instead of point-light then the light-color is the only value to tune and you don't have to care about radius.

But you are saying your cat is black despite having ambient light? That's the thing that's very strange - especially as it works in the meshviewer. Maybe it's ambient-light factor is 0 - so it's only lighted by diffuse-light. And the diffuse light is then a point-light which is too far away in your scene.
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
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Loading an OBJ coming out black

Post by Asimov »

Hi Cutealien,

Well I have been doing some tests.
I added two animated lights only.

Code: Select all

ILightSceneNode* light = smgr->addLightSceneNode();
light->addAnimator(smgr->createFlyCircleAnimator(vector3df(5,150, 5), 50));
ILightSceneNode* light2 = smgr->addLightSceneNode();
light2->addAnimator(smgr->createFlyCircleAnimator(vector3df(5, 90, 5), 38));
I put them at different heights. Now the strange thing is that as the light comes around the cat colours show up.

My original light set up is a point light and a spot light above. And my thinking was this. In normal room in a house you don't have lights at the side. You only have one or maybe two lights up by the ceiling in the middle and yet it lights the whole room because light bounces.

In my scene even though it is lighting up the table it is not lighting the sides of the objects.
Also if you add a light node and don't specify what kind of light it is eg EMT_SPOT or EMT_POINT what light is it?
Is it a point light by default or what?

So I think I may have to have a light in the centre, but I may need a few more lights lower down to light up the models.
Although if the light is bouncing then I shouldn't need the extra lights. In 3ds max Vray you can actually tell it how many times a light bounces in a room.

The other thing I have trouble with is positioning the light. I have been doing this with guesswork so far.
I add a light to the scene and then keep moving it until it looks right. I wish there was a way of positioning the light better.
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Loading an OBJ coming out black

Post by CuteAlien »

The default is point-light. Which works nicely for some effects, but is hard to tune. Often it's easier to work with a combination of ambient light and directional light. A good setup is sometimes to use a low ambient value (0.2 or so) - which can also be somewhat colored if you want a certain mood (for example to have a difference between inside/outside you might use more blue outside and more yellow inside). And 1-3 directional lights (for example 1-2 from front and a weaker counter-light from back). Again depends on the scene - for a single room with single table you might want a point-light to have really the effect of parts of the room beeing inside and parts beeing outside the light (which you do not get with directional light as it has unlimited distances so it lights the whole room). Same if you want some moving light like a torch around the player - then you need maybe spot-light.
This is usually a lot of experimenting and really depends on the effect you try to get. So your way of moving stuff until it looks right - yeah, that's how I do it as well :-)

We have no ray-tracing, so light does not bounce. Also no other global illumation aside from the ambient light. So your bouncy light = the ambient light. That's unless you write your own shaders. More modern engines have by now some better approximations for global illumination, I hope to add that stuff to Irrlicht as well soon, but no promises if it works out.
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
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Loading an OBJ coming out black

Post by Asimov »

Hi cutealien,

Just put one direct light in the scene which seems to give better light than the point light.
So I am setting up some controls to move my light around via keyboard so that I can fine tune it.

Going to echo the coordinates to the screen and get my light in the right position.
Will let you know how it goes.
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Loading an OBJ coming out black

Post by Asimov »

Hi cutealien,

Well I thought I had put a direction light in the scene, but it was actually a point light because I had forgotten to put the setLightData line in.

There is however a problem. Obviously I have only one light at this point and I know I need more, but the problem is this.
I add one point light above the table, and it has given sufficient light to light the table and the board.

Code: Select all

ILightSceneNode* light2 = smgr->addLightSceneNode();
light2->setPosition(vector3df(5.37f, 140.0f, 20.0f));
However when I turn this light into a directional light it won't light up the board.
Please ignore the glowing houses as I believe this is a material problem.

So this is the scene with one point light.
Image
So when I got the point light right I turned that point light into a directional light with the following code

Code: Select all

light2->setRotation(vector3df(90, 0.0f, 0.0f));
SLight mainLight;
mainLight.Type = ELT_DIRECTIONAL;
mainLight.Radius = 100;
light2->setLightData(mainLight);
I had to setRotation to 90 to make sure it was pointing down. However after changing the light to a directional light it won't light up the board at all.
Image

Is there something else I need to do to make the directional light work. I know I need more lights, but I am trying to get the one directional light to work first.
I have only changed it to a directional light, and changed rotation to point down. So it should really still light up the board. I have also tried bigger and smaller radiuses as well, but I am not sure if they are applicable with a directional light.
Have you any ideas?
Last edited by Asimov on Tue Sep 04, 2018 10:33 pm, edited 1 time in total.
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Loading an OBJ coming out black

Post by CuteAlien »

Did you try -90°? Just in case this is now pointing upwards (which I think it should now, but would have to try myself). Grenade beeing lighted from bottom also hints at light going upwards.
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
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Loading an OBJ coming out black

Post by Asimov »

Yes I tried 90,-90,180 and I even put in a key to rotate the light around all the way, and the board always stays black with the directional light.
By the way anything other than 90 and the table is in darkness so I know 90 is the correct direction.

I think if the light was pointed upwards I wouldn't get any colour on the table.
The houses seem to glow when there is no light, so I think there is a material problem with them, but I know the table is ok, as it doesn't show up when there is no light.

I have turned off ambient light for now until I can get the lights right. So my idea was to get the main light working first and then add the other lights after.
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Loading an OBJ coming out black

Post by CuteAlien »

Glowing houses probably means they have emissive light (which basically means self-lighting - aka no need for an external source - stuff is just brighter). Same might be true for the table. If you look at the grenade in your images - it looks lighted from below - not from above. What kind of material-type does the board have?
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
Asimov
Posts: 246
Joined: Thu Dec 04, 2014 7:41 pm
Contact:

Re: Loading an OBJ coming out black

Post by Asimov »

Hi cutealien,

Well the whole room, the table and board are one model with multi sub textures.
Here is the code I use to load my scene though.

Code: Select all

void LoadManager::loadScene(ISceneManager* smgr,IVideoDriver* driver,const wchar_t* modelname)
{
    mesh = smgr->getMesh(modelname);
 
    ((scene::ISkinnedMesh*)mesh)->convertMeshToTangents();
 
//walls
    scene::IMeshBuffer* walls = mesh->getMeshBuffer(0);
    if (walls)
    {
        video::SMaterial& mt = walls->getMaterial();
        mt.MaterialType = video::EMT_NORMAL_MAP_SOLID;
    }
//fire
    scene::IMeshBuffer* fire = mesh->getMeshBuffer(5);
    if (fire)
    {
        video::SMaterial& mt = fire->getMaterial();
        mt.MaterialType = video::EMT_NORMAL_MAP_SOLID;
    }
   //1= table
   //2= board
 
    //Board
 
    scene::IMeshBuffer* board = mesh->getMeshBuffer(2);
    if (board)
    {
        video::SMaterial& mt = board->getMaterial();
       mt.MaterialType = video::EMT_NORMAL_MAP_SOLID;
    }
 
//logs
    scene::IMeshBuffer* logs = mesh->getMeshBuffer(3);
    if (logs)
    {
        video::SMaterial& mt = logs->getMaterial();
        mt.MaterialType = video::EMT_NORMAL_MAP_SOLID;
    }
// floor
    scene::IMeshBuffer* floor = mesh->getMeshBuffer(4);
    if (floor)
    {
        video::SMaterial& mt = floor->getMaterial();
        mt.MaterialType = video::EMT_NORMAL_MAP_SOLID;
    }
 
   // door
    scene::IMeshBuffer* door = mesh->getMeshBuffer(1);
    if (door)
    {
        video::SMaterial& mt = door->getMaterial();
        mt.MaterialType= video::EMT_PARALLAX_MAP_SOLID;
    }
 
    node = smgr->addMeshSceneNode(mesh);
    if (node)
    {
        node->setMaterialFlag(EMF_LIGHTING, true);
        node->addShadowVolumeSceneNode();
        node->setMaterialFlag(EMF_ANTI_ALIASING, true);
        node->getMaterial(2).TextureLayer[0].LODBias = -4;
    }
}
I have also tried other materials like EMT_PARALLAX_MAP_SOLID and EMT_SOLID and other things as well.

At first I didn't need to add the getmeshBuffer for the board when I had the ambient light, but as soon as I removed the ambient light the board became black and so then I added the board getmeshBuffer code to bring the texture back on the board. The board shows up fine with the point light, but comes out black with the directional light.

PS. The board itself has no normalmap, but other parts of the model do, which is why at first I didn't need the getMeshBuffer for the board. Really that is only for the normalmaps, but the board went black when I removed the ambient light and that solved the problem.
CuteAlien
Admin
Posts: 9646
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Loading an OBJ coming out black

Post by CuteAlien »

OK, looks bad. The normal-map renderer and parallax-render both seem to always expect point-light and not directional light. The shaders are nicely documented, but unforturtunately I'm not familiar at all with assembler shaders (I only know HLSL and GLSL).

Maybe workaround - simulate directional light with point-light by moving the position very far away. And making radius even larger than that distance. Not really sure if that works or is a good idea :-/

This looks more and more like you will need a new shader. Or another engine (sorry).
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