/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException(nameof(renderer)); } CommandBuffer cmd = CommandBufferPool.Get(k_FinalBlitTag); if (renderingData.cameraData.isStereoEnabled || renderingData.cameraData.isSceneViewCamera) { cmd.Blit(colorAttachmentHandle.Identifier(), BuiltinRenderTextureType.CameraTarget); } else { cmd.SetGlobalTexture("_BlitTex", colorAttachmentHandle.Identifier()); 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); ScriptableRenderer.RenderFullscreenQuad(cmd, renderer.GetMaterial(MaterialHandle.Blit)); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } CommandBuffer cmd = CommandBufferPool.Get(k_DepthCopyTag); RenderTargetIdentifier depthSurface = source.Identifier(); RenderTargetIdentifier copyDepthSurface = destination.Identifier(); Material depthCopyMaterial = renderer.GetMaterial(MaterialHandle.CopyDepth); RenderTextureDescriptor descriptor = ScriptableRenderer.CreateRenderTextureDescriptor(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); cmd.SetGlobalTexture("_CameraDepthAttachment", source.Identifier()); if (renderingData.cameraData.msaaSamples > 1) { cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthNoMsaa); if (renderingData.cameraData.msaaSamples == 4) { cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthMsaa2); cmd.EnableShaderKeyword(ShaderKeywordStrings.DepthMsaa4); } else { cmd.EnableShaderKeyword(ShaderKeywordStrings.DepthMsaa2); cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthMsaa4); } cmd.Blit(depthSurface, copyDepthSurface, depthCopyMaterial); } else { cmd.EnableShaderKeyword(ShaderKeywordStrings.DepthNoMsaa); cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthMsaa2); cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthMsaa4); ScriptableRenderer.CopyTexture(cmd, depthSurface, copyDepthSurface, depthCopyMaterial); } context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } if (renderingData.lightData.mainLightIndex == -1) { return; } CommandBuffer cmd = CommandBufferPool.Get(k_CollectShadowsTag); cmd.GetTemporaryRT(colorAttachmentHandle.id, descriptor, 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 = colorAttachmentHandle.Identifier(); SetRenderTarget(cmd, screenSpaceOcclusionTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.Color | ClearFlag.Depth, Color.white, descriptor.dimension); // This blit is troublesome. When MSAA is enabled it will render a fullscreen quad + store resolved MSAA + extra blit // This consumes about 10MB of extra unnecessary bandwidth on boat attack. // In order to avoid it we can do a cmd.DrawMesh instead, however because LWRP doesn't setup camera matrices itself, // we would need to call an extra SetupCameraProperties here just to setup those matrices which is also troublesome. // We need get rid of SetupCameraProperties and setup camera matrices in LWRP ASAP. cmd.Blit(screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, renderer.GetMaterial(MaterialHandle.ScreenSpaceShadow)); 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); }
/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } CommandBuffer cmd = CommandBufferPool.Get(k_CopyColorTag); Downsampling downsampling = renderingData.cameraData.opaqueTextureDownsampling; float opaqueScaler = m_OpaqueScalerValues[(int)downsampling]; RenderTextureDescriptor opaqueDesc = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData, opaqueScaler); opaqueDesc.msaaSamples = 1; opaqueDesc.depthBufferBits = 0; 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(MaterialHandle.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); }
/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } // 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(ShaderKeywordStrings.DepthNoMsaa); cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthMsaa2); cmd.DisableShaderKeyword(ShaderKeywordStrings.DepthMsaa4); cmd.Blit(source.Identifier(), BuiltinRenderTextureType.CameraTarget, renderer.GetMaterial(MaterialHandle.CopyDepth)); context.ExecuteCommandBuffer(cmd); CommandBufferPool.Release(cmd); }
/// <inheritdoc/> public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) { if (renderer == null) { throw new ArgumentNullException("renderer"); } if (renderingData.lightData.mainLightIndex == -1) { return; } CommandBuffer cmd = CommandBufferPool.Get(k_CollectShadowsTag); cmd.GetTemporaryRT(colorAttachmentHandle.id, descriptor, 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 = colorAttachmentHandle.Identifier(); SetRenderTarget(cmd, screenSpaceOcclusionTexture, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.Color | ClearFlag.Depth, Color.white, descriptor.dimension); cmd.Blit(screenSpaceOcclusionTexture, screenSpaceOcclusionTexture, renderer.GetMaterial(MaterialHandle.ScreenSpaceShadow)); 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); }