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

Add Ogre2Heightmap functionality #386

Merged
merged 107 commits into from
Sep 20, 2021
Merged

Conversation

darksylinc
Copy link
Contributor

@darksylinc darksylinc commented Aug 24, 2021

🎉 New feature

Closes #187

Summary

This PR adds Terra samples' code and integrates it into Gazebo to provide Heightmap functionality.

It's yet missing the ability for terrain to cast shadows coming from spot and point lights (only directional lights cast terrain shadows onto everything). This feature will come later. The code is ready but integration with ign-rendering is not and due to time constraints (Fortress feature freeze) it's being submitted for review.

Note: All code under ogre2/src/terrain folder should be considered external code.

Test it

There are not many ways to test heightmap in Gazebo AFAIK. Build ign-rendering normally then:

  • Build ign-rendering/examples/heightmap
  • Run it

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge

ahcorde and others added 30 commits March 23, 2021 17:57
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
Co-authored-by: Michael Carroll <[email protected]>

Signed-off-by: ahcorde <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
…ardware gamma to fix dark sky color

Signed-off-by: Ian Chen <[email protected]>
* Local updates for Ogre2.2 against main branch

Signed-off-by: Ian Chen <[email protected]>
Co-authored-by: Ian Chen <[email protected]>
Signed-off-by: ahcorde <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>
@darksylinc
Copy link
Contributor Author

I merged with main and fixed the merge conflicts. However this now causes DCO check to fail

I've also updated to latest Hlms files to fix the compiler error when using shadow mapping; these files also add the missing support for HlmsPbs::setShadowReceiversInPixelShader (which fixes errors when too many shadow mapped lights are on the scene)

@mjcarroll
Copy link
Contributor

However this now causes DCO check to fail

It can be forced to pass in this case. It gets a little picky when merge commits and rebases happen.

@iche033
Copy link
Contributor

iche033 commented Sep 11, 2021

I pulled the latest changes and rebuilt the workspace and no more crashes!

I still get the same output as the one in: #386 (comment), and I verified that I have the fix. Let me know if you're able to reproduce it.

Signed-off-by: Matias N. Goldberg <[email protected]>
Update Terra to latest from upstream

Signed-off-by: Matias N. Goldberg <[email protected]>
@darksylinc
Copy link
Contributor Author

Thanks for the patch to test spot shadows. It was a Z-up issue.

It's now working!

Screenshot_2021-09-11_16-00-40

Terra's workspace listener was being executed before the camera is
rotated for cubemap rendering

Signed-off-by: Matias N. Goldberg <[email protected]>
@darksylinc
Copy link
Contributor Author

darksylinc commented Sep 11, 2021

Thanks to your patch I was able to notice point light shadows were not working properly due to a silly bug.

Fixed:
PointLights

BTW you might notice those "bright spots" at the bottom of the shadowed side of a mountain or cliffs:
PointLights02

These can be alleviated by messing with shadow bias and/or toggling Ogre::Root::getSingleton().getHlmsManager()->setShadowMappingUseBackFaces(false); however it will always be problematic (each fix causes another problem, usually bigger) until Ogre 2.3

That issue is fixed in Ogre 2.3 (it cannot be backported) as we implemented Normal-offset bias which results in much higher quality shadow mapping.

Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lights + shadows are working well for me now! Can you add the point light to the demo?

To get green builds, we'll need to suppress compile warnings coming from the terra directory. I think this works:

diff --git a/ogre2/src/terrain/Terra/CMakeLists.txt b/ogre2/src/terrain/Terra/CMakeLists.txt
index 7dbf9683..531a7763 100644
--- a/ogre2/src/terrain/Terra/CMakeLists.txt
+++ b/ogre2/src/terrain/Terra/CMakeLists.txt
@@ -12,6 +12,13 @@ if(IGN_ADD_fPIC_TO_LIBRARIES AND NOT _ign_add_library_INTERFACE)
   target_compile_options(${PROJECT_NAME} PRIVATE -fPIC)
 endif()
 
+target_compile_options(${PROJECT_NAME} PRIVATE
+    -Wno-unused-parameter
+    -Wno-float-equal
+    -Wno-sign-compare
+    -Wno-strict-aliasing)
+add_definitions(-DOGRE_IGNORE_UNKNOWN_DEBUG)

Can you address the remaining comments from @ahcorde?

: public BaseHeightmap<Ogre2Geometry>
{
/// \brief Constructor
public: explicit Ogre2Heightmap(const HeightmapDescriptor &_desc);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like Parameters that describe how a heightmap should be loaded. should suffice.

this is needed to fix: https://github.com/ignitionrobotics/ign-rendering/pull/386/checks?check_run_id=3576496054

public: virtual void PreRender() override;

/// \brief Returns NULL, heightmaps don't have movable objects.
/// \return Null pointer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true in ogre 1.x but looking at the Ogre2Heightmap::OgreObject() implementation, it returns an Ogre::Terra object. Can you update the comment here @darksylinc ?


/// \brief Returns NULL, heightmap materials don't inherit from
/// MaterialPtr.
/// \return Null pointer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, looks like still always returns null. Textures are specified through HeightmapDescriptor

vNormal += cross( (vNN - v00), (vN0 - v00) );
vNormal += cross( (vN0 - v00), (v01 - v00) );

// vNormal += cross( (v01 - v00), (v11 - v00) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file came from ogre-next samples. We can leave the comment here to minimize diff with upstream version.

@iche033
Copy link
Contributor

iche033 commented Sep 13, 2021

BTW you might notice those "bright spots" at the bottom of the shadowed side of a mountain or cliffs:

ok that's fine. We'll likely play with different bias values if needed, which is what we've done in the past but it was always hard to find something that works for all cases.

darksylinc and others added 6 commits September 15, 2021 12:26
Silence warnings from external code to pass build checks

Signed-off-by: Matias N. Goldberg <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
Signed-off-by: Ian Chen <[email protected]>
@iche033
Copy link
Contributor

iche033 commented Sep 16, 2021

I made some changes in the iche033/ogre22-terra branch to fix windows and homebrew CI builds:
https://github.com/ignitionrobotics/ign-rendering/compare/260255b53bb98ca4a68304e911ee821c2e509692..bb0119bb396ac8a432fa4b0d18ef8046ddf0c962

If that looks good to you, can you merge with that branch? That should make CI green.

@darksylinc
Copy link
Contributor Author

I made some changes in the iche033/ogre22-terra branch to fix windows and homebrew CI builds:
https://github.com/ignitionrobotics/ign-rendering/compare/260255b53bb98ca4a68304e911ee821c2e509692..bb0119bb396ac8a432fa4b0d18ef8046ddf0c962

If that looks good to you, can you merge with that branch? That should make CI green.

All good. Changes pushed.

Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI looks good.

I'll address a couple of small style comments in a separate PR.

Need to get this in for pre-release

@iche033 iche033 dismissed ahcorde’s stale review September 20, 2021 20:50

will address remaining comments in a separate PR.

@iche033 iche033 merged commit b2da7e1 into gazebosim:main Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta Targeting beta release of upcoming collection 🏯 fortress Ignition Fortress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants