light seems to be coming from different directions per objec

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.
ChrisC
Posts: 37
Joined: Sun Dec 03, 2006 6:47 am

light seems to be coming from different directions per objec

Post by ChrisC »

I have created a light like this

Code: Select all

 
    scene::ILightSceneNode* l = smgr->addLightSceneNode(0, core::vector3df(100.f,100.f,100.f),
                            video::SColorf(1.f, 1.f, 1.f, 1.0f), 600.0f);
    l->setLightType(video::ELT_POINT);
    smgr->setAmbientLight(video::SColorf(.4f, .4f, .4f, 1.0f));
 
When creating each object I do this

Code: Select all

 
        scene::IMesh* cylinderMesh = smgr->getGeometryCreator()->createCylinderMesh(
                size.X, /*radius*/   size.Y/2.f, /*length*/   64, // tesselation
                video::SColor(255, 255, 255, 255), /*color*/  true, /*closeTop*/  0.0f  /*oblique*/);        
        node = smgr->addMeshSceneNode(cylinderMesh,
                0, /*parent*/  -1, // id
                core::vector3df(0, 0, 0), /*position*/   core::vector3df(0, 0, 0), //rotation
                core::vector3df(1.f,1.f,1.f) /*scale*/);
        node->setMaterialTexture(0, driver->getTexture("./data/metal.jpg"));
        smgr->getMeshManipulator()->recalculateNormals(cylinderMesh);
        node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
 
As the cylinders are being moved around the light direction stays consistent for a particular object, but it looks like different objects have light coming from different directions

I don't know if it makes a difference but I'm moving the nodes like this

Code: Select all

 
                bodypos = dBodyGetPosition(p->body);
                p->node->setPosition(core::vector3df(bodypos[0],bodypos[1],bodypos[2]));
                q = dBodyGetQuaternion(p->body);
 
                dReal w=q[0];
                x=q[1];
                y=q[2];
                z=q[3];
 
                sx = x*x;
                sy = y*y;
                sz = z*z;
                sw = w*w;
 
                rot.X = (atan2(2.0 * (x*w + y*z ),(-sx - sy + sz + sw)) * irr::core::RADTODEG);
                rot.Y = (asin(-2.0 * (x*z - y*w)) * irr::core::RADTODEG);
                rot.Z = (atan2(2.0 * (x*y + z*w),(sx - sy - sz + sw)) * irr::core::RADTODEG);
                if (p->shape==physObj::ShapeType::cylinder) rot.X+=90;
                p->node->setRotation(rot);
 
NB its not different shapes have different light directions but examples of the smae shape (ie cylinders)

any clues as to what I might be doing wrong would be gratefully received
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: light seems to be coming from different directions per o

Post by Mel »

Unless otherwise specified, the nodes are lit by the closest light by default.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
ChrisC
Posts: 37
Joined: Sun Dec 03, 2006 6:47 am

Re: light seems to be coming from different directions per o

Post by ChrisC »

there is only 1 light - additionally touching cylinders that are at different angles, often don't have constant shading
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: light seems to be coming from different directions per o

Post by REDDemon »

A screenshot?
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
ChrisC
Posts: 37
Joined: Sun Dec 03, 2006 6:47 am

Re: light seems to be coming from different directions per o

Post by ChrisC »

I can throw the same 3d objects at libgdx and get nice shading so I'll probably just stick with that...
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: light seems to be coming from different directions per o

Post by CuteAlien »

Hm, ok. Thought if we had a screenshot we might see what's going on and give hints.
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
ChrisC
Posts: 37
Joined: Sun Dec 03, 2006 6:47 am

Re: light seems to be coming from different directions per o

Post by ChrisC »

http://bedroomcoders.co.uk/tmp/2017-02- ... _scrot.png
I've changed to a loaded obj - notice the shading is at 90 degrees to some of the other objects, and also its not interpolated between vertexes as I'd expect and see with the same model in libgdx

I'm now loading the scene node like this

Code: Select all

 
        scene::IMesh* cylinderMesh = smgr->getMesh("data/drum.obj");
        node = smgr->addMeshSceneNode(cylinderMesh,
                0, /*parent*/  -1, // id
                core::vector3df(0, 0, 0), /*position*/   core::vector3df(0, 0, 0), //rotation
                core::vector3df(size.X,size.X,size.Y) /*scale*/);
        node->setDebugDataVisible(scene::EDS_NORMALS );
 
I wouldn't waste too much time on this, I'm getting much better visuals and roughly the same performance with libgdx...
kornwaretm
Competition winner
Posts: 189
Joined: Tue Oct 16, 2007 3:53 am
Location: Indonesia
Contact:

Re: light seems to be coming from different directions per o

Post by kornwaretm »

have you try recalculating normals?

Code: Select all

 
yourNode->getMaterial(0).setFlag(video::EMF_NORMALIZE_NORMALS, true);
 
or

Code: Select all

 
yourNode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
 
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: light seems to be coming from different directions per o

Post by CuteAlien »

Hm, guess I'd have to code a test - can't really tell from the image (it's pretty hard as that stuff depends on the angle between light and normal and I don't even see the light here - somehwere to the left I guess). Also long thin triangles like those are somewhat tricky for per-vertex lighting (small regular triangles work best with that).

@kornwaretm: he did ;-) (code in first post)
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
ChrisC
Posts: 37
Joined: Sun Dec 03, 2006 6:47 am

Re: light seems to be coming from different directions per o

Post by ChrisC »

kornwaretm wrote:have you try recalculating normals?

Code: Select all

 
yourNode->getMaterial(0).setFlag(video::EMF_NORMALIZE_NORMALS, true);
 
or

Code: Select all

 
yourNode->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
 
already tried that without change
ChrisC
Posts: 37
Joined: Sun Dec 03, 2006 6:47 am

Re: light seems to be coming from different directions per o

Post by ChrisC »

CuteAlien wrote:Hm, guess I'd have to code a test - can't really tell from the image (it's pretty hard as that stuff depends on the angle between light and normal and I don't even see the light here - somehwere to the left I guess). Also long thin triangles like those are somewhat tricky for per-vertex lighting (small regular triangles work best with that).
PM me with your email, I can send you the code, its just irrlicht used as a visualisation for ode so there isn't massive amounts of code

Tried with irrlichts mesh builder and loaded OBJ with identical results, the per vertex lighting seem to work fine elsewhere with the same models...
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: light seems to be coming from different directions per o

Post by CuteAlien »

Which videodriver are you using in Irrlicht? And on which OS is this?
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
ChrisC
Posts: 37
Joined: Sun Dec 03, 2006 6:47 am

Re: light seems to be coming from different directions per o

Post by ChrisC »

Void Linux, Intel HD5500
CuteAlien
Admin
Posts: 9652
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: light seems to be coming from different directions per o

Post by CuteAlien »

Thanks. Still wondering which videodriver - I mean the EDT_.... thing like EDT_OPENGL you set on createDevice. Just checking if you maybe did just set a software driver.
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
ChrisC
Posts: 37
Joined: Sun Dec 03, 2006 6:47 am

Re: light seems to be coming from different directions per o

Post by ChrisC »

video::EDT_OPENGL
Post Reply