예제 #1
0
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            Predicate <Outlinable> editorPredicate = obj =>
            {
#if UNITY_EDITOR
                var stage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();

                return(stage == null || stage.IsPartOfPrefabContents(obj.gameObject));
#else
                return(true);
#endif
            };

            Predicate <Outlinable> gamePredicate = obj =>
            {
#if UNITY_EDITOR
                var stage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();

                return(stage == null || !stage.IsPartOfPrefabContents(obj.gameObject));
#else
                return(true);
#endif
            };

            Parameters.DrawPredicate = renderingData.cameraData.isSceneViewCamera ? editorPredicate : gamePredicate;
            var buffer = CommandBufferPool.Get("Outline");

            outlinables.Clear();
            Parameters.Layers.Clear();
            Outlinable.GetAllActiveOutlinables(outlinables);
            foreach (var outlinable in outlinables)
            {
                Parameters.Layers.Add(outlinable.Layer);
            }

            Parameters.Buffer = buffer;
            OutlineEffect.SetupBuffer(Parameters);

            context.ExecuteCommandBuffer(buffer);

            CommandBufferPool.Release(buffer);
        }
예제 #2
0
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            var camera = renderingData.cameraData.camera;

            var outlineEffect = Outliner;

            if (outlineEffect == null || !outlineEffect.enabled)
            {
                return;
            }

#if UNITY_EDITOR
            Parameters.Buffer.name = renderingData.cameraData.camera.name;
#endif

            Outlinable.GetAllActiveOutlinables(renderingData.cameraData.camera, Parameters.OutlinablesToRender);
            RendererFilteringUtility.Filter(renderingData.cameraData.camera, Parameters);

            Outliner.UpdateSharedParameters(Parameters, renderingData.cameraData.camera, renderingData.cameraData.isSceneViewCamera);

            var targetTexture = camera.targetTexture == null ? camera.activeTexture : camera.targetTexture;

            if (UnityEngine.XR.XRSettings.enabled &&
                !Parameters.IsEditorCamera &&
                Parameters.EyeMask != StereoTargetEyeMask.None)
            {
                var descriptor = UnityEngine.XR.XRSettings.eyeTextureDesc;
                Parameters.TargetWidth  = descriptor.width;
                Parameters.TargetHeight = descriptor.height;
            }
            else
            {
                Parameters.TargetWidth  = targetTexture != null ? targetTexture.width : (int)(camera.scaledPixelWidth * renderingData.cameraData.renderScale);
                Parameters.TargetHeight = targetTexture != null ? targetTexture.height : (int)(camera.scaledPixelHeight * renderingData.cameraData.renderScale);
            }

            Parameters.Antialiasing = renderingData.cameraData.cameraTargetDescriptor.msaaSamples;

            var useCustomRenderTarget = Outliner.HasCutomRenderTarget && !renderingData.cameraData.isSceneViewCamera;
            Parameters.Target      = RenderTargetUtility.ComposeTarget(Parameters, useCustomRenderTarget ? Outliner.GetRenderTarget(Parameters) : Renderer.cameraColorTarget);
            Parameters.DepthTarget =
#if UNITY_2019_3_OR_NEWER && !UNITY_2019_3_0 && !UNITY_2019_3_1 && !UNITY_2019_3_2 && !UNITY_2019_3_3 && !UNITY_2019_3_4 && !UNITY_2019_3_5 && !UNITY_2019_3_6 && !UNITY_2019_3_7 && !UNITY_2019_3_8
                RenderTargetUtility.ComposeTarget(Parameters, UseColorTargetForDepth ? Renderer.cameraColorTarget :
#if UNITY_2020_2_OR_NEWER
                                                  Renderer.cameraDepthTarget);
#else
                                                  Renderer.cameraDepth);
#endif
#else
                RenderTargetUtility.ComposeTarget(Parameters, Renderer.cameraColorTarget);
#endif

            Parameters.Buffer.Clear();
            if (Outliner.RenderingStrategy == OutlineRenderingStrategy.Default)
            {
                OutlineEffect.SetupOutline(Parameters);
                Parameters.BlitMesh = null;
                Parameters.MeshPool.ReleaseAllMeshes();
            }
            else
            {
                temporaryOutlinables.Clear();
                temporaryOutlinables.AddRange(Parameters.OutlinablesToRender);

                Parameters.OutlinablesToRender.Clear();
                Parameters.OutlinablesToRender.Add(null);

                foreach (var outlinable in temporaryOutlinables)
                {
                    Parameters.OutlinablesToRender[0] = outlinable;
                    OutlineEffect.SetupOutline(Parameters);
                    Parameters.BlitMesh = null;
                }

                Parameters.MeshPool.ReleaseAllMeshes();
            }

            context.ExecuteCommandBuffer(Parameters.Buffer);
        }
예제 #3
0
    private void UpdateOutliner(ScriptableRenderContext renderContext, CommandBuffer cmd, Camera camera, Outliner outlineEffect, HDCamera hdCamera)
    {
        if (outlineEffect == null || !outlineEffect.enabled)
        {
            return;
        }

        if (pool == null)
        {
            pool = new Queue <OutlineParameters>();
        }

        if (parametersInUse == null)
        {
            parametersInUse = new Queue <OutlineParameters>();
        }

        if (pool.Count == 0)
        {
            pool.Enqueue(new OutlineParameters());
        }

        var parameters = pool.Dequeue();

        parametersInUse.Enqueue(parameters);

        parameters.Buffer = cmd;

        outlineEffect.UpdateSharedParameters(parameters, camera, camera.cameraType == CameraType.SceneView);
        Outlinable.GetAllActiveOutlinables(parameters.Camera, parameters.OutlinablesToRender);
        RendererFilteringUtility.Filter(parameters.Camera, parameters);

        parameters.Buffer.EnableShaderKeyword("EPO_HDRP");

        var historyProperties = hdCamera.historyRTHandleProperties;

        parameters.Buffer.SetGlobalVector(OutlineEffect.ScaleHash, new Vector4(
                                              (float)historyProperties.currentViewportSize.x - (float)historyProperties.currentRenderTargetSize.x,
                                              (float)historyProperties.currentViewportSize.y - (float)historyProperties.currentRenderTargetSize.y,
                                              (float)historyProperties.currentViewportSize.x / (float)historyProperties.currentRenderTargetSize.x,
                                              (float)historyProperties.currentViewportSize.y / (float)historyProperties.currentRenderTargetSize.y));

        if (outlineEffect.RenderingStrategy == OutlineRenderingStrategy.Default)
        {
            outlineEffect.UpdateSharedParameters(parameters, camera, camera.cameraType == CameraType.SceneView);

            parameters.PrimaryBufferScale = 1.0f;
            parameters.InfoBufferScale    = 1.0f;

            RTHandle colorTarget;
            RTHandle depthTarget;
            GetCameraBuffers(out colorTarget, out depthTarget);

            parameters.Scale = colorTarget.rtHandleProperties.rtHandleScale;

            SetViewport(colorTarget, parameters);

            parameters.Target      = colorTarget;
            parameters.DepthTarget = depthTarget;

            parameters.TargetWidth  = colorTarget.rt.width;
            parameters.TargetHeight = colorTarget.rt.height;
            parameters.Antialiasing = colorTarget.rt.antiAliasing;

            parameters.Prepare();

            OutlineEffect.SetupOutline(parameters);

            renderContext.ExecuteCommandBuffer(parameters.Buffer);

            parameters.Buffer.Clear();
        }
        else
        {
            if (tempOutlinables == null)
            {
                tempOutlinables = new List <Outlinable>();
            }

            tempOutlinables.Clear();
            tempOutlinables.AddRange(parameters.OutlinablesToRender);

            foreach (var outlinable in tempOutlinables)
            {
                outlineEffect.UpdateSharedParameters(parameters, camera, camera.cameraType == CameraType.SceneView);

                RTHandle colorTarget;
                RTHandle depthTarget;
                GetCameraBuffers(out colorTarget, out depthTarget);

                parameters.Scale = colorTarget.rtHandleProperties.rtHandleScale;

                SetViewport(colorTarget, parameters);

                parameters.Target      = colorTarget;
                parameters.DepthTarget = depthTarget;

                parameters.TargetWidth  = colorTarget.rt.width;
                parameters.TargetHeight = colorTarget.rt.height;
                parameters.Antialiasing = colorTarget.rt.antiAliasing;

                parameters.OutlinablesToRender.Clear();
                parameters.OutlinablesToRender.Add(outlinable);

                parameters.BlitMesh = null;

                parameters.Prepare();

                cmd.SetViewport(new Rect(Vector2.zero, colorTarget.rtHandleProperties.currentViewportSize));

                OutlineEffect.SetupOutline(parameters);

                renderContext.ExecuteCommandBuffer(parameters.Buffer);

                parameters.Buffer.Clear();
            }

            parameters.MeshPool.ReleaseAllMeshes();
        }

        parameters.Buffer.Clear();
    }