Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StaticGeometry gets double the Root SceneNode transform #2510

Open
chillywillysoft opened this issue Jul 6, 2022 · 9 comments
Open

StaticGeometry gets double the Root SceneNode transform #2510

chillywillysoft opened this issue Jul 6, 2022 · 9 comments
Labels
Known Issues easy workaround exists or too intrusive to fix right away

Comments

@chillywillysoft
Copy link
Contributor

System Information

  • Ogre Version: 13.4.1
  • Operating System / Platform: macOS Catalina
  • RenderSystem: OpenGL

Detailled description

When StaticGeometry is created using StaticGeometry::addSceneNode(), each Entity is queued along with its derived transform. That bakes the Root SceneNode's transform into the geometry. Then when StaticGeometry::build() calls Region::build(), it creates its Node as a child of the Root SceneNode. This results in the Root SceneNode's transform being applied twice.

Not sure best way to fix:

  1. Straightforward: In StaticGeometry::addSceneNode(), instead of calling _getDerivedPosition() (etc) we manually derive from a child of Root.
  2. Tricky: Use _getDerivedPosition() (etc) but then subtract or divide away the Root's transform.
  3. Ugly: Save the Root's transform, set it to identity, call _getDerivedPosition() (etc), then restore the Root's transform.
@paroj
Copy link
Member

paroj commented Jul 6, 2022

how about setting Matrix4::IDENTITY here:

*xform = mParent->getParent()->getParent()->_getParentNodeFullTransform();

@chillywillysoft
Copy link
Contributor Author

chillywillysoft commented Jul 7, 2022

I'm not sure if I understand. I'm not familiar with the getWorldTransforms() function but I'm only seeing it being called from BillboardSet and AutoParamDataSource. Would that get called while creating the StaticGeometry or while rendering it?

If while rendering, then it would ignore the Root Node's current transform and only use what was baked in. If the transform on the Root node changes after the StaticGeometry is made, it would not track with the rest of the Scene.

While creating the the StaticGeometry, StaticGeometry::addSceneNode() calls Node::_getDerivedPosition(), Node::_getDerivedOrientation(), and Node::_getDerivedScale()), all of which (may) call _updateFromParent() and it recurses up the tree.

@paroj
Copy link
Member

paroj commented Jul 7, 2022

If while rendering, then it would ignore the Root Node's current transform and only use what was baked in.

yes, this.

If the transform on the Root node changes after the StaticGeometry is made, it would not track with the rest of the Scene.

thats kind of the premise of StaticGeometry. If any intermediate node changes, StaticGeometry would not reflect that either

@chillywillysoft
Copy link
Contributor Author

chillywillysoft commented Jul 7, 2022

thats kind of the premise of StaticGeometry. If any intermediate node changes, StaticGeometry would not reflect that either

Fair enough. Can we avoid applying any transforms at all while rendering or do we have to pass something to the GPU? Out of curiosity can you point me to the rendering code that calls getWorldTransforms()? I haven't been able to find it.

@paroj
Copy link
Member

paroj commented Jul 7, 2022

what your write from that function gets almost directly passed to the GPU - e.g. here:

_writeRawConstant(i->physicalIndex, source->getWorldMatrix(),i->elementCount);

@chillywillysoft
Copy link
Contributor Author

I see, thank you.

Returning Matrix4::IDENTITY from getWorldTransforms() sounds good for rendering.

What about culling? Will it still use the Root node's transform while culling?

@paroj
Copy link
Member

paroj commented Jul 9, 2022

What about culling? Will it still use the Root node's transform while culling?

Yes. I dont know all the paths that culling takes off the top of my head. Overriding _notifyCurrentCamera will disable culling by the far plane altogether.
There are also aab and bounding sphere tests though. We should not just disable culling. The individual StaticGeometry Regions should still be culled. Also they need the correct camera distance for LOD AFAIR

@paroj
Copy link
Member

paroj commented Jul 11, 2022

given that transforms on the root scene node have no observable effect, I am inclined to just warn about this now and ignore any root scene node transform in a future release.

Did you have any particular reason to do that transform?

@chillywillysoft
Copy link
Contributor Author

chillywillysoft commented Jul 11, 2022

My models use negative Y as up so I was using the same convention with the lights and cameras in the Scene. Then I integrated the recast/detour library and it assumes positive Y as up so as a quick and easy way to have the coordinates match, I just rotated the Root. But I can just flip things over when I set up the scene. I agree with you, I think it would make more sense if the Root node could NOT be transformed.

@paroj paroj added the Known Issues easy workaround exists or too intrusive to fix right away label Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Known Issues easy workaround exists or too intrusive to fix right away
Projects
None yet
Development

No branches or pull requests

2 participants