예제 #1
0
        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            cmd.GetTemporaryRT(m_ScreenSpaceShadowmap.id, m_RenderTextureDescriptor, FilterMode.Bilinear);

            RenderTargetIdentifier screenSpaceOcclusionTexture = m_ScreenSpaceShadowmap.Identifier();

            ConfigureTarget(screenSpaceOcclusionTexture);
            ConfigureClear(ClearFlag.All, Color.white);
        }
예제 #2
0
        public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {
            cmd.GetTemporaryRT(m_ScreenSpaceShadowmap.id, m_RenderTextureDescriptor, FilterMode.Bilinear);

            // 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 = m_ScreenSpaceShadowmap.Identifier();

            ConfigureTarget(screenSpaceOcclusionTexture);
            ConfigureClear(ClearFlag.All, Color.white);
        }
예제 #3
0
 public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
 {
     //cmd.GetTemporaryRT(depthAttachmentHandle.id, descriptor, FilterMode.Point);
     depthAttachmentHandle.GetTemporary(cmd, descriptor, FilterMode.Point);
     ConfigureTarget(depthAttachmentHandle.Identifier());
     ConfigureClear(ClearFlag.Depth, Color.black);
 }
        public override void Setup(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            Camera camera = renderingData.cameraData.camera;
            RenderTextureDescriptor cameraTargetDescriptor = renderingData.cameraData.cameraTargetDescriptor;

            bool mainLightShadows            = m_MainLightShadowCasterPass.Setup(ref renderingData);
            bool additionalLightShadows      = m_AdditionalLightsShadowCasterPass.Setup(ref renderingData);
            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 = renderingData.cameraData.isSceneViewCamera ||
                                        (renderingData.cameraData.requiresDepthTexture && (!CanCopyDepth(ref renderingData.cameraData)));

            requiresDepthPrepass |= resolveShadowsInScreenSpace;
            bool createColorTexture = RequiresIntermediateColorTexture(ref renderingData, cameraTargetDescriptor) ||
                                      rendererFeatures.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;
            bool postProcessEnabled   = renderingData.cameraData.postProcessEnabled;
            bool hasOpaquePostProcess = postProcessEnabled &&
                                        renderingData.cameraData.postProcessLayer.HasOpaqueOnlyEffects(RenderingUtils.postProcessRenderContext);

            m_ActiveCameraColorAttachment = (createColorTexture) ? m_CameraColorAttachment : RenderTargetHandle.CameraTarget;
            m_ActiveCameraDepthAttachment = (createDepthTexture) ? m_CameraDepthAttachment : RenderTargetHandle.CameraTarget;
            if (createColorTexture || createDepthTexture)
            {
                CreateCameraRenderTarget(context, ref renderingData.cameraData);
            }
            CreateFeedBackRenderTarget(context, ref renderingData.cameraData);
            m_FeedBackPass.ConfigureTarget(m_FeedBackBufferAttachment);
            ConfigureCameraTarget(m_ActiveCameraColorAttachment.Identifier(), m_ActiveCameraDepthAttachment.Identifier());

            for (int i = 0; i < rendererFeatures.Count; ++i)
            {
                rendererFeatures[i].AddRenderPasses(this, ref renderingData);
            }

            int count = activeRenderPassQueue.Count;

            for (int i = count - 1; i >= 0; i--)
            {
                if (activeRenderPassQueue[i] == null)
                {
                    activeRenderPassQueue.RemoveAt(i);
                }
            }
            bool hasAfterRendering = activeRenderPassQueue.Find(x => x.renderPassEvent == RenderPassEvent.AfterRendering) != null;

            if (mainLightShadows)
            {
                EnqueuePass(m_MainLightShadowCasterPass);
            }

            if (additionalLightShadows)
            {
                EnqueuePass(m_AdditionalLightsShadowCasterPass);
            }

            if (requiresDepthPrepass)
            {
                m_DepthPrepass.Setup(cameraTargetDescriptor, m_DepthTexture);
                EnqueuePass(m_DepthPrepass);
            }

            if (resolveShadowsInScreenSpace)
            {
                m_ScreenSpaceShadowResolvePass.Setup(cameraTargetDescriptor);
                EnqueuePass(m_ScreenSpaceShadowResolvePass);
            }
            EnqueuePass(m_FeedBackPass);

            EnqueuePass(m_RenderOpaqueForwardPass);

            if (hasOpaquePostProcess)
            {
                m_OpaquePostProcessPass.Setup(cameraTargetDescriptor, m_ActiveCameraColorAttachment, m_ActiveCameraColorAttachment);
            }

            if (camera.clearFlags == CameraClearFlags.Skybox && RenderSettings.skybox != null)
            {
                EnqueuePass(m_DrawSkyboxPass);
            }

            // 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(m_ActiveCameraDepthAttachment, m_DepthTexture);
                EnqueuePass(m_CopyDepthPass);
            }

            if (renderingData.cameraData.requiresOpaqueTexture)
            {
                m_CopyColorPass.Setup(m_ActiveCameraColorAttachment.Identifier(), m_OpaqueColor);
                EnqueuePass(m_CopyColorPass);
            }

            EnqueuePass(m_RenderTransparentForwardPass);

            bool afterRenderExists = renderingData.cameraData.captureActions != null ||
                                     hasAfterRendering;

            // if we have additional filters
            // we need to stay in a RT
            if (afterRenderExists)
            {
                // perform post with src / dest the same
                if (postProcessEnabled)
                {
                    m_PostProcessPass.Setup(cameraTargetDescriptor, m_ActiveCameraColorAttachment, m_ActiveCameraColorAttachment);
                    EnqueuePass(m_PostProcessPass);
                }

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

                    m_FinalBlitPass.Setup(cameraTargetDescriptor, m_ActiveCameraColorAttachment);
                    EnqueuePass(m_FinalBlitPass);
                }
            }
            else
            {
                if (postProcessEnabled)
                {
                    m_PostProcessPass.Setup(cameraTargetDescriptor, m_ActiveCameraColorAttachment, RenderTargetHandle.CameraTarget);
                    EnqueuePass(m_PostProcessPass);
                }
                else if (m_ActiveCameraColorAttachment != RenderTargetHandle.CameraTarget)
                {
                    m_FinalBlitPass.Setup(cameraTargetDescriptor, m_ActiveCameraColorAttachment);
                    EnqueuePass(m_FinalBlitPass);
                }
            }

#if UNITY_EDITOR
            if (renderingData.cameraData.isSceneViewCamera)
            {
                m_SceneViewDepthCopyPass.Setup(m_DepthTexture);
                EnqueuePass(m_SceneViewDepthCopyPass);
            }
#endif
        }
예제 #5
0
        public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
        {
            var src = (settings.source == Source.Color) ? renderer.cameraColorTarget : m_SrcRenderTextureHandle.Identifier();

            bloomPass.Setup(src, settings.dstTextureId);
            SetupBloomProps();
            renderer.EnqueuePass(bloomPass);
        }
        void SetupVxShadowReceiverConstants(CommandBuffer cmd, int kernel, ref ComputeShader computeShader, ref Camera camera, ref VisibleLight shadowLight)
        {
            var light = shadowLight.light;
            var vxsm  = light.GetComponent <DirectionalVxShadowMap>();

            float screenSizeX    = (float)camera.pixelWidth;
            float screenSizeY    = (float)camera.pixelHeight;
            float invScreenSizeX = 1.0f / screenSizeX;
            float invScreenSizeY = 1.0f / screenSizeY;

            var gpuView = camera.worldToCameraMatrix;
            var gpuProj = GL.GetGPUProjectionMatrix(camera.projectionMatrix, true);

            var viewMatrix     = gpuView;
            var projMatrix     = gpuProj;
            var viewProjMatrix = projMatrix * viewMatrix;

            var vxShadowMapsBuffer = VxShadowMapsManager.Instance.VxShadowMapsBuffer;

            int beginOffset = (int)(vxsm.bitset & 0x3FFFFFFF);

            int   voxelZBias  = 2;
            float voxelUpBias = 1 * (dirVxShadowMap.VolumeScale / dirVxShadowMap.VoxelResolutionInt);

            cmd.SetComputeVectorParam(computeShader, VxShadowMapConstantBuffer._ShadowData, new Vector4(light.shadowStrength, 0.0f, 0.0f, 0.0f));

            cmd.SetComputeMatrixParam(computeShader, VxShadowMapConstantBuffer._InvViewProjMatrix, viewProjMatrix.inverse);
            cmd.SetComputeVectorParam(computeShader, VxShadowMapConstantBuffer._ScreenSize, new Vector4(screenSizeX, screenSizeY, invScreenSizeX, invScreenSizeY));
            cmd.SetComputeIntParam(computeShader, VxShadowMapConstantBuffer._BeginOffset, beginOffset);
            cmd.SetComputeIntParam(computeShader, VxShadowMapConstantBuffer._VoxelZBias, voxelZBias);
            cmd.SetComputeFloatParam(computeShader, VxShadowMapConstantBuffer._VoxelUpBias, voxelUpBias);

            cmd.SetComputeBufferParam(computeShader, kernel, VxShadowMapConstantBuffer._VxShadowMapsBuffer, vxShadowMapsBuffer);
            cmd.SetComputeTextureParam(computeShader, kernel, VxShadowMapConstantBuffer._ScreenSpaceShadowOutput, m_ScreenSpaceShadowmapTexture.Identifier());
        }
예제 #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();

                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);
        }