Skip to content

Commit

Permalink
add fog feature setting initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrMrozik committed Sep 4, 2024
1 parent 135a298 commit 53564a9
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Assets/RGLUnityPlugin/Scripts/LidarFogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,24 @@ public class LidarFogManager : MonoBehaviour
[field: Tooltip("Enable/disable fog effect on devices.r")]
public bool IsFogEnabled { get; set; } = false;

[field: SerializeField]
[field: Tooltip("The attenuation coefficient for fog corresponding to amount of fog in the air")]
[field: Range(0.003f, 0.5f)]
public float AttenuationCoefficient { get; private set; } = 0.03f;

[field: SerializeField]
[field: Tooltip("TODO:")]
[field: Range(0.0f, 1.0f)]
public float r1 { get; private set; } = 0.001f;

[field: SerializeField]
[field: Tooltip("TODO:")]
[field: Range(1.0f, 10.0f)]
public float r2 { get; private set; } = 1.0f;

private void Awake()
{
if (!IsSnowFeatureAvailable())
if (!IsFogFeatureAvailable())
{
Debug.LogError("Loaded RGL plugin does not include support for Lidar Fog Model, removing component");
Destroy(this);
Expand Down Expand Up @@ -68,7 +83,7 @@ private void OnDisable()
OnNewConfig?.Invoke();
}

public bool IsSnowFeatureAvailable()
public bool IsFogFeatureAvailable()
{
return RGLNativeAPI.HasExtension(RGLExtension.RGL_EXTENSION_WEATHER);
}
Expand Down
11 changes: 11 additions & 0 deletions Assets/RGLUnityPlugin/Scripts/LidarFogManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Assets/RGLUnityPlugin/Scripts/LidarRainManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Assets/RGLUnityPlugin/Scripts/LidarSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class LidarSensor : MonoBehaviour
private const string toLidarFrameNodeId = "TO_LIDAR_FRAME";
private const string snowNodeId = "SNOW";
private const string rainNodeId = "RAIN";
private const string fogNodeId = "FOG";

private LidarModel? validatedPreset;
private float timer;
Expand Down Expand Up @@ -159,6 +160,14 @@ public void Start()
LidarRainManager.Instance.OnNewConfig += OnValidate;
}

if(LidarFogManager.Instance != null)
{
// Add deactivated node with some initial values. To be activated and updated when validating.
rglGraphLidar.AddNodePointsSimulateFog(fogNodeId, 0.03f, 0.1f, 1.0f);
rglGraphLidar.SetActive(fogNodeId, false);
LidarFogManager.Instance.OnNewConfig += OnValidate;
}

OnValidate();

if (doValidateConfigurationOnStartup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum RGLNodeType
PUBLISH_UDP_OBJECT_LIST,
POINTS_SIMULATE_SNOW,
POINTS_SIMULATE_RAIN,
POINTS_SIMULATE_FOG,
RAYTRACE,
GAUSSIAN_NOISE_ANGULAR_RAY,
GAUSSIAN_NOISE_ANGULAR_HITPOINT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ public static extern int rgl_node_points_simulate_snow(ref IntPtr node, float mi
public static extern int rgl_node_points_simulate_rain(ref IntPtr node, float min_range, float max_range, float rain_rate,
Int32 num_channels, float beam_divergence, bool simulate_energy_loss, Int32 numerical_threshold);

[DllImport("RobotecGPULidar")]
public static extern int rgl_node_points_simulate_fog(ref IntPtr node, float attenuationCoefficient, float r1, float r2);

[DllImport("RobotecGPULidar")]
public static extern int rgl_graph_run(IntPtr node);

Expand Down Expand Up @@ -636,6 +639,11 @@ public static void NodePointsSimulateRain(ref IntPtr node, float minRange, float
CheckErr(rgl_node_points_simulate_rain(ref node, minRange, maxRange, rainRate,numChannels, beamDivergence, doSimulateEnergyLoss, numericalThreshold));
}

public static void NodePointsSimulateFog(ref IntPtr node, float attenuationCoefficient, float r1, float r2)
{
CheckErr(rgl_node_points_simulate_fog(ref node, attenuationCoefficient, r1, r2));
}

public static void GraphRun(IntPtr node)
{
CheckErr(rgl_graph_run(node));
Expand Down
18 changes: 18 additions & 0 deletions Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNodeSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,17 @@ public RGLNodeSequence AddNodePointsSimulateRain(string identifier, float minRan
return this;
}

public RGLNodeSequence AddNodePointsSimulateFog(string identifier, float attenuationCoefficient, float r1, float r2)
{
CheckNodeNotExist(identifier);
RGLNodeHandle handle = new RGLNodeHandle();
RGLNativeAPI.NodePointsSimulateFog(ref handle.Node, attenuationCoefficient, r1, r2);
handle.Type = RGLNodeType.POINTS_SIMULATE_FOG;
handle.Identifier = identifier;
AddNode(handle);
return this;
}

public RGLNodeSequence AddNodeMultiReturnSwitch(string identifier, RGLReturnType returnType)
{
CheckNodeNotExist(identifier);
Expand Down Expand Up @@ -514,6 +525,13 @@ public RGLNodeSequence UpdateNodePointsSimulateRain(string identifier, float min
return this;
}

public RGLNodeSequence UpdateNodePointsSimulateFog(string identifier, float attenuationCoefficient, float r1, float r2)
{
RGLNodeHandle handle = ValidateNode(identifier, RGLNodeType.POINTS_SIMULATE_FOG);
RGLNativeAPI.NodePointsSimulateFog(ref handle.Node, attenuationCoefficient, r1, r2);
return this;
}

public RGLNodeSequence UpdateMultiReturnSwitch(string identifier, RGLReturnType returnType)
{
RGLNodeHandle handle = ValidateNode(identifier, RGLNodeType.MULTI_RETURN_SWITCH);
Expand Down

0 comments on commit 53564a9

Please sign in to comment.