Skip to content

Commit

Permalink
enable OcclusionCulling flag for UnityEngine.Camera
Browse files Browse the repository at this point in the history
- Camera Device
- Lidar Device

Member variable name changed in Lidar Device
-> laserCamera -> laserCam
  • Loading branch information
hyunseok-yang committed Jul 26, 2020
1 parent dd2614c commit 0cfebaa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/DevicePlugins/MultiCameraPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void OnDestroy()

private void Sender()
{
Stopwatch sw = new Stopwatch();
var sw = new Stopwatch();
while (true)
{
if (cam == null)
Expand Down
2 changes: 2 additions & 0 deletions Assets/Scripts/Devices/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
50 changes: 26 additions & 24 deletions Assets/Scripts/Devices/Lidar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,9 +86,9 @@ protected override void OnAwake()

protected override void OnStart()
{
laserCamera = gameObject.AddComponent<UnityEngine.Camera>();
laserCam = gameObject.AddComponent<UnityEngine.Camera>();

if (laserCamera)
if (laserCam)
{
SetupLaserCamera();

Expand Down Expand Up @@ -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);
Expand All @@ -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()
Expand All @@ -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();
Expand All @@ -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)
{
Expand Down

0 comments on commit 0cfebaa

Please sign in to comment.