diff --git a/Assets/Scripts/DevicePlugins/MultiCameraPlugin.cs b/Assets/Scripts/DevicePlugins/MultiCameraPlugin.cs index caa89b0a..102b487b 100644 --- a/Assets/Scripts/DevicePlugins/MultiCameraPlugin.cs +++ b/Assets/Scripts/DevicePlugins/MultiCameraPlugin.cs @@ -45,7 +45,7 @@ void OnDestroy() private void Sender() { - Stopwatch sw = new Stopwatch(); + var sw = new Stopwatch(); while (true) { if (cam == null) diff --git a/Assets/Scripts/Devices/Camera.cs b/Assets/Scripts/Devices/Camera.cs index 43323e04..a76e9cb9 100644 --- a/Assets/Scripts/Devices/Camera.cs +++ b/Assets/Scripts/Devices/Camera.cs @@ -136,6 +136,8 @@ private void SetupCamera() cam.allowHDR = true; cam.allowMSAA = false; + cam.allowDynamicResolution = true; + cam.useOcclusionCulling = true; cam.targetDisplay = 0; cam.stereoTargetEye = StereoTargetEyeMask.None; diff --git a/Assets/Scripts/Devices/Lidar.cs b/Assets/Scripts/Devices/Lidar.cs index 1c283ab4..18887db1 100644 --- a/Assets/Scripts/Devices/Lidar.cs +++ b/Assets/Scripts/Devices/Lidar.cs @@ -45,7 +45,7 @@ public partial class Lidar : Device public Color rayColor = new Color(1, 0.1f, 0.1f, 0.2f); private Transform lidarLink = null; - private UnityEngine.Camera laserCamera = null; + private UnityEngine.Camera laserCam = null; private Material depthMaterial = null; private const float defaultRotationOffset = 90.00000000000000f; @@ -86,9 +86,9 @@ protected override void OnAwake() protected override void OnStart() { - laserCamera = gameObject.AddComponent(); + laserCam = gameObject.AddComponent(); - if (laserCamera) + if (laserCam) { SetupLaserCamera(); @@ -135,22 +135,24 @@ private void SetupLaserCamera() var shader = Shader.Find("Sensor/Depth"); depthMaterial = new Material(shader); - laserCamera.backgroundColor = Color.white; - laserCamera.clearFlags = CameraClearFlags.SolidColor; - laserCamera.depthTextureMode = DepthTextureMode.Depth; - laserCamera.cullingMask = LayerMask.GetMask("Default"); + laserCam.backgroundColor = Color.white; + laserCam.clearFlags = CameraClearFlags.SolidColor; + laserCam.depthTextureMode = DepthTextureMode.Depth; + laserCam.cullingMask = LayerMask.GetMask("Default"); - laserCamera.allowHDR = true; - laserCamera.allowMSAA = false; - laserCamera.renderingPath = RenderingPath.DeferredLighting; - laserCamera.stereoTargetEye = StereoTargetEyeMask.None; + laserCam.allowHDR = true; + laserCam.allowMSAA = false; + laserCam.allowDynamicResolution = true; + laserCam.useOcclusionCulling = true; + laserCam.renderingPath = RenderingPath.DeferredLighting; + laserCam.stereoTargetEye = StereoTargetEyeMask.None; - laserCamera.orthographic = false; - laserCamera.nearClipPlane = (float)rangeMin; - laserCamera.farClipPlane = (float)rangeMax; + laserCam.orthographic = false; + laserCam.nearClipPlane = (float)rangeMin; + laserCam.farClipPlane = (float)rangeMax; var projMatrix = DeviceHelper.MakeCustomProjectionMatrix(laserCameraHFov, laserCameraVFov, (float)rangeMin, (float)rangeMax); - laserCamera.projectionMatrix = projMatrix; + laserCam.projectionMatrix = projMatrix; var renderTextrueWidth = Mathf.CeilToInt(laserCameraHFov / laserHAngleResolution); var aspectRatio = Mathf.Tan(laserCameraVFov / 2 * Mathf.Deg2Rad) / Mathf.Tan(laserCameraHFov / 2 * Mathf.Deg2Rad); @@ -160,11 +162,11 @@ private void SetupLaserCamera() name = "LidarDepthTexture" }; - laserCamera.targetTexture = targetDepthRT; + laserCam.targetTexture = targetDepthRT; - laserCamera.enabled = false; + laserCam.enabled = false; - // laserCamera.hideFlags |= HideFlags.NotEditable; + // laserCam.hideFlags |= HideFlags.NotEditable; } private void SetupLaserCameraData() @@ -174,7 +176,7 @@ private void SetupLaserCameraData() laserCamData = new LaserCamData[numberOfLaserCamData]; - var targetDepthRT = laserCamera.targetTexture; + var targetDepthRT = laserCam.targetTexture; for (var index = 0; index < numberOfLaserCamData; index++) { var data = new LaserCamData(); @@ -196,17 +198,17 @@ private IEnumerator LaserCameraWorker() var data = laserCamData[dataIndex]; axisRotation.y = data.CenterAngle; - laserCamera.transform.localRotation = Quaternion.Euler(axisRotation); + laserCam.transform.localRotation = Quaternion.Euler(axisRotation); - laserCamera.enabled = true; + laserCam.enabled = true; - laserCamera.Render(); + laserCam.Render(); - var readback = AsyncGPUReadback.Request(laserCamera.targetTexture, 0, TextureFormat.RGBA32); + var readback = AsyncGPUReadback.Request(laserCam.targetTexture, 0, TextureFormat.RGBA32); yield return new WaitUntil(() => readback.done); - laserCamera.enabled = false; + laserCam.enabled = false; if (readback.hasError) {