public LightweightRenderPipeline(LightweightRenderPipelineAsset asset)
        {
            SetSupportedRenderingFeatures();

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

            PerFrameBuffer._Time           = Shader.PropertyToID("_Time");
            PerFrameBuffer._SinTime        = Shader.PropertyToID("_SinTime");
            PerFrameBuffer._CosTime        = Shader.PropertyToID("_CosTime");
            PerFrameBuffer.unity_DeltaTime = Shader.PropertyToID("unity_DeltaTime");
            PerFrameBuffer._TimeParameters = Shader.PropertyToID("_TimeParameters");

            PerCameraBuffer._InvCameraViewProj   = Shader.PropertyToID("_InvCameraViewProj");
            PerCameraBuffer._ScreenParams        = Shader.PropertyToID("_ScreenParams");
            PerCameraBuffer._ScaledScreenParams  = Shader.PropertyToID("_ScaledScreenParams");
            PerCameraBuffer._WorldSpaceCameraPos = Shader.PropertyToID("_WorldSpaceCameraPos");

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

            Shader.globalRenderPipeline = "LightweightPipeline";

            Lightmapping.SetDelegate(lightsDelegate);

            CameraCaptureBridge.enabled = true;

            RenderingUtils.ClearSystemInfoCache();
        }
Beispiel #2
0
        /// <inheritdoc/>
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            using (new ProfilingSample(cmd, m_ProfilerTag))
            {
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                if (IsAfterPP)
                {
                    SetRenderTarget(
                        cmd,
                        BuiltinRenderTextureType.CameraTarget,
                        RenderBufferLoadAction.Load,
                        RenderBufferStoreAction.Store,
                        ClearFlag.None,
                        Color.black,
                        TargetDimension);
                }

                Camera camera       = renderingData.cameraData.camera;
                var    drawSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, SortingCriteria.CommonTransparent);
                context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_FilteringSettings);

                // Render objects that did not match any shader pass with error shader
                RenderingUtils.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_FilteringSettings, SortingCriteria.None);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
Beispiel #3
0
        static RenderTextureDescriptor CreateRenderTextureDescriptor(Camera camera, float renderScale,
                                                                     bool isStereoEnabled, bool isHdrEnabled, int msaaSamples)
        {
            RenderTextureDescriptor desc;
            RenderTextureFormat     renderTextureFormatDefault = RenderTextureFormat.Default;

            if (isStereoEnabled)
            {
                desc = XRGraphics.eyeTextureDesc;
                renderTextureFormatDefault = desc.colorFormat;
            }
            else
            {
                desc        = new RenderTextureDescriptor(camera.pixelWidth, camera.pixelHeight);
                desc.width  = (int)((float)desc.width * renderScale);
                desc.height = (int)((float)desc.height * renderScale);
            }

            // TODO: when preserve framebuffer alpha is enabled we can't use RGB111110Float format.
            bool useRGB111110             = Application.isMobilePlatform && RenderingUtils.SupportsRenderTextureFormat(RenderTextureFormat.RGB111110Float);
            RenderTextureFormat hdrFormat = (useRGB111110) ? RenderTextureFormat.RGB111110Float : RenderTextureFormat.DefaultHDR;

            desc.colorFormat       = isHdrEnabled ? hdrFormat : renderTextureFormatDefault;
            desc.depthBufferBits   = 32;
            desc.enableRandomWrite = false;
            desc.sRGB            = (QualitySettings.activeColorSpace == ColorSpace.Linear);
            desc.msaaSamples     = msaaSamples;
            desc.bindMS          = false;
            desc.useDynamicScale = camera.allowDynamicResolution;
            return(desc);
        }
        /// <inheritdoc/>
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            const string  semiTranShadowKeywords = "_SEMITRANSPARENT_SHADOWS";
            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            using (new ProfilingSample(cmd, m_ProfilerTag))
            {
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                Camera camera       = renderingData.cameraData.camera;
                var    sortFlags    = renderingData.cameraData.defaultOpaqueSortFlags;
                var    drawSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, sortFlags);
                CoreUtils.SetKeyword(cmd, semiTranShadowKeywords, renderingData.shadowData.supportsSemiTransShadow);

                if (IsAfterPP)
                {
                    SetRenderTarget(
                        cmd,
                        BuiltinRenderTextureType.CameraTarget,
                        RenderBufferLoadAction.Load,
                        RenderBufferStoreAction.Store,
                        ClearFlag.None,
                        Color.black,
                        TargetDimension);
                }

                context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_FilteringSettings);

                // Render objects that did not match any shader pass with error shader
                RenderingUtils.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_FilteringSettings, SortingCriteria.None);
            }
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
Beispiel #5
0
 public void Setup(RenderTextureDescriptor baseDescriptor)
 {
     m_RenderTextureDescriptor = baseDescriptor;
     m_RenderTextureDescriptor.depthBufferBits = 0;
     m_RenderTextureDescriptor.colorFormat     = RenderingUtils.SupportsRenderTextureFormat(RenderTextureFormat.R8)
         ? RenderTextureFormat.R8
         : RenderTextureFormat.ARGB32;
 }
Beispiel #6
0
 static ShadowUtils()
 {
     m_ShadowmapFormat = RenderingUtils.SupportsRenderTextureFormat(RenderTextureFormat.Shadowmap)
         ? RenderTextureFormat.Shadowmap
         : RenderTextureFormat.Depth;
     m_ForceShadowPointSampling = SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal &&
                                  GraphicsSettings.HasShaderDefine(Graphics.activeTier, BuiltinShaderDefine.UNITY_METAL_SHADOWS_USE_POINT_FILTERING);
 }
Beispiel #7
0
        /// <inheritdoc/>
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            using (new ProfilingSample(cmd, m_ProfilerTag))
            {
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                Camera camera       = renderingData.cameraData.camera;
                var    sortFlags    = renderingData.cameraData.defaultOpaqueSortFlags;
                var    drawSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, sortFlags);
                context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_FilteringSettings, ref m_RenderStateBlock);

                // Render objects that did not match any shader pass with error shader
                RenderingUtils.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_FilteringSettings, SortingCriteria.None);
            }
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
Beispiel #8
0
        /// <inheritdoc/>
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            using (new ProfilingSample(cmd, m_ProfilerTag))
            {
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                Camera camera       = renderingData.cameraData.camera;
                var    sortFlags    = renderingData.cameraData.defaultOpaqueSortFlags;
                var    drawSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, sortFlags);
                CoreUtils.SetKeyword(cmd, "SHADOWS_SCREEN", renderingData.shadowData.requiresScreenSpaceShadowResolve);
                CoreUtils.SetKeyword(cmd, "SS_DOWNSAMPLE", renderingData.shadowData.requiresScreenSpaceShadowResolve && renderingData.shadowData.ssShadowDownSampleSize > 1);
                context.DrawRenderers(renderingData.cullResults, ref drawSettings, ref m_FilteringSettings);

                // Render objects that did not match any shader pass with error shader
                RenderingUtils.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_FilteringSettings, SortingCriteria.None);
            }
            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
        /// <inheritdoc/>
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get(m_ProfilerTag);

            using (new ProfilingSample(cmd, m_ProfilerTag))
            {
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();

                SetRenderTarget(
                    cmd,
                    m_RenderTargetHandle.Identifier(),
                    RenderBufferLoadAction.Load,
                    RenderBufferStoreAction.Store,
                    ClearFlag.Depth,
                    Color.black,
                    TargetDimension);



                // GetCameraDescriptor
                Camera uiCamera = renderingData.uiCmaera;

                Matrix4x4 projMatrix = uiCamera.projectionMatrix;
                Matrix4x4 viewMatrix = uiCamera.worldToCameraMatrix;
                //Matrix4x4 viewProjMatrix = projMatrix * viewMatrix;
                //cmd.SetGlobalMatrix("UNITY_MATRIX_VP", viewProjMatrix);
                cmd.SetProjectionMatrix(projMatrix);
                cmd.SetViewMatrix(viewMatrix);
                cmd.SetViewProjectionMatrices(viewMatrix, projMatrix);
                cmd.SetViewport(uiCamera.pixelRect);
                context.ExecuteCommandBuffer(cmd);
                cmd.Clear();
                LWRPAdditionalCameraData additionalCameraData = null;
                //LightweightRenderPipeline.BeginCameraRenderingWrapper(context, uiCamera);
                if (!uiCamera.TryGetCullingParameters(LightweightRenderPipeline.IsStereoEnabled(uiCamera), out var cullingParameters))
                {
                    return;
                }
                if (uiCamera.cameraType == CameraType.Game || uiCamera.cameraType == CameraType.VR)
                {
                    additionalCameraData = uiCamera.gameObject.GetComponent <LWRPAdditionalCameraData>();
                }
                LightweightRenderPipeline.InitializeCameraData(renderingData.pipelineAsset, uiCamera, additionalCameraData, out var uiCameraData);
                LightweightRenderPipeline.SetupPerCameraShaderConstants(uiCameraData);


                // Get Rendering data

                var cullResults = context.Cull(ref cullingParameters);
                LightweightRenderPipeline.InitializeRenderingData(renderingData.pipelineAsset, ref uiCameraData, ref cullResults, out var uiRenderingData);

                //var drawOpaqueSettings = CreateDrawingSettings(m_ShaderTagIdList, ref uiRenderingData, SortingCriteria.CommonOpaque);
                //context.DrawRenderers(uiRenderingData.cullResults, ref drawOpaqueSettings, ref m_FilteringSettings);

                var drawTransparentSettings = CreateDrawingSettings(m_ShaderTagIdList, ref uiRenderingData, SortingCriteria.CommonTransparent);
                context.DrawRenderers(uiRenderingData.cullResults, ref drawTransparentSettings, ref m_FilteringSettings);

                // Render objects that did not match any shader pass with error shader
                RenderingUtils.RenderObjectsWithError(context, ref uiRenderingData.cullResults, uiCamera, m_FilteringSettings, SortingCriteria.None);
            }

            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }