/// <summary> /// Main Capture entrypoint. /// </summary> /// <param name="camera"> The Camera to capture data from. </param> /// <param name="colorFunctor"> Completion functor for the color channel. </param> /// <param name="colorFormat"> The pixel format to capture in. </param> /// <param name="depthFunctor"> Completion functor for the depth channel. </param> /// <param name="depthFormat"> The pixel format to capture in. </param> /// <param name="motionFunctor"> Completion functor for the motion vectors channel. </param> /// <param name="motionFormat"> The pixel format to capture in. </param> /// <param name="forceFlipY"> Override one ore more channels to force flip either true or false. </param> /// <param name="readWrite"> Specify the desired color space conversion. If Default, then will be set to sRGB for SRP Color channel. </param> /// <returns>AsyncRequest<CaptureState></returns> public static AsyncRequest <CaptureState> Capture ( Camera camera, Func <AsyncRequest <CaptureState>, AsyncRequest.Result> colorFunctor = null, GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_UNorm, Func <AsyncRequest <CaptureState>, AsyncRequest.Result> depthFunctor = null, GraphicsFormat depthFormat = GraphicsFormat.R8G8B8A8_UNorm, Func <AsyncRequest <CaptureState>, AsyncRequest.Result> normalFunctor = null, GraphicsFormat normalFormat = GraphicsFormat.R8G8B8A8_UNorm, Func <AsyncRequest <CaptureState>, AsyncRequest.Result> motionFunctor = null, GraphicsFormat motionFormat = GraphicsFormat.R8G8B8A8_UNorm, ForceFlip forceFlip = ForceFlip.None, RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default ) { var request = Manager.Instance.CreateRequest <AsyncRequest <CaptureState> >(); request.data.camera = camera; request.data.frame = Time.frameCount; if (colorFunctor != null) { SetupCaptureRequest(request, Channel.Color, camera, colorFormat, colorFunctor, forceFlip, readWrite); } if (depthFunctor != null) { SetupCaptureRequest(request, Channel.Depth, camera, depthFormat, depthFunctor, forceFlip, readWrite); } if (normalFunctor != null) { SetupCaptureRequest(request, Channel.Normal, camera, normalFormat, normalFunctor, forceFlip, readWrite); } if (motionFunctor != null) { SetupCaptureRequest(request, Channel.Motion, camera, motionFormat, motionFunctor, forceFlip, readWrite); } #if UNITY_EDITOR ValidateRequestParameters(request); #endif #if UNITY_2019_3_OR_NEWER if (scriptableRenderPipeline) { SRPSupport?.QueueCameraRequest(camera, request); } #endif return(request); }
/// <summary> /// Main Capture entrypoint. /// </summary> /// <param name="camera"> The Camera to capture data from. </param> /// <param name="colorFunctor"> Completion functor for the color channel. </param> /// <param name="colorFormat"> The pixel format to capture in. </param> /// <param name="depthFunctor"> Completion functor for the depth channel. </param> /// <param name="depthFormat"> The pixel format to capture in. </param> /// <param name="motionVectorsFunctor"> Completion functor for the motion vectors channel. </param> /// <param name="motionFormat"> The pixel format to capture in. </param> /// <param name="flipY"> Whether or not to flip the image vertically. </param> /// <returns>AsyncRequest<CaptureState></returns> public static AsyncRequest <CaptureState> Capture ( Camera camera, Func <AsyncRequest <CaptureState>, AsyncRequest <CaptureState> .Result> colorFunctor = null, GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_UNorm, Func <AsyncRequest <CaptureState>, AsyncRequest <CaptureState> .Result> depthFunctor = null, GraphicsFormat depthFormat = GraphicsFormat.R16_UNorm, Func <AsyncRequest <CaptureState>, AsyncRequest <CaptureState> .Result> motionVectorsFunctor = null, GraphicsFormat motionFormat = GraphicsFormat.R16_UNorm, bool flipY = false ) { #if UNITY_EDITOR Debug.Assert(camera != null, "Capture camera cannot be null."); Debug.Assert(colorFunctor != null || depthFunctor != null || motionVectorsFunctor != null, "Capture one functor must be valid."); if (colorFunctor != null) { Debug.Assert(GraphicsUtilities.SupportsRenderTextureFormat(colorFormat), "GraphicsFormat not supported"); } if (depthFunctor != null) { Debug.Assert((camera.depthTextureMode & (DepthTextureMode.Depth | DepthTextureMode.DepthNormals)) != 0, "Depth not specified for camera"); Debug.Assert(GraphicsUtilities.SupportsRenderTextureFormat(depthFormat), "GraphicsFormat not supported"); } if (motionVectorsFunctor != null) { Debug.Assert((camera.depthTextureMode & DepthTextureMode.MotionVectors) != 0, "Motion vectors not enabled in depthTextureMode"); Debug.Assert(SystemInfo.supportsMotionVectors, "Motion vectors are not supported"); Debug.Assert(GraphicsUtilities.SupportsRenderTextureFormat(motionFormat), "GraphicsFormat not supported"); } #endif // UNITY_EDITOR var req = Manager.Instance.CreateRequest <AsyncRequest <CaptureState> >(); SetupCaptureRequest(req, Channel.Color, camera, CameraEvent.AfterEverything, BuiltinRenderTextureType.CameraTarget, colorFormat, colorFunctor, flipY); SetupCaptureRequest(req, Channel.Depth, camera, CameraEvent.AfterDepthTexture, BuiltinRenderTextureType.Depth, depthFormat, depthFunctor, flipY); SetupCaptureRequest(req, Channel.Motion, camera, CameraEvent.BeforeImageEffects, BuiltinRenderTextureType.MotionVectors, motionFormat, motionVectorsFunctor, flipY); #if UNITY_2019_3_OR_NEWER SRPSupport?.QueueCameraRequest(camera, req); #endif return(req); }