예제 #1
0
 /// <summary>
 /// 创建一个用户自定义的渲染到纹理
 /// </summary>
 /// <param name="width">渲染到纹理的宽度</param>
 /// <param name="height">渲染到纹理的高度</param>
 /// <param name="format">渲染到纹理的格式</param>
 /// <param name="flag">渲染到纹理的渲染标志</param>
 /// <param name="color">渲染到纹理的颜色</param>
 /// <param name="useDepth">渲染到纹理是否使用深度</param>
 public void Setup(int width, int height, PixelFormat format, ClearFlag flag, ref Vector4 color, bool useDepth)
 {
     ICall_RenderToTexture_Setup(this, width, height, (int)format, (uint)flag, ref color, useDepth, 0, 0, 0, 0, 0, 0);
 }
예제 #2
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag = ClearFlag.ClearNone)
 {
     SetRenderTarget(cmd, colorBuffers, depthBuffer, clearFlag, Color.black);
 }
예제 #3
0
        private static void SetViewportAndClear(CommandBuffer cmd, HDCamera camera, RTHandleSystem.RTHandle buffer, ClearFlag clearFlag, Color clearColor)
        {
            // Clearing a partial viewport currently does not go through the hardware clear.
            // Instead it goes through a quad rendered with a specific shader.
            // When enabling wireframe mode in the scene view, unfortunately it overrides this shader thus breaking every clears.
            // That's why in the editor we don't set the viewport before clearing (it's set to full screen by the previous SetRenderTarget) but AFTER so that we benefit from un-bugged hardware clear.
            // We consider that the small loss in performance is acceptable in the editor.
            // A refactor of wireframe is needed before we can fix this properly (with not doing anything!)
#if !UNITY_EDITOR
            SetViewport(cmd, camera, buffer);
#endif
            CoreUtils.ClearRenderTarget(cmd, clearFlag, clearColor);
#if UNITY_EDITOR
            SetViewport(cmd, camera, buffer);
#endif
        }
예제 #4
0
        public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor)
        {
            var cmd = new CommandBuffer();

            cmd.name = "";
            cmd.SetRenderTarget(colorBuffers, depthBuffer);
            if (clearFlag != ClearFlag.ClearNone)
            {
                cmd.ClearRenderTarget((clearFlag & ClearFlag.ClearDepth) != 0, (clearFlag & ClearFlag.ClearColor) != 0, clearColor);
            }
            renderContext.ExecuteCommandBuffer(cmd);
            cmd.Dispose();
        }
예제 #5
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
 {
     SetRenderTarget(cmd, colorBuffer, depthBuffer, clearFlag, Color.black, miplevel, cubemapFace);
 }
예제 #6
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorBuffer, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction,
                                    RenderTargetIdentifier depthBuffer, RenderBufferLoadAction depthLoadAction, RenderBufferStoreAction depthStoreAction,
                                    ClearFlag clearFlag)
 {
     SetRenderTarget(cmd, colorBuffer, colorLoadAction, colorStoreAction, depthBuffer, depthLoadAction, depthStoreAction, clearFlag, clearColorAllBlack);
 }
예제 #7
0
        public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
        {
            var cmd = new CommandBuffer();

            cmd.name = "";
            cmd.SetRenderTarget(colorBuffer, depthBuffer, miplevel, cubemapFace);
            if (clearFlag != ClearFlag.ClearNone)
            {
                cmd.ClearRenderTarget((clearFlag & ClearFlag.ClearDepth) != 0, (clearFlag & ClearFlag.ClearColor) != 0, clearColor);
            }
            renderContext.ExecuteCommandBuffer(cmd);
            cmd.Dispose();
        }
예제 #8
0
 ScriptableRenderPass IBeforeRender.GetPassToEnqueue(RenderTextureDescriptor baseDescriptor, RenderTargetHandle colorHandle, RenderTargetHandle depthAttachmentHandle, ClearFlag clearFlag)
 {
     return(new ClearColorPass(colorHandle, clearFlag));
 }
예제 #9
0
 /// <summary>
 /// Return true if ClearFlag a contains ClearFlag b
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns></returns>
 internal static bool Contains(ClearFlag a, ClearFlag b)
 {
     return((a & b) == b);
 }
예제 #10
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorAttachment, RenderBufferLoadAction colorLoadAction, RenderBufferStoreAction colorStoreAction, ClearFlag clearFlags, Color clearColor, TextureDimension dimension)
 {
     if (dimension == TextureDimension.Tex2DArray)
     {
         CoreUtils.SetRenderTarget(cmd, colorAttachment, clearFlags, clearColor, 0, CubemapFace.Unknown, -1);
     }
     else
     {
         CoreUtils.SetRenderTarget(cmd, colorAttachment, colorLoadAction, colorStoreAction, clearFlags, clearColor);
     }
 }
예제 #11
0
 public ClearColorPass(RenderTargetHandle colorHandle, ClearFlag clearFlag)
 {
     m_ColorHandle = colorHandle;
     m_ClearFlag   = clearFlag;
 }
예제 #12
0
        /// <summary>
        /// Bind the custom color buffer as the current render target
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="bindDepth">if true we bind the custom depth buffer in addition to the color</param>
        /// <param name="clearFlags"></param>
        protected void SetCustomRenderTarget(CommandBuffer cmd, bool bindDepth = true, ClearFlag clearFlags = ClearFlag.None)
        {
            if (!isExecuting)
            {
                throw new Exception("SetCameraRenderTarget can only be called inside the CustomPass.Execute function");
            }

            if (bindDepth)
            {
                CoreUtils.SetRenderTarget(cmd, currentRenderTarget.customColorBuffer, currentRenderTarget.customDepthBuffer, clearFlags);
            }
            else
            {
                CoreUtils.SetRenderTarget(cmd, currentRenderTarget.customColorBuffer, clearFlags);
            }
        }
 void SetRenderTarget(CommandBuffer cmd, RenderBufferLoadAction loadOp, RenderBufferStoreAction storeOp, ClearFlag clearFlag, Color clearColor)
 {
     if (colorAttachmentHandle != -1)
     {
         if (depthAttachmentHandle != -1)
         {
             SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), loadOp, storeOp, GetSurface(depthAttachmentHandle), loadOp, storeOp, clearFlag, clearColor);
         }
         else
         {
             SetRenderTarget(cmd, GetSurface(colorAttachmentHandle), loadOp, storeOp, clearFlag, clearColor);
         }
     }
     else
     {
         SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget, loadOp, storeOp, clearFlag, clearColor);
     }
 }
예제 #14
0
        public static void Render(ScriptableRenderContext context, Camera camera, ClearFlag clearFlag, RenderTargetIdentifier targetColor, RenderTargetIdentifier targetDepth)
        {
#if UNITY_EDITOR
            if (camera.cameraType == CameraType.SceneView)
            {
                ScriptableRenderContext.EmitWorldGeometryForSceneView(camera);
            }
#endif

            ScriptableCullingParameters cullingParameters;
            CullingResults cullingResults;
            if (camera.TryGetCullingParameters(false, out cullingParameters))
            {
                cullingResults = context.Cull(ref cullingParameters);
            }
            else
            {
                return;
            }

            CommandBuffer buffer = new CommandBuffer()
            {
                name = camera.name
            };

            NativeArray <VisibleLight> visibleLights = cullingResults.visibleLights;
            Lighting.SetupLights(buffer, visibleLights, cullingResults);
            context.ExecuteCommandBuffer(buffer);
            buffer.Clear();

            context.SetupCameraProperties(camera);

            SortingSettings sortingSettings = new SortingSettings(camera)
            {
                criteria = SortingCriteria.CommonOpaque
            };
            DrawingSettings drawingSettings = new DrawingSettings(unlitShaderTagId, sortingSettings)
            {
                perObjectData = PerObjectData.LightData | PerObjectData.LightIndices
            };
            FilteringSettings filteringSettings = new FilteringSettings(RenderQueueRange.all);

            buffer.SetRenderTarget(
                targetColor, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
                targetDepth, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store
                );
            if (clearFlag != ClearFlag.None)
            {
                buffer.ClearRenderTarget(
                    (clearFlag & ClearFlag.Depth) != 0,
                    (clearFlag & ClearFlag.Color) != 0,
                    (clearFlag & ClearFlag.Color) != 0 ? camera.backgroundColor : Color.clear,
                    1.0f
                    );
            }
            context.ExecuteCommandBuffer(buffer);
            buffer.Clear();

            context.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);
            context.DrawSkybox(camera);

#if UNITY_EDITOR
            if (Handles.ShouldRenderGizmos())
            {
                context.DrawGizmos(camera, GizmoSubset.PreImageEffects);
            }
#endif

            // if (postProcessingSettings != null)
            // {
            //     CommandBuffer postProcessingBuffer = new CommandBuffer() { name = "Post-processing" };
            //     postProcessingBuffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store);
            //     PostProcessing.Render(postProcessingBuffer, camera, postProcessingSettings);
            //     context.ExecuteCommandBuffer(postProcessingBuffer);
            //     postProcessingBuffer.Release();
            // }

#if UNITY_EDITOR
            if (Handles.ShouldRenderGizmos())
            {
                context.DrawGizmos(camera, GizmoSubset.PostImageEffects);
            }
#endif

            buffer.Release();
            context.Submit(); // TODO: necessary?
        }
예제 #15
0
 /// <summary>
 /// 创建一个用户自定义的渲染到纹理
 /// </summary>
 /// <param name="width">渲染到纹理的宽度</param>
 /// <param name="height">渲染到纹理的高度</param>
 /// <param name="format">渲染到纹理的格式</param>
 /// <param name="flag">渲染到纹理的渲染标志</param>
 /// <param name="color">渲染到纹理的颜色</param>
 /// <param name="useDepth">渲染到纹理是否使用深度</param>
 public void Setup(int width, int height, PixelFormat format, ClearFlag flag, ref Vector4 color, bool useDepth)
 {
     ICall_RenderToTexture_Setup(this, width, height, (int)format, (uint)flag, ref color, useDepth, 0, 0, 0, 0, 0, 0);
 }
예제 #16
0
 public static void SetRenderTarget(CommandBuffer cmd, HDCamera camera, RTHandleSystem.RTHandle buffer, ClearFlag clearFlag = ClearFlag.None, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown, int depthSlice = 0)
 {
     SetRenderTarget(cmd, camera, buffer, clearFlag, CoreUtils.clearColorAllBlack, miplevel, cubemapFace, depthSlice);
 }
예제 #17
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier buffer, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction, ClearFlag clearFlag)
 {
     SetRenderTarget(cmd, buffer, loadAction, storeAction, clearFlag, clearColorAllBlack);
 }
예제 #18
0
        public static void SetRenderTarget(CommandBuffer cmd, HDCamera camera, RTHandleSystem.RTHandle colorBuffer, RTHandleSystem.RTHandle depthBuffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown, int depthSlice = 0)
        {
            int cw = colorBuffer.rt.width;
            int ch = colorBuffer.rt.height;
            int dw = depthBuffer.rt.width;
            int dh = depthBuffer.rt.height;

            Debug.Assert(cw == dw && ch == dh);

            CoreUtils.SetRenderTarget(cmd, colorBuffer, depthBuffer, miplevel, cubemapFace, depthSlice);
            SetViewportAndClear(cmd, camera, colorBuffer, clearFlag, clearColor);
        }
예제 #19
0
 public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
 {
     SetRenderTarget(renderContext, colorBuffer, depthBuffer, clearFlag, Color.black, miplevel, cubemapFace);
 }
예제 #20
0
 public static void SetRenderTarget(CommandBuffer cmd, HDCamera camera, RenderTargetIdentifier[] colorBuffers, RTHandleSystem.RTHandle depthBuffer, ClearFlag clearFlag = ClearFlag.None)
 {
     CoreUtils.SetRenderTarget(cmd, colorBuffers, depthBuffer); // Don't clear here, viewport needs to be set before we do.
     SetViewportAndClear(cmd, camera, depthBuffer, clearFlag, CoreUtils.clearColorAllBlack);
 }
예제 #21
0
 public static void SetRenderTarget(ScriptableRenderContext renderContext, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag = ClearFlag.ClearNone)
 {
     SetRenderTarget(renderContext, colorBuffers, depthBuffer, clearFlag, Color.black);
 }
예제 #22
0
 public static void SetRenderTarget(CommandBuffer cmd, HDCamera camera, RenderTargetIdentifier[] colorBuffers, RTHandleSystem.RTHandle depthBuffer, ClearFlag clearFlag, Color clearColor)
 {
     cmd.SetRenderTarget(colorBuffers, depthBuffer);
     SetViewportAndClear(cmd, camera, depthBuffer, clearFlag, clearColor);
 }
        public override void Setup(ScriptableRenderer renderer, ref RenderingData renderingData)
        {
            Camera camera = renderingData.cameraData.camera;

            renderer.SetupPerObjectLightIndices(ref renderingData.cullResults, ref renderingData.lightData);
            RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);
            ClearFlag clearFlag = ScriptableRenderer.GetCameraClearFlag(renderingData.cameraData.camera);
            RenderTextureDescriptor shadowDescriptor = baseDescriptor;

            shadowDescriptor.dimension = TextureDimension.Tex2D;

            bool mainLightShadows = false;

            if (renderingData.shadowData.supportsMainLightShadows)
            {
                mainLightShadows = m_MainLightShadowCasterPass.Setup(m_MainLightShadowmap, ref renderingData);
                if (mainLightShadows)
                {
                    renderer.EnqueuePass(m_MainLightShadowCasterPass);
                }
            }

            if (renderingData.shadowData.supportsAdditionalLightShadows)
            {
                bool additionalLightShadows = m_AdditionalLightsShadowCasterPass.Setup(m_AdditionalLightsShadowmap, ref renderingData, renderer.maxVisibleAdditionalLights);
                if (additionalLightShadows)
                {
                    renderer.EnqueuePass(m_AdditionalLightsShadowCasterPass);
                }
            }

            bool resolveShadowsInScreenSpace = mainLightShadows && renderingData.shadowData.requiresScreenSpaceShadowResolve;

            // Depth prepass is generated in the following cases:
            // - We resolve shadows in screen space
            // - Scene view camera always requires a depth texture. We do a depth pre-pass to simplify it and it shouldn't matter much for editor.
            // - If game or offscreen camera requires it we check if we can copy the depth from the rendering opaques pass and use that instead.
            bool requiresDepthPrepass = resolveShadowsInScreenSpace ||
                                        renderingData.cameraData.isSceneViewCamera ||
                                        (renderingData.cameraData.requiresDepthTexture && (!CanCopyDepth(ref renderingData.cameraData)));

            // For now VR requires a depth prepass until we figure out how to properly resolve texture2DMS in stereo
            requiresDepthPrepass |= renderingData.cameraData.isStereoEnabled;

            renderer.EnqueuePass(m_SetupForwardRenderingPass);

            camera.GetComponents(m_BeforeRenderPasses);
            camera.GetComponents(m_AfterOpaquePasses);
            camera.GetComponents(m_AfterOpaquePostProcessPasses);
            camera.GetComponents(m_AfterSkyboxPasses);
            camera.GetComponents(m_AfterTransparentPasses);
            camera.GetComponents(m_AfterRenderPasses);

            bool createColorTexture = RequiresIntermediateColorTexture(ref renderingData, baseDescriptor) ||
                                      m_BeforeRenderPasses.Count != 0 ||
                                      m_AfterOpaquePasses.Count != 0 ||
                                      m_AfterOpaquePostProcessPasses.Count != 0 ||
                                      m_AfterSkyboxPasses.Count != 0 ||
                                      m_AfterTransparentPasses.Count != 0 ||
                                      m_AfterRenderPasses.Count != 0;

            // If camera requires depth and there's no depth pre-pass we create a depth texture that can be read
            // later by effect requiring it.
            bool createDepthTexture = renderingData.cameraData.requiresDepthTexture && !requiresDepthPrepass;

            RenderTargetHandle colorHandle = (createColorTexture) ? m_ColorAttachment : RenderTargetHandle.CameraTarget;
            RenderTargetHandle depthHandle = (createDepthTexture) ? m_DepthAttachment : RenderTargetHandle.CameraTarget;

            var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples;

            if (createColorTexture || createDepthTexture)
            {
                m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount);
                renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass);
            }

            foreach (var pass in m_BeforeRenderPasses)
            {
                renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle, clearFlag));
            }

            if (requiresDepthPrepass)
            {
                m_DepthOnlyPass.Setup(baseDescriptor, m_DepthTexture);
                renderer.EnqueuePass(m_DepthOnlyPass);
            }

            if (resolveShadowsInScreenSpace)
            {
                m_ScreenSpaceShadowResolvePass.Setup(baseDescriptor, m_ScreenSpaceShadowmap);
                renderer.EnqueuePass(m_ScreenSpaceShadowResolvePass);
            }

            if (renderingData.cameraData.isStereoEnabled)
            {
                renderer.EnqueuePass(m_BeginXrRenderingPass);
            }

            var perObjectFlags = ScriptableRenderer.GetPerObjectLightFlags(renderingData.lightData.mainLightIndex, renderingData.lightData.additionalLightsCount);

            m_SetupLightweightConstants.Setup(renderer.maxVisibleAdditionalLights, renderer.perObjectLightIndices);
            renderer.EnqueuePass(m_SetupLightweightConstants);

            // If a before all render pass executed we expect it to clear the color render target
            if (m_BeforeRenderPasses.Count != 0)
            {
                clearFlag = ClearFlag.None;
            }

            m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, clearFlag, camera.backgroundColor, perObjectFlags);
            renderer.EnqueuePass(m_RenderOpaqueForwardPass);
            foreach (var pass in m_AfterOpaquePasses)
            {
                renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle));
            }

            if (renderingData.cameraData.postProcessEnabled &&
                renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessingContext))
            {
                m_OpaquePostProcessPass.Setup(baseDescriptor, colorHandle, colorHandle, true, false);
                renderer.EnqueuePass(m_OpaquePostProcessPass);

                foreach (var pass in m_AfterOpaquePostProcessPasses)
                {
                    renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle));
                }
            }

            if (camera.clearFlags == CameraClearFlags.Skybox && RenderSettings.skybox != null)
            {
                // We can't combine skybox and render opaques passes if there's a custom render pass in between
                // them. Ideally we need a render graph here that each render pass declares inputs and output
                // attachments and their Load/Store action so we figure out properly if we can combine passes
                // and move to interleaved rendering with RenderPass API.
                bool combineWithRenderOpaquesPass = m_AfterOpaquePostProcessPasses.Count == 0;
                m_DrawSkyboxPass.Setup(baseDescriptor, colorHandle, depthHandle, combineWithRenderOpaquesPass);
                renderer.EnqueuePass(m_DrawSkyboxPass);
            }

            foreach (var pass in m_AfterSkyboxPasses)
            {
                renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle));
            }

            // If a depth texture was created we necessarily need to copy it, otherwise we could have render it to a renderbuffer
            if (createDepthTexture)
            {
                m_CopyDepthPass.Setup(depthHandle, m_DepthTexture);
                renderer.EnqueuePass(m_CopyDepthPass);
            }

            if (renderingData.cameraData.requiresOpaqueTexture)
            {
                m_CopyColorPass.Setup(colorHandle, m_OpaqueColor);
                renderer.EnqueuePass(m_CopyColorPass);
            }

            m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, perObjectFlags);
            renderer.EnqueuePass(m_RenderTransparentForwardPass);

            foreach (var pass in m_AfterTransparentPasses)
            {
                renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle));
            }

#if UNITY_EDITOR
            m_LitGizmoRenderingPass.Setup(true);
            renderer.EnqueuePass(m_LitGizmoRenderingPass);
#endif

            bool afterRenderExists = m_AfterRenderPasses.Count != 0;

            // if we have additional filters
            // we need to stay in a RT
            if (afterRenderExists)
            {
                // perform post with src / dest the same
                if (renderingData.cameraData.postProcessEnabled)
                {
                    m_PostProcessPass.Setup(baseDescriptor, colorHandle, colorHandle, false, false);
                    renderer.EnqueuePass(m_PostProcessPass);
                }

                //execute after passes
                foreach (var pass in m_AfterRenderPasses)
                {
                    renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle));
                }

                //now blit into the final target
                if (colorHandle != RenderTargetHandle.CameraTarget)
                {
                    if (m_CapturePass.Setup(colorHandle, renderingData.cameraData.captureActions))
                    {
                        renderer.EnqueuePass(m_CapturePass);
                    }

                    m_FinalBlitPass.Setup(baseDescriptor, colorHandle, Display.main.requiresSrgbBlitToBackbuffer, renderingData.killAlphaInFinalBlit);
                    renderer.EnqueuePass(m_FinalBlitPass);
                }
            }
            else
            {
                if (renderingData.cameraData.postProcessEnabled)
                {
                    m_PostProcessPass.Setup(baseDescriptor, colorHandle, RenderTargetHandle.CameraTarget, false, renderingData.cameraData.camera.targetTexture == null);
                    renderer.EnqueuePass(m_PostProcessPass);
                }
                else if (colorHandle != RenderTargetHandle.CameraTarget)
                {
                    if (m_CapturePass.Setup(colorHandle, renderingData.cameraData.captureActions))
                    {
                        renderer.EnqueuePass(m_CapturePass);
                    }

                    m_FinalBlitPass.Setup(baseDescriptor, colorHandle, Display.main.requiresSrgbBlitToBackbuffer, renderingData.killAlphaInFinalBlit);
                    renderer.EnqueuePass(m_FinalBlitPass);
                }
            }

            if (renderingData.cameraData.isStereoEnabled)
            {
                renderer.EnqueuePass(m_EndXrRenderingPass);
            }

#if UNITY_EDITOR
            m_UnlitGizmoRenderingPass.Setup(false);
            renderer.EnqueuePass(m_UnlitGizmoRenderingPass);

            if (renderingData.cameraData.isSceneViewCamera)
            {
                m_SceneViewDepthCopyPass.Setup(m_DepthTexture);
                renderer.EnqueuePass(m_SceneViewDepthCopyPass);
            }
#endif
        }
예제 #24
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier buffer, ClearFlag clearFlag = ClearFlag.None, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown, int depthSlice = 0)
 {
     SetRenderTarget(cmd, buffer, clearFlag, clearColorAllBlack, miplevel, cubemapFace, depthSlice);
 }
예제 #25
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown)
 {
     cmd.SetRenderTarget(colorBuffer, depthBuffer, miplevel, cubemapFace);
     if (clearFlag != ClearFlag.ClearNone)
     {
         cmd.ClearRenderTarget((clearFlag & ClearFlag.ClearDepth) != 0, (clearFlag & ClearFlag.ClearColor) != 0, clearColor);
     }
 }
예제 #26
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown, int depthSlice = 0)
 {
     cmd.SetRenderTarget(colorBuffer, depthBuffer, miplevel, cubemapFace, depthSlice);
     ClearRenderTarget(cmd, clearFlag, clearColor);
 }
예제 #27
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor)
 {
     cmd.SetRenderTarget(colorBuffers, depthBuffer);
     if (clearFlag != ClearFlag.ClearNone)
     {
         cmd.ClearRenderTarget((clearFlag & ClearFlag.ClearDepth) != 0, (clearFlag & ClearFlag.ClearColor) != 0, clearColor);
     }
 }
예제 #28
0
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier[] colorBuffers, RenderTargetIdentifier depthBuffer, ClearFlag clearFlag, Color clearColor)
 {
     cmd.SetRenderTarget(colorBuffers, depthBuffer);
     ClearRenderTarget(cmd, clearFlag, clearColor);
 }
예제 #29
0
 // This set of RenderTarget management methods is supposed to be used when rendering into a camera dependent render texture.
 // This will automatically set the viewport based on the camera size and the RTHandle scaling info.
 public static void SetRenderTarget(CommandBuffer cmd, HDCamera camera, RTHandleSystem.RTHandle buffer, ClearFlag clearFlag, Color clearColor, int miplevel = 0, CubemapFace cubemapFace = CubemapFace.Unknown, int depthSlice = 0)
 {
     cmd.SetRenderTarget(buffer, miplevel, cubemapFace, depthSlice);
     SetViewportAndClear(cmd, camera, buffer, clearFlag, clearColor);
 }
예제 #30
0
 // Explicit load and store actions
 public static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier buffer, RenderBufferLoadAction loadAction, RenderBufferStoreAction storeAction, ClearFlag clearFlag, Color clearColor)
 {
     cmd.SetRenderTarget(buffer, loadAction, storeAction);
     ClearRenderTarget(cmd, clearFlag, clearColor);
 }
예제 #31
0
파일: Camera.cs 프로젝트: swtrse/duality
			public Pass(Pass copyFrom, BatchInfo inputOverride)
			{
				this.input = inputOverride;
				this.output = copyFrom.output;
				this.clearColor = copyFrom.clearColor;
				this.clearDepth = copyFrom.clearDepth;
				this.clearFlags = copyFrom.clearFlags;
				this.matrixMode = copyFrom.matrixMode;
				this.visibilityMask = copyFrom.visibilityMask;

				this.MakeAvailable();
			}
예제 #32
0
        public void Setup(ScriptableRenderer renderer, ref RenderingData renderingData)
        {
            Init();

            Camera camera = renderingData.cameraData.camera;

            renderer.SetupPerObjectLightIndices(ref renderingData.cullResults, ref renderingData.lightData);
            RenderTextureDescriptor baseDescriptor = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);
            ClearFlag clearFlag = ScriptableRenderer.GetCameraClearFlag(renderingData.cameraData.camera);
            RenderTextureDescriptor shadowDescriptor = baseDescriptor;

            shadowDescriptor.dimension = TextureDimension.Tex2D;

            bool mainLightShadows = false;

            if (renderingData.shadowData.supportsMainLightShadows)
            {
                mainLightShadows = m_MainLightShadowCasterPass.Setup(m_MainLightShadowmap, ref renderingData);
                if (mainLightShadows)
                {
                    renderer.EnqueuePass(m_MainLightShadowCasterPass);
                }
            }

            if (renderingData.shadowData.supportsAdditionalLightShadows)
            {
                bool additionalLightShadows = m_AdditionalLightsShadowCasterPass.Setup(m_AdditionalLightsShadowmap, ref renderingData, renderer.maxVisibleAdditionalLights);
                if (additionalLightShadows)
                {
                    renderer.EnqueuePass(m_AdditionalLightsShadowCasterPass);
                }
            }

            bool resolveShadowsInScreenSpace = mainLightShadows && renderingData.shadowData.requiresScreenSpaceShadowResolve;
            bool requiresDepthPrepass        = resolveShadowsInScreenSpace || renderingData.cameraData.isSceneViewCamera ||
                                               (renderingData.cameraData.requiresDepthTexture && (!CanCopyDepth(ref renderingData.cameraData)));

            // For now VR requires a depth prepass until we figure out how to properly resolve texture2DMS in stereo
            requiresDepthPrepass |= renderingData.cameraData.isStereoEnabled;

            renderer.EnqueuePass(m_SetupForwardRenderingPass);

            camera.GetComponents(m_BeforeRenderPasses);
            camera.GetComponents(m_AfterOpaquePasses);
            camera.GetComponents(m_AfterOpaquePostProcessPasses);
            camera.GetComponents(m_AfterSkyboxPasses);
            camera.GetComponents(m_AfterTransparentPasses);
            camera.GetComponents(m_AfterRenderPasses);

            bool requiresRenderToTexture = RequiresIntermediateColorTexture(ref renderingData.cameraData, baseDescriptor) ||
                                           m_BeforeRenderPasses.Count != 0 ||
                                           m_AfterOpaquePasses.Count != 0 ||
                                           m_AfterOpaquePostProcessPasses.Count != 0 ||
                                           m_AfterSkyboxPasses.Count != 0 ||
                                           m_AfterTransparentPasses.Count != 0 ||
                                           m_AfterRenderPasses.Count != 0 ||
                                           Display.main.requiresBlitToBackbuffer ||
                                           renderingData.killAlphaInFinalBlit;

            RenderTargetHandle colorHandle = RenderTargetHandle.CameraTarget;
            RenderTargetHandle depthHandle = RenderTargetHandle.CameraTarget;

            var sampleCount = (SampleCount)renderingData.cameraData.msaaSamples;

            if (requiresRenderToTexture)
            {
                colorHandle = m_ColorAttachment;
                depthHandle = m_DepthAttachment;

                m_CreateLightweightRenderTexturesPass.Setup(baseDescriptor, colorHandle, depthHandle, sampleCount);
                renderer.EnqueuePass(m_CreateLightweightRenderTexturesPass);
            }

            foreach (var pass in m_BeforeRenderPasses)
            {
                renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle, clearFlag));
            }

            if (requiresDepthPrepass)
            {
                m_DepthOnlyPass.Setup(baseDescriptor, m_DepthTexture, SampleCount.One);
                renderer.EnqueuePass(m_DepthOnlyPass);
            }

            if (resolveShadowsInScreenSpace)
            {
                m_ScreenSpaceShadowResolvePass.Setup(baseDescriptor, m_ScreenSpaceShadowmap);
                renderer.EnqueuePass(m_ScreenSpaceShadowResolvePass);
            }

            if (renderingData.cameraData.isStereoEnabled)
            {
                renderer.EnqueuePass(m_BeginXrRenderingPass);
            }

            var perObjectFlags = ScriptableRenderer.GetPerObjectLightFlags(renderingData.lightData.mainLightIndex, renderingData.lightData.additionalLightsCount);

            m_SetupLightweightConstants.Setup(renderer.maxVisibleAdditionalLights, renderer.perObjectLightIndices);
            renderer.EnqueuePass(m_SetupLightweightConstants);

            // If a before all render pass executed we expect it to clear the color render target
            if (m_BeforeRenderPasses.Count != 0)
            {
                clearFlag = ClearFlag.None;
            }

            m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, clearFlag, camera.backgroundColor, perObjectFlags);
            renderer.EnqueuePass(m_RenderOpaqueForwardPass);
            foreach (var pass in m_AfterOpaquePasses)
            {
                renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle));
            }

            if (renderingData.cameraData.postProcessEnabled &&
                renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessingContext))
            {
                m_CreatePostOpaqueColorPass.Setup(baseDescriptor, m_ColorAttachmentAfterOpaquePost, sampleCount);
                renderer.EnqueuePass(m_CreatePostOpaqueColorPass);
                m_OpaquePostProcessPass.Setup(baseDescriptor, colorHandle, m_ColorAttachmentAfterOpaquePost, true, false);
                renderer.EnqueuePass(m_OpaquePostProcessPass);

                colorHandle = m_ColorAttachmentAfterOpaquePost;

                foreach (var pass in m_AfterOpaquePostProcessPasses)
                {
                    renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle));
                }
            }

            if (camera.clearFlags == CameraClearFlags.Skybox)
            {
                m_DrawSkyboxPass.Setup(colorHandle, depthHandle);
                renderer.EnqueuePass(m_DrawSkyboxPass);
            }

            foreach (var pass in m_AfterSkyboxPasses)
            {
                renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle));
            }

            if (renderingData.cameraData.requiresDepthTexture && !requiresDepthPrepass)
            {
                m_CopyDepthPass.Setup(depthHandle, m_DepthTexture);
                renderer.EnqueuePass(m_CopyDepthPass);
            }

            if (renderingData.cameraData.requiresOpaqueTexture)
            {
                m_CopyColorPass.Setup(colorHandle, m_OpaqueColor);
                renderer.EnqueuePass(m_CopyColorPass);
            }

            m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, perObjectFlags);
            renderer.EnqueuePass(m_RenderTransparentForwardPass);

            foreach (var pass in m_AfterTransparentPasses)
            {
                renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle));
            }

#if UNITY_EDITOR
            m_LitGizmoRenderingPass.Setup(true);
            renderer.EnqueuePass(m_LitGizmoRenderingPass);
#endif

            bool afterRenderExists = m_AfterRenderPasses.Count != 0;

            // if we have additional filters
            // we need to stay in a RT
            if (afterRenderExists)
            {
                // perform post with src / dest the same
                if (renderingData.cameraData.postProcessEnabled)
                {
                    m_CreatePostTransparentColorPass.Setup(baseDescriptor, m_ColorAttachmentAfterTransparentPost, sampleCount);
                    renderer.EnqueuePass(m_CreatePostTransparentColorPass);

                    m_PostProcessPass.Setup(baseDescriptor, colorHandle, m_ColorAttachmentAfterTransparentPost, false, false);
                    renderer.EnqueuePass(m_PostProcessPass);

                    colorHandle = m_ColorAttachmentAfterTransparentPost;
                }

                //execute after passes
                foreach (var pass in m_AfterRenderPasses)
                {
                    renderer.EnqueuePass(pass.GetPassToEnqueue(baseDescriptor, colorHandle, depthHandle));
                }

                //now blit into the final target
                if (colorHandle != RenderTargetHandle.CameraTarget)
                {
                    if (m_CapturePass.Setup(colorHandle, renderingData.cameraData.captureActions))
                    {
                        renderer.EnqueuePass(m_CapturePass);
                    }

                    m_FinalBlitPass.Setup(baseDescriptor, colorHandle, Display.main.requiresSrgbBlitToBackbuffer, renderingData.killAlphaInFinalBlit);
                    renderer.EnqueuePass(m_FinalBlitPass);
                }
            }
            else
            {
                if (renderingData.cameraData.postProcessEnabled)
                {
                    m_PostProcessPass.Setup(baseDescriptor, colorHandle, RenderTargetHandle.CameraTarget, false, renderingData.cameraData.camera.targetTexture == null);
                    renderer.EnqueuePass(m_PostProcessPass);
                }
                else if (colorHandle != RenderTargetHandle.CameraTarget)
                {
                    if (m_CapturePass.Setup(colorHandle, renderingData.cameraData.captureActions))
                    {
                        renderer.EnqueuePass(m_CapturePass);
                    }

                    m_FinalBlitPass.Setup(baseDescriptor, colorHandle, Display.main.requiresSrgbBlitToBackbuffer, renderingData.killAlphaInFinalBlit);
                    renderer.EnqueuePass(m_FinalBlitPass);
                }
            }

            if (renderingData.cameraData.isStereoEnabled)
            {
                renderer.EnqueuePass(m_EndXrRenderingPass);
            }

#if UNITY_EDITOR
            m_UnlitGizmoRenderingPass.Setup(false);
            renderer.EnqueuePass(m_UnlitGizmoRenderingPass);

            if (renderingData.cameraData.isSceneViewCamera)
            {
                m_SceneViewDepthCopyPass.Setup(m_DepthTexture);
                renderer.EnqueuePass(m_SceneViewDepthCopyPass);
            }
#endif
        }