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 16, 2024
1 parent 994a6ce commit f745b0d
Show file tree
Hide file tree
Showing 7 changed files with 88 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 @@ -94,6 +94,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 @@ -186,6 +186,9 @@ public static extern int rgl_node_points_simulate_snow_configure_defaults(IntPtr
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 @@ -662,6 +665,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
31 changes: 31 additions & 0 deletions Assets/RGLUnityPlugin/Scripts/LowLevelWrappers/RGLNodeSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,30 @@ public RGLNodeSequence AddNodePointsSimulateSnow(string identifier, float minRan
return this;
}

public RGLNodeSequence AddNodePointsSimulateRain(string identifier, float minRange, float maxRange, float rainRate,
Int32 numChannels, float beamDivergence, bool doSimulateEnergyLoss, Int32 numericalThreshold)
{
CheckNodeNotExist(identifier);
RGLNodeHandle handle = new RGLNodeHandle();
RGLNativeAPI.NodePointsSimulateRain(ref handle.Node, minRange, maxRange, rainRate,
numChannels, beamDivergence, doSimulateEnergyLoss, numericalThreshold);
handle.Type = RGLNodeType.POINTS_SIMULATE_RAIN;
handle.Identifier = identifier;
AddNode(handle);
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;
}

//// UPDATE NODES ////
public RGLNodeSequence UpdateNodeRaysFromMat3x4f(string identifier, Matrix4x4[] rays)
{
Expand Down Expand Up @@ -488,6 +512,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 UpdateNodePointsSnowDefaults(string identifier, int snowflakesId, float fullBeamIntensity, float snowflakesLaserRetro)
{
RGLNodeHandle handle = ValidateNode(identifier, RGLNodeType.POINTS_SIMULATE_SNOW);
Expand Down

0 comments on commit f745b0d

Please sign in to comment.