Lighting a surface flipped (inverted) cube

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
oholiab
Posts: 2
Joined: Tue May 17, 2016 10:30 pm

Lighting a surface flipped (inverted) cube

Post by oholiab »

Hi! Sorry if this is a dupe, I was pretty unsure on how to word it for Google so I've come up with nada.

I have a cube which I want to use as a room, so I have the following code:

Code: Select all

 
scene::IMeshSceneNode *room = smgr->addCubeSceneNode(15.0f, 0, IDFlag_IsSolid, core::vector3df(10,160,30), core::vector3df(0,0,0), core::vector3df(30, 30, 30));
smgr->getMeshManipulator()->flipSurfaces(room->getMesh());
room->setMaterialFlag(video::EMF_LIGHTING, true);
//room->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
//room->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
room->setMaterialTexture(0, driver->getTexture("media/texture.jpg"));
room->setTriangleSelector(smgr->createTriangleSelector( room->getMesh(), room ));
 
The commented lines are ones I've tried with and without.

I have an animated light circling round the room, but it's not lighting these inside faces! So I created a duplicate cube but smaller, without the surface flip:

Code: Select all

 
scene::IMeshSceneNode *room2 = smgr->addCubeSceneNode(15.0f, 0, IDFlag_IsSolid, core::vector3df(10,160,30), core::vector3df(0,0,0), core::vector3df(3, 3, 3));
room2->setMaterialFlag(video::EMF_LIGHTING, true);
room2->setMaterialTexture(0, driver->getTexture("media/texture.jpg"));
room2->setTriangleSelector(smgr->createTriangleSelector( room2->getMesh(), room2 ));
 
Same cube, inside the other cube, with the same texture and center position, but without the faces flipped... And it lights up just fine!

So, for my first question: what have I missed?

Thanks in advance :)
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Lighting a surface flipped (inverted) cube

Post by mongoose7 »

You probably need to have the normals pointing in, that is, towards the light.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Lighting a surface flipped (inverted) cube

Post by hendu »

Call recalculatenormals after flipsurfaces.
oholiab
Posts: 2
Joined: Tue May 17, 2016 10:30 pm

Re: Lighting a surface flipped (inverted) cube

Post by oholiab »

Ah, I see - so the quantity and directionality of the light on a surface are calculated from its normals? Does this mean that if I were to render both sides of a surface, not only would I need to disable back side culling but I'd also need to add a normal to the reverse surface so it would receive light?

It worked perfectly by the way, thanks so much :)
Post Reply