Something I should now about Lights ?

Discussion area about developing with Ogre2 branches (2.1, 2.2 and beyond)
Post Reply
N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am

Something I should now about Lights ?

Post by N0vember » Mon Dec 22, 2014 3:13 pm

I have a problem with both a light and a camera attached to the same scene node.
They are created in the "new" way, that is, I directly attach them to a SceneNode and only set position and orientation on the SceneNode.
So the direction where the camera is facing, the light should be facing too, right ?

Except it doesn't, so does anyone have any idea why I have it wrong ?

Things get more weird that even when I set the light to LT_POINT, the light isn't applied correctly.
So, somehow, it's not only the orientation that is wrong but the position itself. It doesn't come from the same position as the camera even though they are attached to the same exact scene node, and position and orientation are only ever set on the SceneNode by myself.

I post it here since it's with the CTP v2-0 branch, I'm wondering if I'm doing it wrong regarding to the changes in v2-0 ?
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1200
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: Something I should now about Lights ?

Post by al2950 » Mon Dec 22, 2014 4:33 pm

**EDIT** This post is not correct, see next post!!!

Hmmm, as far as I am concerned you are talking sense!

I have not been able to test out your problem yet, however looking at the code there might be a few issues. Although everything needs to be attached to a scene node, cameras are still treated specially. As a result if you were to call getDirection on a normal movableObject, ie light, it would return +Zaxis by default. However a camera will return -Zaxis. So this would be the first thing I would check. Also I am slightly confused about how AABB is setup for a spotlight, it does not seem right to me.

As for point lights, they should be ok. Can you describe what you mean by "the light is not applied correctly"?
Last edited by al2950 on Mon Dec 22, 2014 4:58 pm, edited 1 time in total.
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1200
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: Something I should now about Lights ?

Post by al2950 » Mon Dec 22, 2014 4:49 pm

Above I stated that getDirection on a normal movableObject would return +Zaxis by default. This is total rubbish! The Ogre default is NEGATIVE_UNIT_Z, so it is just the Light class overrides which I believe are wrong. I will check further tonight
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1200
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: Something I should now about Lights ?

Post by al2950 » Mon Dec 22, 2014 11:43 pm

I just did a quick check and there is a bug in OgreLight. Both getDirection & setDirection are wrong in OgreLight.

Basically SceneNode::setDirection has different functionality to Light::setDirection which is wrong... I think! Or at least I can not work out why it would be different! I could fix the bug and do a pull request, but as it is such a small fix it might be quicker for an Ogre Team member to fix it directly?
0 x

N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am

Re: Something I should now about Lights ?

Post by N0vember » Sat Dec 27, 2014 3:51 pm

I tried and reversing the direction of lights to making it return -Z doesn't quite solve the problem though. So it's more complicated (intertwined) than that...

EDIT : My bad, I didn't set the normals on my mesh. No wonder light was fucked up. I'll report back on whether the inverted Z was actually a bug or not
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4063
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 228
Contact:

Re: Something I should now about Lights ?

Post by dark_sylinc » Tue Dec 30, 2014 7:22 pm

Hi,

I'm sorry for not seeing this post sooner. I've been terribly occupied and forgot to check on the forums regularly.

Indeed, the issue is that Camera's "forward" is towards negative Z, whilst Light's "forward" is torwards positive Z.

I quickly decided Light's forward to be +Z because it's more intuitive and plays nicer with a lot of math and algorithms (eg. specially with deferred lighting while rendering the light geometry: a spot light in its default orientation is a cone facing towards +Z which matches a 3D modelling application)
Camera's forward being -Z is something that has been like that since Ogre's inception, and changing it would be a nightmare (and break a lot of working code when porting).

When I see it from the perspective of attaching a light and a camera to the same node, yeah it sucks.

I see two quick fixes:
  • Change the camera's direction. The camera for many legacy reasons still maintains its own direction that will be concatenated with SceneNode's, so you can manipulate the Camera::setDirection once (set it to positive Z) and then use the node to modify the camera.
  • Use a second node either for the light or the camera, so that the second node can be reoriented and both end up matching their orientation.
If you're wondering why Camera retained its own direction and the Lights didn't; the reasons are rather complicated.
Lights need to be frustum culled and have their AABBs up to date. For that, I needed the transform data to live entirely in the SceneNode both for performance and to avoid code duplication.

Cameras on the other hand didn't need this and should theoretically not need a SceneNode. However Cameras unfortunately (wrongly?) derive from MovableObject, and MovableObjects assume they're tied with Nodes when they're part of a scene. Trying to use a MovableObject without a parent could lead to an eventual crash, hence Cameras are forced to use a Node.

If I were designing a new engine from scratch this awkardness wouldn't happen, but we have a lot of old baggage to deal with, and sometimes situations like this arise. Perhaps in the future we could refactor Camera to not have its own independent position and direction and change its Forward to being +Z for both consistency and simplicity; but one step at a time.
0 x

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7147
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 16

Re: Something I should now about Lights ?

Post by Kojack » Wed Dec 31, 2014 3:28 am

-Z for forward is the standard price for right handed coordinate systems (I prefer left handed, but that's almost a religious argument like brace location in c++).
If lights have forward as +z, then that means their right is -x. That seems more annoying, since the screen space itself in standard opengl is -z forward, +x right.
dark_sylinc wrote: a spot light in its default orientation is a cone facing towards +Z which matches a 3D modelling application)
Which modelling program? Both 3ds max and blender create default spotlights with no orientation set as facing downwards, which is -z in their coordinate systems and -y in ogre's. Maya uses the same (y up, right handed) coordinate system as ogre, and it's spotlights face -z.
0 x

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 4063
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 228
Contact:

Re: Something I should now about Lights ?

Post by dark_sylinc » Sun Jan 04, 2015 9:45 pm

Ok, we can change Lights to -Z forward.

Any motions against, in favour?
0 x

al2950
OGRE Expert User
OGRE Expert User
Posts: 1200
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 76

Re: Something I should now about Lights ?

Post by al2950 » Mon Jan 05, 2015 12:06 am

dark_sylinc wrote:Ok, we can change Lights to -Z forward.

Any motions against, in favour?
It makes sense to me to do that as that is the Ogre standard, however I am curious about your remarks about playing nicer with various algorithms...
0 x

N0vember
Gremlin
Posts: 196
Joined: Tue Jan 27, 2009 12:27 am

Re: Something I should now about Lights ?

Post by N0vember » Mon Jan 05, 2015 2:03 am

I guess consistency should prevail. -Z or Z is like indexing from 0 or 1, or left-handed vs right handed : you can argue for both but the most important is that it's consistent.
I wouldn't suddenly switch to the opposite except if only for internal use that has no influence on the user.

In the end, forward for a camera should be the same direction as for a light, or a mesh, or anything.
0 x

TheSHEEEP
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 972
Joined: Mon Jun 02, 2008 6:52 pm
Location: Berlin

Re: Something I should now about Lights ?

Post by TheSHEEEP » Mon Jan 05, 2015 10:22 am

N0vember wrote:: you can argue for both but the most important is that it's consistent.
Agreed.
0 x
My site! - Have a look :)
Also on Twitter - extra fluffy

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7147
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 16

Re: Something I should now about Lights ?

Post by Kojack » Mon Jan 05, 2015 11:43 am

Although we could always use this chance to switch Ogre over to left handed coordinates! Please?
(not going to happen, but I can dream)
0 x

Post Reply