protected virtual void CheckCubemapTexture() { // Fisheye camera uses Camera.RenderToCubemap(...), and thus do not need normal RenderTexture. // Although Camera.RenderToCubemap has its own target texture as parameter, // setting Camera.targetTexture will still affect its result. // So we set Camera.targetTexture to null to make sure its result is correct. SensorCamera.targetTexture = null; renderTarget?.Release(); renderTarget = null; if (CurrentCubemapSize != CubemapSize) { CubemapTexture.Release(); CubemapTexture = null; } if (CubemapTexture == null) { CubemapTexture = new RenderTexture(CubemapSize, CubemapSize, 24, RenderTextureFormat.ARGB32, CameraTargetTextureReadWriteType) { dimension = TextureDimension.Cube, antiAliasing = 1, useMipMap = false, useDynamicScale = false, wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear, }; CubemapTexture.Create(); } }
void CheckTexture() { if (!Distorted || !Fisheye) // No-distortion and non-fisheye distortion use Camera.Render(). { // if this is not first time if (renderTarget != null) { if (!renderTarget.IsValid(RenderTextureWidth, RenderTextureHeight)) { // if camera capture size has changed or we have lost rendertexture due to Unity window resizing or otherwise renderTarget.Release(); renderTarget = null; } } if (renderTarget == null) { renderTarget = SensorRenderTarget.Create2D(RenderTextureWidth, RenderTextureHeight, GraphicsFormat.R8G8B8A8_SRGB); SensorCamera.targetTexture = renderTarget; } } else { CheckCubemapTexture(); } if (Distorted) { // if this is not first time if (DistortedTexture != null) { if (SizeChanged) { // if camera capture size has changed DistortedTexture.Release(); DistortedTexture = null; } else if (!DistortedTexture.IsCreated()) { // if we have lost DistortedTexture due to Unity window resizing or otherwise DistortedTexture.Release(); DistortedTexture = null; } } if (DistortedTexture == null) { DistortedTexture = new RenderTexture(Width, Height, 24, RenderTextureFormat.ARGB32, CameraTargetTextureReadWriteType) { dimension = TextureDimension.Tex2D, antiAliasing = 1, useMipMap = false, useDynamicScale = false, wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear, enableRandomWrite = true, }; DistortedTexture.Create(); } } }
/// <summary> /// Creates new instance of <see cref="SensorRenderTarget"/> and allocates required resources. Uses cube map. /// </summary> /// <param name="width">Width (in pixels) of the texture.</param> /// <param name="height">Height (in pixels) of the texture.</param> /// <param name="faceMask">Mask for cubemap faces that should be rendered.</param> public static SensorRenderTarget CreateCube(int width, int height, int faceMask) { var instance = new SensorRenderTarget(width, height, true) { CubeFaceMask = faceMask }; return(instance); }
protected override void CheckCubemapTexture() { if (renderTarget != null && (!renderTarget.IsCube || !renderTarget.IsValid(CubemapSize, CubemapSize))) { renderTarget.Release(); renderTarget = null; } if (renderTarget == null) { renderTarget = SensorRenderTarget.CreateCube(CubemapSize, CubemapSize, faceMask); SensorCamera.targetTexture = null; } }
protected override void Deinitialize() { renderTarget?.Release(); renderTarget = null; PointCloudBuffer?.Release(); PointCloudBuffer = null; LatitudeAnglesBuffer?.Release(); LatitudeAnglesBuffer = null; ReadbackPool?.Dispose(); }
bool BeginReadRequest(int count, ref ReadRequest req) { if (count == 0) { return(false); } BeginReadMarker.Begin(); SensorRenderTarget renderTarget = null; if (AvailableRenderTextures.Count != 0) { renderTarget = AvailableRenderTextures.Pop(); } if (renderTarget == null) { renderTarget = SensorRenderTarget.Create2D(RenderTextureWidth, RenderTextureHeight); } else if (!renderTarget.IsValid(RenderTextureWidth, RenderTextureHeight)) { renderTarget.Release(); renderTarget = SensorRenderTarget.Create2D(RenderTextureWidth, RenderTextureHeight); } activeTarget = renderTarget; SensorCamera.targetTexture = renderTarget; SensorCamera.Render(); req = new ReadRequest() { TextureSet = renderTarget, Index = CurrentIndex, Count = count, Origin = SensorCamera.transform.position, CameraToWorldMatrix = SensorCamera.cameraToWorldMatrix, }; if (!Compensated) { req.Transform = transform.worldToLocalMatrix; } BeginReadMarker.End(); CurrentIndex = (CurrentIndex + count) % CurrentMeasurementsPerRotation; return(true); }
void CheckTexture() { // if this is not first time if (renderTarget != null) { if (!renderTarget.IsValid(Width, Height)) { // if camera capture size has changed or we have lost rendertexture due to Unity window resizing or otherwise renderTarget.Release(); renderTarget = null; } } if (renderTarget == null) { renderTarget = SensorRenderTarget.Create2D(Width, Height); SensorCamera.targetTexture = renderTarget; } }
protected override void Initialize() { Controller = GetComponentInParent <IAgentController>(); activeRT = new RenderTexture(Width, Height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear) { dimension = TextureDimension.Tex2D, antiAliasing = 1, useMipMap = false, useDynamicScale = false, wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear }; activeRT.Create(); Camera = GetComponentInChildren <Camera>(); Camera.targetTexture = activeRT; Camera.fieldOfView = FieldOfView; Camera.nearClipPlane = MinDistance; Camera.farClipPlane = MaxDistance; Camera.gameObject.GetComponent <HDAdditionalCameraData>().hasPersistentHistory = true; passId = new ShaderTagId("SimulatorSegmentationPass"); SegmentationCamera.fieldOfView = FieldOfView; SegmentationCamera.nearClipPlane = MinDistance; SegmentationCamera.farClipPlane = DetectionRange; SegmentationCamera.gameObject.GetComponent <HDAdditionalCameraData>().customRender += OnSegmentationRender; SegmentationCamera.gameObject.GetComponent <HDAdditionalCameraData>().hasPersistentHistory = true; renderTarget = SensorRenderTarget.Create2D(Width, Height, GraphicsFormat.R8G8B8A8_UNorm); SegmentationCamera.targetTexture = renderTarget; minX = new ComputeBuffer(256, sizeof(uint)); maxX = new ComputeBuffer(256, sizeof(uint)); minY = new ComputeBuffer(256, sizeof(uint)); maxY = new ComputeBuffer(256, sizeof(uint)); AAWireBoxes = gameObject.AddComponent <AAWireBox>(); AAWireBoxes.Camera = Camera; AAWireBoxes.IgnoreUpdates = true; }
void CheckTexture() { var targetWidth = -1; var targetHeight = -1; if (Distorted) { // Distorted + fisheye - render to cubemap, then distort to sensor-sized texture if (Fisheye) { if (renderTarget != null && (!renderTarget.IsCube || !renderTarget.IsValid(CubemapSize, CubemapSize))) { renderTarget.Release(); renderTarget = null; } if (renderTarget == null) { renderTarget = SensorRenderTarget.CreateCube(CubemapSize, CubemapSize, faceMask); SensorCamera.targetTexture = null; } } // Distorted - render to larger texture, then distort to sensor-sized one else { targetWidth = LensDistortion.ActualWidth; targetHeight = LensDistortion.ActualHeight; } if (DistortedHandle != null && !DistortedHandle.IsValid(Width, Height)) { DistortedHandle.Release(); DistortedHandle = null; } if (DistortedHandle == null) { DistortedHandle = SensorRenderTarget.Create2D(Width, Height, GraphicsFormat.R8G8B8A8_SRGB, true); } } else { // Undistorted - use only sensor-sized texture if (DistortedHandle != null) { DistortedHandle.Release(); DistortedHandle = null; } targetWidth = Width; targetHeight = Height; } if (targetWidth > 0) { if (renderTarget != null && !renderTarget.IsValid(targetWidth, targetHeight)) { renderTarget.Release(); renderTarget = null; } if (renderTarget == null) { renderTarget = SensorRenderTarget.Create2D(targetWidth, targetHeight, GraphicsFormat.R8G8B8A8_SRGB, !Distorted); SensorCamera.targetTexture = renderTarget; } } }
/// <summary> /// Creates new instance of <see cref="SensorRenderTarget"/> and allocates required resources. Uses 2D texture. /// </summary> /// <param name="width">Width (in pixels) of the texture.</param> /// <param name="height">Height (in pixels) of the texture.</param> public static SensorRenderTarget Create2D(int width, int height) { var instance = new SensorRenderTarget(width, height, false); return(instance); }
/// <summary> /// Creates new instance of <see cref="SensorRenderTarget"/> and allocates required resources. Uses 2D texture. /// </summary> /// <param name="width">Width (in pixels) of the texture.</param> /// <param name="height">Height (in pixels) of the texture.</param> /// /// <param name="colorFormat">GraphicsFormat of the color texture.</param> public static SensorRenderTarget Create2D(int width, int height, GraphicsFormat colorFormat) { var instance = new SensorRenderTarget(width, height, false, colorFormat); return(instance); }
/// <summary> /// Creates new instance of <see cref="SensorRenderTarget"/> and allocates required resources. Uses 2D texture. /// </summary> /// <param name="width">Width (in pixels) of the texture.</param> /// <param name="height">Height (in pixels) of the texture.</param> /// <param name="uiVisible">Will this texture be displayed on UI elements?</param> public static SensorRenderTarget Create2D(int width, int height, bool uiVisible = false) { var instance = new SensorRenderTarget(width, height, false, uiVisible: uiVisible); return(instance); }
void CheckTexture() { if (!Distorted || !Fisheye) // No-distortion and non-fisheye distortion use Camera.Render(). { // if this is not first time if (renderTarget != null) { if (!renderTarget.IsValid(RenderTextureWidth, RenderTextureHeight)) { // if camera capture size has changed or we have lost rendertexture due to Unity window resizing or otherwise renderTarget.Release(); renderTarget = null; } } if (renderTarget == null) { renderTarget = SensorRenderTarget.Create2D(RenderTextureWidth, RenderTextureHeight); SensorCamera.targetTexture = renderTarget; } } else // Fisheye camera uses Camera.RenderToCubemap(...), and thus do not need normal RenderTexture. { // Although Camera.RenderToCubemap has its own target texture as parameter, // setting Camera.targetTexture will still affect its result. // So we set Camera.targetTexture to null to make sure its result is correct. SensorCamera.targetTexture = null; if (CurrentCubemapSize != CubemapSize) { CubemapTexture.Release(); CubemapTexture = null; } if (CubemapTexture == null) { CubemapTexture = new RenderTexture(CubemapSize, CubemapSize, 24, RenderTextureFormat.ARGB32, CameraTargetTextureReadWriteType) { dimension = TextureDimension.Cube, antiAliasing = 1, useMipMap = false, useDynamicScale = false, wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear, }; CubemapTexture.Create(); } } if (Distorted) { // if this is not first time if (DistortedTexture != null) { if (SizeChanged) { // if camera capture size has changed DistortedTexture.Release(); DistortedTexture = null; } else if (!DistortedTexture.IsCreated()) { // if we have lost DistortedTexture due to Unity window resizing or otherwise DistortedTexture.Release(); DistortedTexture = null; } } if (DistortedTexture == null) { DistortedTexture = new RenderTexture(Width, Height, 24, RenderTextureFormat.ARGB32, CameraTargetTextureReadWriteType) { dimension = TextureDimension.Tex2D, antiAliasing = 1, useMipMap = false, useDynamicScale = false, wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear, enableRandomWrite = true, }; DistortedTexture.Create(); } } }