示例#1
0
        public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                                     ref CullResults cullResults,
                                     ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(k_RenderOpaquesTag);

            using (new ProfilingSample(cmd, k_RenderOpaquesTag))
            {
                SetRenderTarget(cmd, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(clearColor));

                // TODO: We need a proper way to handle multiple camera/ camera stack. Issue is: multiple cameras can share a same RT
                // (e.g, split screen games). However devs have to be dilligent with it and know when to clear/preserve color.
                // For now we make it consistent by resolving viewport with a RT until we can have a proper camera management system
                //if (colorAttachmentHandle == -1 && !cameraData.isDefaultViewport)
                //    cmd.SetViewport(camera.pixelRect);
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                Camera camera       = renderingData.cameraData.camera;
                var    drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonOpaque, rendererConfiguration, dynamicBatching);
                context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings);

                // Render objects that did not match any shader pass with error shader
                RenderObjectsWithError(renderer, ref context, ref cullResults, camera, opaqueFilterSettings, SortFlags.None);
            }
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
        public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                                     ref CullResults cullResults,
                                     ref RenderingData renderingData)
        {
            Material material = renderingData.cameraData.isStereoEnabled ? null : renderer.GetMaterial(MaterialHandles.Blit);
            RenderTargetIdentifier sourceRT = colorAttachmentHandle.Identifier();

            CommandBuffer cmd = CommandBufferPool.Get(k_FinalBlitTag);

            cmd.SetGlobalTexture("_BlitTex", sourceRT);

            // We need to handle viewport on a RT. We do it by rendering a fullscreen quad + viewport
            if (!renderingData.cameraData.isDefaultViewport)
            {
                SetRenderTarget(
                    cmd,
                    BuiltinRenderTextureType.CameraTarget,
                    RenderBufferLoadAction.DontCare,
                    RenderBufferStoreAction.Store,
                    ClearFlag.None,
                    Color.black,
                    descriptor.dimension);

                cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
                cmd.SetViewport(renderingData.cameraData.camera.pixelRect);
                LightweightPipeline.DrawFullScreen(cmd, material);
            }
            else
            {
                cmd.Blit(colorAttachmentHandle.Identifier(), BuiltinRenderTextureType.CameraTarget, material);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
        public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                                     ref CullResults cullResults,
                                     ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get("");

            if (colorAttachmentHandle != RenderTargetHandle.CameraTarget)
            {
                var colorDescriptor = descriptor;
                colorDescriptor.depthBufferBits = k_DepthStencilBufferBits; // TODO: does the color RT always need depth?
                colorDescriptor.sRGB            = true;
                colorDescriptor.msaaSamples     = (int)samples;
                cmd.GetTemporaryRT(colorAttachmentHandle.id, colorDescriptor, FilterMode.Bilinear);
            }

            if (depthAttachmentHandle != RenderTargetHandle.CameraTarget)
            {
                var depthDescriptor = descriptor;
                depthDescriptor.colorFormat     = RenderTextureFormat.Depth;
                depthDescriptor.depthBufferBits = k_DepthStencilBufferBits;
                depthDescriptor.msaaSamples     = (int)samples;
                depthDescriptor.bindMS          = (int)samples > 1;
                cmd.GetTemporaryRT(depthAttachmentHandle.id, depthDescriptor, FilterMode.Point);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
        public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
            ref CullResults cullResults,
            ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(k_DepthPrepassTag);
            using (new ProfilingSample(cmd, k_DepthPrepassTag))
            {
                cmd.GetTemporaryRT(depthAttachmentHandle.id, descriptor, FilterMode.Point);
                SetRenderTarget(
                    cmd,
                    depthAttachmentHandle.Identifier(),
                    RenderBufferLoadAction.DontCare,
                    RenderBufferStoreAction.Store,
                    ClearFlag.Depth,
                    Color.black,
                    descriptor.dimension);

                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                var drawSettings = CreateDrawRendererSettings(renderingData.cameraData.camera, SortFlags.CommonOpaque, RendererConfiguration.None, renderingData.supportsDynamicBatching);
                if (renderingData.cameraData.isStereoEnabled)
                {
                    Camera camera = renderingData.cameraData.camera;
                    context.StartMultiEye(camera);
                    context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings);
                    context.StopMultiEye(camera);
                }
                else
                    context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, opaqueFilterSettings);
            }
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
示例#5
0
        public DirectionalShadowsPass(LightweightForwardRenderer renderer) : base(renderer)
        {
            RegisterShaderPassName("ShadowCaster");

            m_DirectionalShadowMatrices = new Matrix4x4[k_MaxCascades + 1];
            m_CascadeSlices             = new ShadowSliceData[k_MaxCascades];
            m_CascadeSplitDistances     = new Vector4[k_MaxCascades];

            DirectionalShadowConstantBuffer._WorldToShadow             = Shader.PropertyToID("_WorldToShadow");
            DirectionalShadowConstantBuffer._ShadowData                = Shader.PropertyToID("_ShadowData");
            DirectionalShadowConstantBuffer._DirShadowSplitSpheres0    = Shader.PropertyToID("_DirShadowSplitSpheres0");
            DirectionalShadowConstantBuffer._DirShadowSplitSpheres1    = Shader.PropertyToID("_DirShadowSplitSpheres1");
            DirectionalShadowConstantBuffer._DirShadowSplitSpheres2    = Shader.PropertyToID("_DirShadowSplitSpheres2");
            DirectionalShadowConstantBuffer._DirShadowSplitSpheres3    = Shader.PropertyToID("_DirShadowSplitSpheres3");
            DirectionalShadowConstantBuffer._DirShadowSplitSphereRadii = Shader.PropertyToID("_DirShadowSplitSphereRadii");
            DirectionalShadowConstantBuffer._ShadowOffset0             = Shader.PropertyToID("_ShadowOffset0");
            DirectionalShadowConstantBuffer._ShadowOffset1             = Shader.PropertyToID("_ShadowOffset1");
            DirectionalShadowConstantBuffer._ShadowOffset2             = Shader.PropertyToID("_ShadowOffset2");
            DirectionalShadowConstantBuffer._ShadowOffset3             = Shader.PropertyToID("_ShadowOffset3");
            DirectionalShadowConstantBuffer._ShadowmapSize             = Shader.PropertyToID("_ShadowmapSize");

            m_ShadowmapFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Shadowmap)
                ? RenderTextureFormat.Shadowmap
                : RenderTextureFormat.Depth;
        }
        public ScreenSpaceShadowResolvePass(LightweightForwardRenderer renderer) : base(renderer)
        {
            m_ColorFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.R8)
                ? RenderTextureFormat.R8
                : RenderTextureFormat.ARGB32;

            m_ScreenSpaceShadowsMaterial = renderer.GetMaterial(MaterialHandles.ScrenSpaceShadow);
        }
示例#7
0
        public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                                     ref CullResults cullResults,
                                     ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get("Render PostProcess Effects");

            LightweightPipeline.RenderPostProcess(cmd, postContext, ref renderingData.cameraData, descriptor.colorFormat, colorAttachmentHandle.Identifier(), BuiltinRenderTextureType.CameraTarget, false);
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
示例#8
0
 public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                              ref CullResults cullResults,
                              ref RenderingData renderingData)
 {
     if (renderingData.shadowData.renderDirectionalShadows)
     {
         Clear();
         RenderDirectionalCascadeShadowmap(ref context, ref cullResults, ref renderingData.lightData, ref renderingData.shadowData);
     }
 }
示例#9
0
        public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                                     ref CullResults cullResults,
                                     ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get("SetupShaderConstants");

            SetupShaderLightConstants(cmd, ref renderingData.lightData);
            SetShaderKeywords(cmd, ref renderingData.cameraData, ref renderingData.lightData, ref renderingData.shadowData);
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
        protected LightweightForwardPass(LightweightForwardRenderer renderer) : base(renderer)
        {
            m_ErrorMaterial = renderer.GetMaterial(MaterialHandles.Error);

            m_LegacyShaderPassNames = new List <ShaderPassName>();
            m_LegacyShaderPassNames.Add(new ShaderPassName("Always"));
            m_LegacyShaderPassNames.Add(new ShaderPassName("ForwardBase"));
            m_LegacyShaderPassNames.Add(new ShaderPassName("PrepassBase"));
            m_LegacyShaderPassNames.Add(new ShaderPassName("Vertex"));
            m_LegacyShaderPassNames.Add(new ShaderPassName("VertexLMRGBM"));
            m_LegacyShaderPassNames.Add(new ShaderPassName("VertexLM"));

            RegisterShaderPassName("LightweightForward");
            RegisterShaderPassName("SRPDefaultUnlit");
        }
        public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                                     ref CullResults cullResults,
                                     ref RenderingData renderingData)
        {
            // Restore Render target for additional editor rendering.
            // Note: Scene view camera always perform depth prepass
            CommandBuffer cmd = CommandBufferPool.Get(k_CopyDepthToCameraTag);

            CoreUtils.SetRenderTarget(cmd, BuiltinRenderTextureType.CameraTarget);
            cmd.SetGlobalTexture("_CameraDepthAttachment", source.Identifier());
            cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa);
            cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
            cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
            cmd.Blit(source.Identifier(), BuiltinRenderTextureType.CameraTarget, renderer.GetMaterial(MaterialHandles.DepthCopy));
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
示例#12
0
        protected void RenderObjectsWithError(LightweightForwardRenderer renderer, ref ScriptableRenderContext context, ref CullResults cullResults, Camera camera, FilterRenderersSettings filterSettings, SortFlags sortFlags)
        {
            Material errorMaterial = renderer.GetMaterial(MaterialHandles.Error);

            if (errorMaterial != null)
            {
                DrawRendererSettings errorSettings = new DrawRendererSettings(camera, m_LegacyShaderPassNames[0]);
                for (int i = 1; i < m_LegacyShaderPassNames.Count; ++i)
                {
                    errorSettings.SetShaderPassName(i, m_LegacyShaderPassNames[i]);
                }

                errorSettings.sorting.flags         = sortFlags;
                errorSettings.rendererConfiguration = RendererConfiguration.None;
                errorSettings.SetOverrideMaterial(errorMaterial, 0);
                context.DrawRenderers(cullResults.visibleRenderers, ref errorSettings, filterSettings);
            }
        }
示例#13
0
        public ForwardLitPass(LightweightForwardRenderer renderer) : base(renderer)
        {
            RegisterShaderPassName("LightweightForward");
            RegisterShaderPassName("SRPDefaultUnlit");

            m_LegacyShaderPassNames = new List <ShaderPassName>();
            m_LegacyShaderPassNames.Add(new ShaderPassName("Always"));
            m_LegacyShaderPassNames.Add(new ShaderPassName("ForwardBase"));
            m_LegacyShaderPassNames.Add(new ShaderPassName("PrepassBase"));
            m_LegacyShaderPassNames.Add(new ShaderPassName("Vertex"));
            m_LegacyShaderPassNames.Add(new ShaderPassName("VertexLMRGBM"));
            m_LegacyShaderPassNames.Add(new ShaderPassName("VertexLM"));

            PerCameraBuffer._MainLightPosition                  = Shader.PropertyToID("_MainLightPosition");
            PerCameraBuffer._MainLightColor                     = Shader.PropertyToID("_MainLightColor");
            PerCameraBuffer._MainLightCookie                    = Shader.PropertyToID("_MainLightCookie");
            PerCameraBuffer._WorldToLight                       = Shader.PropertyToID("_WorldToLight");
            PerCameraBuffer._AdditionalLightCount               = Shader.PropertyToID("_AdditionalLightCount");
            PerCameraBuffer._AdditionalLightPosition            = Shader.PropertyToID("_AdditionalLightPosition");
            PerCameraBuffer._AdditionalLightColor               = Shader.PropertyToID("_AdditionalLightColor");
            PerCameraBuffer._AdditionalLightDistanceAttenuation = Shader.PropertyToID("_AdditionalLightDistanceAttenuation");
            PerCameraBuffer._AdditionalLightSpotDir             = Shader.PropertyToID("_AdditionalLightSpotDir");
            PerCameraBuffer._AdditionalLightSpotAttenuation     = Shader.PropertyToID("_AdditionalLightSpotAttenuation");
            PerCameraBuffer._LightIndexBuffer                   = Shader.PropertyToID("_LightIndexBuffer");

            int maxVisibleLocalLights = renderer.maxVisibleLocalLights;

            m_LightPositions            = new Vector4[maxVisibleLocalLights];
            m_LightColors               = new Vector4[maxVisibleLocalLights];
            m_LightDistanceAttenuations = new Vector4[maxVisibleLocalLights];
            m_LightSpotDirections       = new Vector4[maxVisibleLocalLights];
            m_LightSpotAttenuations     = new Vector4[maxVisibleLocalLights];

            m_ColorFormat   = RenderTextureFormat.Default;
            m_BlitMaterial  = renderer.GetMaterial(MaterialHandles.Blit);
            m_ErrorMaterial = renderer.GetMaterial(MaterialHandles.Error);

            // Copy Depth Pass
            m_DepthCopyMaterial = renderer.GetMaterial(MaterialHandles.DepthCopy);

            // Copy Opaque Color Pass
            m_SamplingMaterial         = renderer.GetMaterial(MaterialHandles.Sampling);
            m_SampleOffsetShaderHandle = Shader.PropertyToID("_SampleOffset");
        }
        public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                                     ref CullResults cullResults,
                                     ref RenderingData renderingData)
        {
            CommandBuffer          cmd              = CommandBufferPool.Get(k_DepthCopyTag);
            RenderTargetIdentifier depthSurface     = source.Identifier();
            RenderTargetIdentifier copyDepthSurface = destination.Identifier();
            Material depthCopyMaterial              = renderer.GetMaterial(MaterialHandles.DepthCopy);

            RenderTextureDescriptor descriptor = LightweightForwardRenderer.CreateRTDesc(ref renderingData.cameraData);

            descriptor.colorFormat     = RenderTextureFormat.Depth;
            descriptor.depthBufferBits = 32; //TODO: fix this ;
            descriptor.msaaSamples     = 1;
            descriptor.bindMS          = false;
            cmd.GetTemporaryRT(destination.id, descriptor, FilterMode.Point);

            if (renderingData.cameraData.msaaSamples > 1)
            {
                cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa);
                if (renderingData.cameraData.msaaSamples == 4)
                {
                    cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
                    cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
                }
                else
                {
                    cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
                    cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
                }
                cmd.Blit(depthSurface, copyDepthSurface, depthCopyMaterial);
            }
            else
            {
                cmd.EnableShaderKeyword(LightweightKeywordStrings.DepthNoMsaa);
                cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa2);
                cmd.DisableShaderKeyword(LightweightKeywordStrings.DepthMsaa4);
                LightweightPipeline.CopyTexture(cmd, depthSurface, copyDepthSurface, depthCopyMaterial);
            }
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
        public LightweightPipeline(LightweightPipelineAsset asset)
        {
            pipelineAsset = asset;

            SetSupportedRenderingFeatures();
            SetPipelineCapabilities(asset);

            PerFrameBuffer._GlossyEnvironmentColor = Shader.PropertyToID("_GlossyEnvironmentColor");
            PerFrameBuffer._SubtractiveShadowColor = Shader.PropertyToID("_SubtractiveShadowColor");

            PerCameraBuffer._ScaledScreenParams = Shader.PropertyToID("_ScaledScreenParams");
            m_Renderer = new LightweightForwardRenderer(asset);

            // Let engine know we have MSAA on for cases where we support MSAA backbuffer
            if (QualitySettings.antiAliasing != pipelineAsset.msaaSampleCount)
                QualitySettings.antiAliasing = pipelineAsset.msaaSampleCount;

            Shader.globalRenderPipeline = "LightweightPipeline";
            m_IsCameraRendering = false;
        }
示例#16
0
        private void Init(LightweightForwardRenderer renderer)
        {
            if (m_Initialized)
            {
                return;
            }

            m_DepthOnlyPass                       = new DepthOnlyPass(renderer);
            m_DirectionalShadowPass               = new DirectionalShadowsPass(renderer);
            m_LocalShadowPass                     = new LocalShadowsPass(renderer);
            m_SetupForwardRenderingPass           = new SetupForwardRenderingPass(renderer);
            m_ScreenSpaceShadowResovePass         = new ScreenSpaceShadowResolvePass(renderer);
            m_CreateLightweightRenderTexturesPass = new CreateLightweightRenderTexturesPass(renderer);
            m_BeginXrRenderingPass                = new BeginXRRenderingPass(renderer);
            m_SetupLightweightConstants           = new SetupLightweightConstanstPass(renderer);
            m_RenderOpaqueForwardPass             = new RenderOpaqueForwardPass(renderer);
            m_OpaquePostProcessPass               = new OpaquePostProcessPass(renderer);
            m_DrawSkyboxPass                      = new DrawSkyboxPass(renderer);
            m_CopyDepthPass                       = new CopyDepthPass(renderer);
            m_CopyColorPass                       = new CopyColorPass(renderer);
            m_RenderTransparentForwardPass        = new RenderTransparentForwardPass(renderer);
            m_TransparentPostProcessPass          = new TransparentPostProcessPass(renderer);
            m_FinalBlitPass                       = new FinalBlitPass(renderer);
            m_EndXrRenderingPass                  = new EndXRRenderingPass(renderer);

            #if UNITY_EDITOR
            m_SceneViewDepthCopyPass = new SceneViewDepthCopyPass(renderer);
            #endif

            // RenderTexture format depends on camera and pipeline (HDR, non HDR, etc)
            // Samples (MSAA) depend on camera and pipeline
            Color.Init("_CameraColorTexture");
            DepthAttachment.Init("_CameraDepthAttachment");
            DepthTexture.Init("_CameraDepthTexture");
            OpaqueColor.Init("_CameraOpaqueTexture");
            DirectionalShadowmap.Init("_DirectionalShadowmapTexture");
            LocalShadowmap.Init("_LocalShadowmapTexture");
            ScreenSpaceShadowmap.Init("_ScreenSpaceShadowMapTexture");

            m_Initialized = true;
        }
示例#17
0
        public SetupLightweightConstanstPass(LightweightForwardRenderer renderer) : base(renderer)
        {
            PerCameraBuffer._MainLightPosition                  = Shader.PropertyToID("_MainLightPosition");
            PerCameraBuffer._MainLightColor                     = Shader.PropertyToID("_MainLightColor");
            PerCameraBuffer._MainLightCookie                    = Shader.PropertyToID("_MainLightCookie");
            PerCameraBuffer._WorldToLight                       = Shader.PropertyToID("_WorldToLight");
            PerCameraBuffer._AdditionalLightCount               = Shader.PropertyToID("_AdditionalLightCount");
            PerCameraBuffer._AdditionalLightPosition            = Shader.PropertyToID("_AdditionalLightPosition");
            PerCameraBuffer._AdditionalLightColor               = Shader.PropertyToID("_AdditionalLightColor");
            PerCameraBuffer._AdditionalLightDistanceAttenuation = Shader.PropertyToID("_AdditionalLightDistanceAttenuation");
            PerCameraBuffer._AdditionalLightSpotDir             = Shader.PropertyToID("_AdditionalLightSpotDir");
            PerCameraBuffer._AdditionalLightSpotAttenuation     = Shader.PropertyToID("_AdditionalLightSpotAttenuation");
            PerCameraBuffer._LightIndexBuffer                   = Shader.PropertyToID("_LightIndexBuffer");

            int maxVisibleLocalLights = renderer.maxVisibleLocalLights;

            m_LightPositions            = new Vector4[maxVisibleLocalLights];
            m_LightColors               = new Vector4[maxVisibleLocalLights];
            m_LightDistanceAttenuations = new Vector4[maxVisibleLocalLights];
            m_LightSpotDirections       = new Vector4[maxVisibleLocalLights];
            m_LightSpotAttenuations     = new Vector4[maxVisibleLocalLights];
        }
        public LocalShadowsPass(LightweightForwardRenderer renderer) : base(renderer)
        {
            RegisterShaderPassName("ShadowCaster");

            int maxVisibleLocalLights = renderer.maxVisibleLocalLights;

            m_LocalShadowMatrices = new Matrix4x4[maxVisibleLocalLights];
            m_LocalLightSlices    = new ShadowSliceData[maxVisibleLocalLights];
            m_LocalShadowStrength = new float[maxVisibleLocalLights];

            LocalShadowConstantBuffer._LocalWorldToShadowAtlas = Shader.PropertyToID("_LocalWorldToShadowAtlas");
            LocalShadowConstantBuffer._LocalShadowStrength     = Shader.PropertyToID("_LocalShadowStrength");
            LocalShadowConstantBuffer._LocalShadowOffset0      = Shader.PropertyToID("_LocalShadowOffset0");
            LocalShadowConstantBuffer._LocalShadowOffset1      = Shader.PropertyToID("_LocalShadowOffset1");
            LocalShadowConstantBuffer._LocalShadowOffset2      = Shader.PropertyToID("_LocalShadowOffset2");
            LocalShadowConstantBuffer._LocalShadowOffset3      = Shader.PropertyToID("_LocalShadowOffset3");
            LocalShadowConstantBuffer._LocalShadowmapSize      = Shader.PropertyToID("_LocalShadowmapSize");

            m_LocalShadowmapFormat = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.Shadowmap)
                ? RenderTextureFormat.Shadowmap
                : RenderTextureFormat.Depth;
        }
示例#19
0
        public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                                     ref CullResults cullResults,
                                     ref RenderingData renderingData)
        {
            if (renderingData.shadowData.renderedDirectionalShadowQuality == LightShadows.None)
            {
                return;
            }

            CommandBuffer cmd = CommandBufferPool.Get("Collect Shadows");

            cmd.GetTemporaryRT(colorAttachmentHandle.id, descriptor, FilterMode.Bilinear);
            SetShadowCollectPassKeywords(cmd, ref renderingData.shadowData);

            // Note: The source isn't actually 'used', but there's an engine peculiarity (bug) that
            // doesn't like null sources when trying to determine a stereo-ized blit.  So for proper
            // stereo functionality, we use the screen-space shadow map as the source (until we have
            // a better solution).
            // An alternative would be DrawProcedural, but that would require further changes in the shader.
            RenderTargetIdentifier screenSpaceOcclusionTexture = colorAttachmentHandle.Identifier();

            SetRenderTarget(cmd, screenSpaceOcclusionTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store,
                            ClearFlag.Color | ClearFlag.Depth, Color.white, descriptor.dimension);
            cmd.Blit(screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, renderer.GetMaterial(MaterialHandles.ScrenSpaceShadow));

            if (renderingData.cameraData.isStereoEnabled)
            {
                Camera camera = renderingData.cameraData.camera;
                context.StartMultiEye(camera);
                context.ExecuteCommandBuffer(cmd);
                context.StopMultiEye(camera);
            }
            else
            {
                context.ExecuteCommandBuffer(cmd);
            }
            CommandBufferPool.Release(cmd);
        }
示例#20
0
        public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                                     ref CullResults cullResults,
                                     ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(k_RenderTransparentsTag);

            using (new ProfilingSample(cmd, k_RenderTransparentsTag))
            {
                SetRenderTarget(cmd, RenderBufferLoadAction.Load, RenderBufferStoreAction.Store, clearFlag, CoreUtils.ConvertSRGBToActiveColorSpace(clearColor));
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                Camera camera       = renderingData.cameraData.camera;
                var    drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonTransparent, rendererConfiguration, dynamicBatching);
                context.DrawRenderers(cullResults.visibleRenderers, ref drawSettings, transparentFilterSettings);

                // Render objects that did not match any shader pass with error shader
                RenderObjectsWithError(renderer, ref context, ref cullResults, camera, transparentFilterSettings, SortFlags.None);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
        public override void Execute(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                                     ref CullResults cullResults,
                                     ref RenderingData renderingData)
        {
            CommandBuffer cmd          = CommandBufferPool.Get("Copy Color");
            Downsampling  downsampling = renderingData.cameraData.opaqueTextureDownsampling;
            float         opaqueScaler = m_OpaqueScalerValues[(int)downsampling];

            RenderTextureDescriptor opaqueDesc    = LightweightForwardRenderer.CreateRTDesc(ref renderingData.cameraData, opaqueScaler);
            RenderTargetIdentifier  colorRT       = source.Identifier();
            RenderTargetIdentifier  opaqueColorRT = destination.Identifier();

            cmd.GetTemporaryRT(destination.id, opaqueDesc, renderingData.cameraData.opaqueTextureDownsampling == Downsampling.None ? FilterMode.Point : FilterMode.Bilinear);
            switch (downsampling)
            {
            case Downsampling.None:
                cmd.Blit(colorRT, opaqueColorRT);
                break;

            case Downsampling._2xBilinear:
                cmd.Blit(colorRT, opaqueColorRT);
                break;

            case Downsampling._4xBox:
                Material samplingMaterial = renderer.GetMaterial(MaterialHandles.Sampling);
                samplingMaterial.SetFloat(m_SampleOffsetShaderHandle, 2);
                cmd.Blit(colorRT, opaqueColorRT, samplingMaterial, 0);
                break;

            case Downsampling._4xBilinear:
                cmd.Blit(colorRT, opaqueColorRT);
                break;
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
 public ScriptableRenderPass(LightweightForwardRenderer renderer)
 {
     this.renderer = renderer;
 }
 public DepthOnlyPass(LightweightForwardRenderer renderer) : base(renderer)
 {
     RegisterShaderPassName("DepthOnly");
 }
 public TransparentPostProcessPass(LightweightForwardRenderer renderer) : base(renderer)
 {
 }
 public CreateLightweightRenderTexturesPass(LightweightForwardRenderer renderer) : base(renderer)
 {
 }
示例#26
0
 public SceneViewDepthCopyPass(LightweightForwardRenderer renderer) : base(renderer)
 {
 }
 public CopyColorPass(LightweightForwardRenderer renderer) : base(renderer)
 {
     m_SamplingMaterial         = renderer.GetMaterial(MaterialHandles.Sampling);
     m_SampleOffsetShaderHandle = Shader.PropertyToID("_SampleOffset");
 }
 public FinalBlitPass(LightweightForwardRenderer renderer) : base(renderer)
 {
     m_BlitMaterial = renderer.GetMaterial(MaterialHandles.Blit);
 }
        public void Setup(LightweightForwardRenderer renderer, ref ScriptableRenderContext context,
                          ref CullResults cullResults, ref RenderingData renderingData)
        {
            Init();

            renderer.Clear();

            renderer.SetupPerObjectLightIndices(ref cullResults, ref renderingData.lightData);
            RenderTextureDescriptor baseDescriptor   = LightweightForwardRenderer.CreateRTDesc(ref renderingData.cameraData);
            RenderTextureDescriptor shadowDescriptor = baseDescriptor;

            shadowDescriptor.dimension = TextureDimension.Tex2D;

            bool requiresCameraDepth  = renderingData.cameraData.requiresDepthTexture;
            bool requiresDepthPrepass = renderingData.shadowData.requiresScreenSpaceShadowResolve ||
                                        renderingData.cameraData.isSceneViewCamera ||
                                        (requiresCameraDepth &&
                                         !LightweightForwardRenderer.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;

            if (renderingData.shadowData.renderDirectionalShadows)
            {
                m_DirectionalShadowPass.Setup(DirectionalShadowmap);
                renderer.EnqueuePass(m_DirectionalShadowPass);
            }

            if (renderingData.shadowData.renderLocalShadows)
            {
                m_LocalShadowPass.Setup(LocalShadowmap, renderer.maxVisibleLocalLights);
                renderer.EnqueuePass(m_LocalShadowPass);
            }

            renderer.EnqueuePass(m_SetupForwardRenderingPass);

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

            if (renderingData.shadowData.renderDirectionalShadows &&
                renderingData.shadowData.requiresScreenSpaceShadowResolve)
            {
                m_ScreenSpaceShadowResovePass.Setup(baseDescriptor, ScreenSpaceShadowmap);
                renderer.EnqueuePass(m_ScreenSpaceShadowResovePass);
            }

            bool requiresDepthAttachment = requiresCameraDepth && !requiresDepthPrepass;
            bool requiresColorAttachment =
                LightweightForwardRenderer.RequiresIntermediateColorTexture(
                    ref renderingData.cameraData,
                    baseDescriptor,
                    requiresDepthAttachment);
            RenderTargetHandle colorHandle = (requiresColorAttachment) ? Color : RenderTargetHandle.CameraTarget;
            RenderTargetHandle depthHandle = (requiresDepthAttachment) ? DepthAttachment : RenderTargetHandle.CameraTarget;

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

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

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

            Camera camera          = renderingData.cameraData.camera;
            bool   dynamicBatching = renderingData.supportsDynamicBatching;
            RendererConfiguration rendererConfiguration = LightweightForwardRenderer.GetRendererConfiguration(renderingData.lightData.totalAdditionalLightsCount);

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

            m_RenderOpaqueForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, LightweightForwardRenderer.GetCameraClearFlag(camera), camera.backgroundColor, rendererConfiguration, dynamicBatching);
            renderer.EnqueuePass(m_RenderOpaqueForwardPass);

            if (renderingData.cameraData.postProcessEnabled &&
                renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(renderer.postProcessRenderContext))
            {
                m_OpaquePostProcessPass.Setup(renderer.postProcessRenderContext, baseDescriptor, colorHandle);
                renderer.EnqueuePass(m_OpaquePostProcessPass);
            }

            if (camera.clearFlags == CameraClearFlags.Skybox)
            {
                renderer.EnqueuePass(m_DrawSkyboxPass);
            }

            if (depthHandle != RenderTargetHandle.CameraTarget)
            {
                m_CopyDepthPass.Setup(depthHandle, DepthTexture);
                renderer.EnqueuePass(m_CopyDepthPass);
            }

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

            m_RenderTransparentForwardPass.Setup(baseDescriptor, colorHandle, depthHandle, ClearFlag.None, camera.backgroundColor, rendererConfiguration, dynamicBatching);
            renderer.EnqueuePass(m_RenderTransparentForwardPass);

            if (renderingData.cameraData.postProcessEnabled)
            {
                m_TransparentPostProcessPass.Setup(renderer.postProcessRenderContext, baseDescriptor, colorHandle);
                renderer.EnqueuePass(m_TransparentPostProcessPass);
            }
            else if (!renderingData.cameraData.isOffscreenRender && colorHandle != RenderTargetHandle.CameraTarget)
            {
                m_FinalBlitPass.Setup(baseDescriptor, colorHandle);
                renderer.EnqueuePass(m_FinalBlitPass);
            }

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

#if UNITY_EDITOR
            if (renderingData.cameraData.isSceneViewCamera)
            {
                m_SceneViewDepthCopyPass.Setup(DepthTexture);
                renderer.EnqueuePass(m_SceneViewDepthCopyPass);
            }
#endif
        }
示例#30
0
 public RenderOpaqueForwardPass(LightweightForwardRenderer renderer) : base(renderer)
 {
 }