POSIM v1.0.1Platform for Ocean Simulation · Documentation
Documentation menu
POSIM / Plugin reference

Underwater camera

The UnderwaterCamera plugin uses depth data to reduce RGB color intensity with distance. Adjust attenuation and background color to match the water conditions you want to simulate. For scene-wide haze, absorption, caustics, suspended specks (marine snow), seabed grids and live controls, use the public underwater scene renderer.

Run the example

The camera tutorial enables gentle waves and native underwater scene effects. The sensor launch sets POSIM_UNDERWATER_PLUGIN so the compatibility image output passes through the shaded RGB pixels without applying attenuation twice. To compare the separate depth-based filter, use a world without the native system and leave that environment variable unset.

Run the example in prepared Terminal A.

ros2 launch posim_demos posim_sensor.launch.py \
  namespace:=underwater_camera world_name:=camera_tutorial \
  x:=10 z:=-93.5 pitch:=0.3 yaw:=3.14 \
  paused:=false gui:=true headless:=false

In the prepared terminal B:

ros2 topic echo /underwater_camera/simulated_image \
  sensor_msgs/msg/Image --once --no-arr
ros2 topic hz /underwater_camera/simulated_image

Use an RViz Image display to inspect the resulting image. If the topic is discovered but images stop arriving, check large-image transport.

Configure the plugin

The model uses an RGBD sensor and the plugin UnderwaterCamera, class posim_gz_sensor_plugins::UnderwaterCamera. Keep its sensor/data topics consistent with the model configuration.

Place this sensor inside a model <link>. The world also needs gz-sim-sensors-system with <render_engine>ogre2</render_engine>, as in the camera world. The plugin reads Gazebo RGB/depth images and directly publishes the ROS output /underwater_camera/simulated_image.

<sensor name="underwater_camera" type="rgbd_camera">
  <update_rate>10</update_rate>
  <topic>underwater_camera</topic>
  <camera>
    <horizontal_fov>1.05</horizontal_fov>
    <image><width>320</width><height>240</height></image>
    <clip><near>0.1</near><far>10.0</far></clip>
  </camera>
  <plugin filename="UnderwaterCamera"
          name="posim_gz_sensor_plugins::UnderwaterCamera">
    <attenuationR>0.8</attenuationR>
    <attenuationG>0.5</attenuationG>
    <attenuationB>0.2</attenuationB>
    <backgroundR>85</backgroundR>
    <backgroundG>107</backgroundG>
    <backgroundB>47</backgroundB>
  </plugin>
</sensor>
SDF parameter Meaning Code default
attenuationR Red-channel attenuation per meter, finite and ≥ 0 1/30
attenuationG Green-channel attenuation per meter, finite and ≥ 0 1/30
attenuationB Blue-channel attenuation per meter, finite and ≥ 0 1/30
backgroundR Red background channel, integer 0–255 0
backgroundG Green background channel, integer 0–255 0
backgroundB Blue background channel, integer 0–255 0

Image topics and camera geometry

The sensor's <topic> must produce a valid ROS topic name. Omitting it uses Gazebo's /world/<world>/model/<model>/link/<link>/sensor/<sensor> scope; the ROS image is published below that scope at /simulated_image. Nested models add their parent model scopes.

Depth-to-range conversion uses an explicit camera lens projection when supplied, then explicit lens intrinsics, otherwise image dimensions and horizontal field of view. Explicit zero principal-point coordinates are valid. Focal lengths must be positive, lens values must be finite, and clipping distances must satisfy 0 < near < far in meters. Invalid settings produce a log error and disable the plugin's output.

Frame timing and example values

Color and depth frames are paired by their acquisition timestamp, whichever arrives first. Each ROS image preserves the color frame's timestamp and frame ID. Unmatched frames are discarded when the pending buffer fills; resetting simulation time clears pending frames and allows timestamps to restart.

The example model uses these values. SDF settings override code defaults.

Tune and compare

Place a recognizable object at known distances. Keep pose, lighting, scene materials and camera settings fixed while changing one attenuation channel. Verify image timestamps and received rate in addition to the visual result.

Camera-specific attenuation changes the sensor image. Use the scene renderer to apply shared underwater effects to PBR surfaces in scene and camera views. When that native system is active, POSIM_UNDERWATER_PLUGIN enables pass-through in this compatibility output to avoid filtering the same pixels twice. The camera model defines input wiring and output names.

Configure RGBD sensing and water appearance

The RGBD sensor supplies color and depth images. The plugin uses depth-derived range, per-channel attenuation and background values to produce underwater imagery. Attenuation follows a per-channel exponential model; background channels range from 0 to 255.

For an unattenuated comparison, explicitly set attenuationR, attenuationG, attenuationB and all three background values to zero. For murky coastal water, use the example values 0.8/0.5/0.2 and 85/107/47 above. Omitting tags uses the code defaults.

This sensor implements distance-dependent RGB attenuation and background blending. The scene renderer supplies visual sunlight, caustics and optional suspended specks. Studies of calibrated particle scattering need a suitable optical model beyond these visual approximations.

Suspended particles

The native renderer can show suspended specks in RGB and RGBD color images. Specks are off by default. Enable them through the renderer's appearance service.

Particles occupy shared positions in the world and drift uniformly with simulation time. Different camera views observe the same positions at the same time. Opaque surfaces hide particles behind them. The visible interval is 0.05–3 m, clipped by the scene and the mean water level. Numeric depth and acoustic rays retain their values.

This is a procedural optical effect. Its drift is independent of simulated currents. When evaluating visual navigation, treat suspended particles as moving observations and keep appearance settings fixed across comparisons.

Compare underwater images

Gazebo underwater-camera scene
Gazebo underwater-camera scene
Underwater-camera image display
Underwater-camera image display
Image with zero RGB attenuation and zero background
Image with zero RGB attenuation and zero background
Murky coastal image: RGB attenuation 0.8/0.5/0.2 and background 85/107/47
Murky coastal image: RGB attenuation 0.8/0.5/0.2 and background 85/107/47

Figures and videos: POSIM Notion Wiki. See Citation and licenses for DAVE documentation attribution. Use this page's code blocks for execution commands and topic names.