-
Notifications
You must be signed in to change notification settings - Fork 52
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
Use clipping distance for minimum LIDAR distance #365
Use clipping distance for minimum LIDAR distance #365
Conversation
Using Hlms custom pieces and a listener to implement it See changes to Ogre2GpuRays::Render for usage Update ogre2/src/media/Hlms/Pbs/GLSL/VertexShader_vs.glsl to latest upstream version Signed-off-by: Matias N. Goldberg <[email protected]>
da879bb
to
acdfd09
Compare
Codecov Report
@@ Coverage Diff @@
## lidar_near_clip #365 +/- ##
===================================================
+ Coverage 58.15% 58.30% +0.14%
===================================================
Files 170 172 +2
Lines 16790 16852 +62
===================================================
+ Hits 9764 9825 +61
- Misses 7026 7027 +1
Continue to review full report at Codecov.
|
@@ -612,6 +616,10 @@ void Ogre2RenderEngine::CreateResources() | |||
|
|||
Ogre::ArchiveManager &archiveManager = Ogre::ArchiveManager::getSingleton(); | |||
|
|||
Ogre::Archive *customizationsArchiveLibrary = | |||
archiveManager.load( rootHlmsFolder + "Hlms/Ignition", "FileSystem", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the path please use common::JoinPath()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -631,13 +639,16 @@ void Ogre2RenderEngine::CreateResources() | |||
++libraryFolderPathIt; | |||
} | |||
|
|||
archiveUnlitLibraryFolders.push_back( customizationsArchiveLibrary ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
archiveUnlitLibraryFolders.push_back( customizationsArchiveLibrary ); | |
archiveUnlitLibraryFolders.push_back(customizationsArchiveLibrary); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -661,12 +672,15 @@ void Ogre2RenderEngine::CreateResources() | |||
++libraryFolderPathIt; | |||
} | |||
|
|||
archivePbsLibraryFolders.push_back( customizationsArchiveLibrary ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
archivePbsLibraryFolders.push_back( customizationsArchiveLibrary ); | |
archivePbsLibraryFolders.push_back(customizationsArchiveLibrary); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (size_t i = 0; i < 16u; ++i) | ||
*_passBufferPtr++ = static_cast<float>(invViewProj[0][i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (size_t i = 0; i < 16u; ++i) | |
*_passBufferPtr++ = static_cast<float>(invViewProj[0][i]); | |
for (size_t i = 0; i < 16u; ++i) | |
{ | |
*_passBufferPtr++ = static_cast<float>(invViewProj[0][i]); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -163,6 +164,9 @@ namespace ignition | |||
/// \return a list of FSAA levels | |||
public: std::vector<unsigned int> FSAALevels() const; | |||
|
|||
/// \brief Retrieves Hlms customizations for tweaking them | |||
public: Ogre2IgnHlmsCustomizations& HlmsCustomizations(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: put &
next to variable, i.e. Ogre2IgnHlmsCustomizations &HlmsCustomizations();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_hlms->_setProperty( "ign_spherical_clip_min_distance", 1 ); | ||
_hlms->_setProperty( "ign_spherical_clip_idx", numClipPlanes ); | ||
_hlms->_setProperty( "hlms_pso_clip_distances", numClipPlanes + 1 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_hlms->_setProperty( "ign_spherical_clip_min_distance", 1 ); | |
_hlms->_setProperty( "ign_spherical_clip_idx", numClipPlanes ); | |
_hlms->_setProperty( "hlms_pso_clip_distances", numClipPlanes + 1 ); | |
_hlms->_setProperty("ign_spherical_clip_min_distance", 1); | |
_hlms->_setProperty("ign_spherical_clip_idx", numClipPlanes); | |
_hlms->_setProperty("hlms_pso_clip_distances", numClipPlanes + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After doing more testing I think this almost fixes the issue found in #356 (comment). The only problem left is that as soon as I rotate the robot to something other than multiple of 90 degrees, the sensor's view become occluded in the same way described in gazebosim/gz-sensors#128. My guess is that it's an object culling issue based on axis aligned bounding box. @darksylinc do you have any insights? I think near clipping is working so we can merge this first if you think gazebosim/gz-sensors#128 is a separate issue. |
I saw you made a new commit after this msg, so perhaps you've already solved it. As for the problem you're describing (starts breaking when rotated) I can think of 4 reasons:
But this is what's actually happening (or any variation of it):
Probably the best way to see this is to take a RenderDoc capture of 0°, 45°, 90° and compare them drawcall by drawcall to see where they diverge. Although RenderDoc capture should be done in ign-rendering5 which is where we fixed the race condition bug (without the fix RenderDoc in the capture calls are all out of order or messed up) |
I just noticed he said:
Please note my camera changes were made to Ogre2GpuRays, not to Ogre2ThermalCamera. However it can be activated for Ogre2ThermalCamera as well. |
I can confirm @iche033 's observations - axis-aligned robots render the cloud correctly, but rotated do not. This is what I get with a rotated MARV - I haven't seen this kind of behavior before. |
I'm relatively new: how do I test rotated vs non rotated? |
If you open Ignition Gazebo GUI, there is a plugin called Transform tools, and that one has the rotate tool. Click the robot and turn the ring to rotate the robot. You can view the pointclouds in Ignition Gazebo GUI using the Visualize Lidar plugin, but if you turn it on for one of these high-density 3D lidars, performance suffers a lot. It's best to first choose the "Points" type of visualization and only after that select the lidar topic. Or, if you're testing using the SubT challenge simulator, just launch |
I created a minimal example world for testing: near_clip.sdf
|
THIS IS PRELIMINARY, I'M STILL RESEARCHING OK so I was off to a bad start because this is the output I see on the GUI. Fortunately the bug still repros on the server so it doesn't actually affect my work: So I tried RenderDoc on the server (after a couple minor mods so that RenderDoc capture works with ign-rendering4 in server mode) The "bad" version (i.e. rotated) is rendering 3 objects while the "good" version only renders 1 object:
It's also curious why Ogre submits it to the GPU when 45°, but not at 0° Next steps
|
Oh btw the patch to add RenderDoc support to server mode is this quick hack (do not push it to production!)
|
OK the 3rd "invalid geometry" mesh mystery has been revealed.
Because its part of the sensor geometry, if Ogre submits the geometry it will also submit the line. And if the sensor should not be submitted, the line will also not be submitted. |
RenderSystem::setClipPlanes is a legacy function that no one is using. However setClipPlanes would get called because mClipPlanesDirty starts as true; which causes a lot of problems (e.g. see gazebosim/gz-rendering#365) Proper depth clamp support was added in Ogre 2.3 Not using depth clamp is consistent with all other RenderSystems anyway
Well... this was FUN! (no sarcasm, it was fun) Short version:
(*) However I'd recommend an update at some point, since who knows what other side effects forcing depth clamping does (probably only manifest in edge cases like this one). Long version:Several things going on. Why does Ogre not submit the sensor geometry to GPU at 0°?Because it fails the frustum test. With the near plane at 0.06 and the lidar's AABB being in range [-0.037; 0.037], the lidar is well behind the near plane: However Ogre simplifies calculations by working with AABBs, not Oriented Bounding Boxes. When rotating an object by 45°, we use the AABB the encloses the rotated object. This means that its AABB gets bigger when rotated, and gets smaller again when getting close to being aligned to 0/90/180/270°: When the object is at 45°, its AABB is bigger, and now this is already enough to pass the frustum test: But let's remember that AABB is bigger but still aligned (never rotated), but the frustum is rotated. Hence this is the actual representation of the test: It's more than enough to pass frustum test and Ogre sends the geometry to GPU. IIRC this math simplification was there in Ogre 1.x too (the code is vastly different though). But it's possible small details change and the observable behavior ends up being different. This part so far is working as intended. If I edit Ogre to remove the frustum test completely (i.e always pass), then the buggy behavior happens at all orientations. Why is the object on screen blocking the lidar?Because Ogre 2.1 is incorrectly activating depth clamp. Very old legacy code meant for v1 objects,
SolutionsAny of the following will fix it:
|
Needs Ogre 2.1 update to actually take effect The `num_clip_distances` keyword will otherwise be ignored Signed-off-by: Matias N. Goldberg <[email protected]>
OK I pushed the fix. There's good and bad news:
Unfortunately I forgot shaders had to inform they need to use gl_ClipDistance and low level materials did not have such interface. A solution without an Ogre 2.1 update would need us to switch from using low level materials to an Hlms implementation (or overriding Pbs & Unlit). While this may be more ideal for performance and flexibility (i.e. the current solution being used is ignoring skeletal animations), that requires more time, analysis, testing and could potentially break ABI or other stuff. This is something we could discuss for Fortress. Hence an update to Ogre 2.1 was the quickest path. |
OK the triangle soup is a locale problem when parsing the DAE. I have to check if gazebosim/gz-common#120 was applied, and if so, why it's not working. I'll take a look |
No, the PR you refer to is declined. I can confirm that with Dome, the locale issues are still there. |
Oh! Great point! Thanks! That explains the issue. |
thanks for digging deep into this and coming up with a fix! Given that this requires an ogre update, we decided that we'll have to retarget this fix to the Fortress branch (currently
Let's hold off on doing this. I'm inclined to keep the low level material implementation as it's fairly stable and we'll soon be preparing for the Fortress release. I've just retargeted my branch to |
Increasing the clip distance will only work if it's big enough so that frustum culling prevents Ogre from sending the object to GPU. Otherwise the GPU won't correctly clip the geometry due to depth clamp incorrectly activated Alternative solutions:
|
I'm not sure what you're asking? What is it that I need to confirm? The HlmsListener probably had a few interface changes so the overloaded virtuals may 'just work', or warn that we're overriding a non-virtual function (because the argument signature changed slightly), or error that there's a pure virtual function. |
ah I was mainly thinking of the changes in the material and shader files, e.g. the addition of |
Signed-off-by: Matias N. Goldberg <[email protected]>
I've merged with main branch. I checked the code regarding the use of |
I'll take care of @ahcorde's comments in my branch |
I applied the patch on top of our ogre 2.x fork and tested with the minimal example world, near_clip.sdf The lidar point clouds now look consistent at different angles. |
* Use clipping distance for minimum LIDAR distance Using Hlms custom pieces and a listener to implement it See changes to Ogre2GpuRays::Render for usage Update ogre2/src/media/Hlms/Pbs/GLSL/VertexShader_vs.glsl to latest upstream version Signed-off-by: Matias N. Goldberg <[email protected]> * Add gl_ClipDistance to low level material that needed it Needs Ogre 2.1 update to actually take effect The `num_clip_distances` keyword will otherwise be ignored Signed-off-by: Matias N. Goldberg <[email protected]>
Using Hlms custom pieces and a listener to implement it
See changes to Ogre2GpuRays::Render for usage
Update ogre2/src/media/Hlms/Pbs/GLSL/VertexShader_vs.glsl to latest
upstream version
Signed-off-by: Matias N. Goldberg [email protected]
🦟 Bug fix
Summary
As discussed in #356 this implements Hlms custom pieces so that LIDAR can clip correctly without the undesired side effects of pushing the near clip plane closer.
I forgot to ask for an actual test; so I did not test whether the solution does the intended job; however I'm very confident it should.
I was able to test though, that the code works by forcing it to clip on regular view
Ogre2IgnHlmsCustomizations
is purposely not intended to be exposed to the user. This class could vary too much between updates (including new Ogre releases; although we try to avoid changes for patch releases) and trying to maintain ABI compatibility would be hell.Also a user trying to mess with
Ogre2IgnHlmsCustomizations
could potentially fiddle too much with low level workings of rendering. Hence it's best to not expose it at all.Usage
Use:
To enable it.
After rendering, you can use the following to disable the feature (any negative value works):
A value of 0 will keep the feature enabled but won't make any visible effect. The reason for this behavior (i.e. why doesn't 0 disable the feature?) is that when the feature is toggled on/off for a given pass then new shaders may be generated, causing stutter or performance problems (and higher RAM consumption).
Keeping the feature enabled at minDistanceClip = 0 lowers the chance of useless shader generation; and I suspect it could happen during UI editing (e.g. when sliding a value between a 0 and a max range)
Problem
UPDATE: This problem has been fixed. Living the comments for history's sake. Scroll to bottom to find the solution. This PR is ready for review
This is currently a DRAFT because marking the code like the following:
results in a runtime crash:
Which c++filt translates to:
No matter what I do I can't seem to fix the problem unless I add a Ogre2IgnHlmsCustomizations member to a public API e.g.
But I can't do that because that'd break ABI (and is also unnecessary).
So far I had to workaround this problem via:
Note that
IGNITION_RENDERING_OGRE2_HIDDEN
orIGNITION_RENDERING_OGRE2_VISIBLE
doesn't seem to make a difference.With my workaround INTEGRATION_versioned_symbols_ogre2 is now obviously failing.
Help is appreciated on how to resolve this problem because I'm out of ideas.
Other than that, the code should be functional and working, hopefully solving the intended problem
OMG I FOUND THE PROBLEM:
Some times IGNITION_RENDERING_VERSION_NAMESPACE is a macro, sometimes it's not. So the actual symbol ends up as
ignition::rendering::IGNITION_RENDERING_VERSION_NAMESPACE::Ogre2IgnHlmsCustomizations
instead ofignition::rendering::v4::Ogre2IgnHlmsCustomizations
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge