示例#1
0
        /// <summary>
        /// Setup a capture request for a channel. Once completed, the functor will be called with the channel data, in the format requested.
        /// </summary>
        /// <param name="request"> AsyncRequest to enqueue readbacks to. When all are completed, the request is marked completed. </param>
        /// <param name="channel"> The channel to capture data from (color, depth etc.) </param>
        /// <param name="camera"> The Camera to capture data from. </param>
        /// <param name="format"> The graphics format you want the data to be in. </param>
        /// <param name="functor"> The completion functor to call with the data. </param>
        /// <param name="forceFlipY"> Flags allowing you to force flipY for arbitrary channels. </param>
        /// <param name="readWrite"> Specify the desired color space conversion. If Default, then will be set to sRGB for SRP Color channel. </param>
        public static void SetupCaptureRequest
        (
            AsyncRequest <CaptureState> request,
            Channel channel,
            Camera camera,
            GraphicsFormat format,
            Func <AsyncRequest <CaptureState>, AsyncRequest.Result> functor,
            ForceFlip forceFlipY,
            RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default
        )
        {
            request.data.SetFunctor(channel, functor);

            Debug.Assert(request.data.camera == camera, "Capture: Camera must match the camera in request.data.camera");
            Debug.Assert(GraphicsUtilities.SupportsRenderTextureFormat(format), $"Capture: GraphicsFormat {format} not supported for {channel} channel");

            var material = SelectShaderVariantForChannel(channel, format);

            if (scriptableRenderPipeline)
            {
                request.data.SetTrigger(channel, (cb, rtid) => SetupCaptureRequestCommandBufferForChannel(request, channel, camera, cb, rtid, material, format, forceFlipY, readWrite, HandleReadbackCompletion));
            }
            else
            {
                SetupCaptureRequestCommandBufferForChannel(request, channel, camera, null, default, material, format, forceFlipY, readWrite, HandleReadbackCompletion);
示例#2
0
        /// <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&lt;CaptureState&gt;</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);
        }