srmainwaring / asv_wave_sim

This package contains plugins that support the simulation of waves and surface vessels in Gazebo.
GNU General Public License v3.0
118 stars 32 forks source link

Migrate to Ignition Gazebo #15

Closed srmainwaring closed 2 years ago

srmainwaring commented 2 years ago

New Feature

This issue is to track the migration of the wave simulation and hydrodynamics plugins to Ignition (Garden).

Desired behaviour

The wave visuals and physics behaviour are available in Ignition using the ogre2 render engine. There should be support for both Linux and macOS (the latter using Metal graphics API).

Implementation suggestion

The model and visual plugins from legacy Gazebo will be replaced with system plugins in Ignition. As before three plugins are required:

wave visuals

The wave visuals are perhaps the most challenging change as they require migration to the Ogre2 render engine and integration into the ignition-rendering framework. As with legacy Gazebo, there is no direct support for modifying meshes at run time, with the exception perhaps of the DynamicRenderable objects for Ogre and Ogre2 which sit outside the main mesh frameworks from ignition-common and ignition-rendering.

The proposed approach is to first create visuals for a static wave field, which can be done staying within the available mesh and rendering framework and will use the vertex generation from the existing OceanTile. Static waves will allow the following to be migrated:

Other changes

The migration to Ignition requires such a significant change, it could be regarded as a complete reworking of the library. Other changes that may be included as sub-issues are:

Progress

srmainwaring commented 2 years ago

Progress

This section will be periodically updated to track progress on this issue.

wave visuals

WIP on branch https://github.com/srmainwaring/asv_wave_sim/tree/feature/ign-garden-wip

Initial version of static FFT generated waves:

ign-static-fftw

Update 1

Investigated a number of options for dynamic meshes in Ignition with the Ogre2 render engine

https://user-images.githubusercontent.com/24916364/153723312-d753c838-ef08-49c2-a39c-765117b957b8.mov

Update 2

Single OceanTile with dynamic FFT waves and averaged normals using a modified version of rendering::Ogre2DynamicRenderable as described above. Plenty of scope for increased efficiency in the implementation, but even an initial version is running acceptably well.

https://user-images.githubusercontent.com/24916364/153761799-449e933d-86fd-4b1f-b064-f38818195f85.mov

Update 3

wave shaders

Ignition Garden has support for custom shaders using the ShaderParam system plugin for the <visual> element. However it turns out that only one plugin is processed from the <visual> element (multiple may be specified, but only one is loaded).

There are a number of places where changes are required. The following may not be exhaustive:

A proper solution is to modify ignition-gazebo to support multiple visual plugin elements. In the interim a work-around is to re-implement the ShaderParams logic in the Wave system plugin.

Fix-it list

Update 4

A number of changes in order to support PBS materials. Custom shaders are still not working, but improved visuals are available using PBS materials which supply the bump map and environment map (the mixture of shallow and deep colours is not available with this approach).

https://user-images.githubusercontent.com/24916364/154754258-d1fa28dc-d86f-4d79-8a96-672b5d74c8c9.mov

Next Steps

srmainwaring commented 2 years ago

Initial working version

There are initial versions of all three plugins which allow objects of various shapes to interact with the wave field. There is much to be improved, but the bulk of the conceptual work required to migrate to Ignition is in place.

ign-marine-various-v1

waves model plugin

The waves model system plugin holds a wavefield object and its parameters. The entity component system makes it simpler to manage these objects than in legacy Gazebo. A new component for the wavefield is used to store a weak pointer to the wavefield and then this is registered with a new entity. It can then be retrieved by name from the ECM.

This approach appears to work quite well, and eliminates the need for a separate wavefield entity object derived from the physics base model.

Outstanding tasks

hydrodynamics plugin

The hydrodynamics system plugin is also substantially reworked from the original. It uses the ECM to retrieve the wavefield component registered by the wave model plugin. The collision shapes are obtained from the collision component using the same approach used in the buoyancy system plugin.

Outstanding tasks

srmainwaring commented 2 years ago

Scaling to larger environments

https://user-images.githubusercontent.com/24916364/157044239-2d9ac4e2-746d-4824-b990-a5908a1e831b.mov

For larger models (ships) the ocean will need to be scaled accordingly, while retaining sufficient detail to make the local wave field interesting. Investigate the following:

Some of the ideas listed above are investigated in this ogre-next branch: ogre-next - feature/v2-2-osrf-mac-ocean-compute2

Using textures to store the displacement, normal and tangent maps the trochoid wave example may be extended to a 10km x 10km region using 512m x 512m tiles. In this example the textures are updated in CPU and uploaded to GPU. The underlying vertex structure is a 128 x 128 segment Ogre plane repeated 2*10+1 times in each direction (i.e. 441 tiles).

ogre-next-trochoid-texmaps

https://user-images.githubusercontent.com/24916364/158489622-61f3901b-17a5-4e11-8c39-56b0ca7d45e4.mov

srmainwaring commented 2 years ago

FFT generated wave textures with 256m x 256m tiles and 200 x 200 grid segments using 256 x 256 FFT samples. There are some repetition artefacts which are mitigated to some extent by the tile size and viewpoint.

https://user-images.githubusercontent.com/24916364/169540114-8922989e-d9f0-445b-a75f-1907fdc1ac14.mov

srmainwaring commented 2 years ago

Closing as the main aspects of the initial migration have been dealt with in the following PRs: #16, #18, #19, #23, #24, #25, #26, #27, #28, #29, #31, #32, #33, #34, #36, #37, #38, #39, #40