public override void Draw(RenderDrawContext context, RenderView renderView, RenderViewStage renderViewStage, int startIndex, int endIndex) { lock (drawLock) { context.PushRenderTargets(); DrawInternal(context, renderView, renderViewStage, startIndex, endIndex); context.PopRenderTargets(); } }
protected override void DrawCore(RenderDrawContext context) { try { context.PushRenderTargets(); minMax.SetInput(context.CommandList.DepthStencilBuffer); ((RendererBase)minMax).Draw(context); IsResultAvailable = minMax.IsResultAvailable; if (IsResultAvailable) { DepthMinMax = minMax.Result; } } finally { context.PopRenderTargets(); } }
protected override void DrawCore(RenderDrawContext context) { var currentViewport = context.CommandList.Viewport; // GBuffer //if (GBuffer) //{ // context.PushRenderTargets(); // // var gbuffer = PushScopedResource(Context.Allocator.GetTemporaryTexture2D((int)currentViewport.Width, (int)currentViewport.Height, GBufferRenderStage.Output.RenderTargetFormat0)); // context.CommandList.Clear(gbuffer, Color4.Black); // context.CommandList.SetDepthAndRenderTarget(context.CommandList.DepthStencilBuffer, gbuffer); // RenderSystem.Draw(context, mainRenderView, GBufferRenderStage); // // context.PopRenderTargets(); //} // Shadow maps var shadowMapRenderer = meshPipelinePlugin?.ForwardLightingRenderFeature?.ShadowMapRenderer; if (Shadows && shadowMapRenderer != null) { // Clear atlases shadowMapRenderer.PrepareAtlasAsRenderTargets(context.CommandList); context.PushRenderTargets(); // Draw all shadow views generated for the current view foreach (var renderView in RenderSystem.Views) { var shadowmapRenderView = renderView as ShadowMapRenderView; if (shadowmapRenderView != null && shadowmapRenderView.RenderView == MainRenderView) { var shadowMapRectangle = shadowmapRenderView.Rectangle; shadowmapRenderView.ShadowMapTexture.Atlas.RenderFrame.Activate(context); shadowmapRenderView.ShadowMapTexture.Atlas.MarkClearNeeded(); context.CommandList.SetViewport(new Viewport(shadowMapRectangle.X, shadowMapRectangle.Y, shadowMapRectangle.Width, shadowMapRectangle.Height)); RenderSystem.Draw(context, shadowmapRenderView, ShadowMapRenderStage); } } context.PopRenderTargets(); shadowMapRenderer.PrepareAtlasAsShaderResourceViews(context.CommandList); } // Draw [main view | main stage] RenderSystem.Draw(context, MainRenderView, MainRenderStage); // Some transparent shaders will require the depth as a shader resource - resolve it only once and set it here Texture depthStencilSRV = ResolveDepthAsSRV(context); // Draw [main view | transparent stage] RenderSystem.Draw(context, MainRenderView, TransparentRenderStage); // Free the depth texture since we won't need it anymore if (depthStencilSRV != null) { context.Resolver.ReleaseDepthStenctilAsShaderResource(depthStencilSRV); } }
private Texture ResolveDepthAsSRV(RenderDrawContext context) { if (!enableDepthAsShaderResource) return null; context.PushRenderTargets(); var currentRenderFrame = context.RenderContext.Tags.Get(RenderFrame.Current); var depthStencilSRV = context.Resolver.ResolveDepthStencil(currentRenderFrame.DepthStencil); foreach (var renderFeature in RenderSystem.RenderFeatures) { if (!(renderFeature is RootEffectRenderFeature)) continue; var depthLogicalKey = ((RootEffectRenderFeature)renderFeature).CreateViewLogicalGroup("Depth"); var viewFeature = MainRenderView.Features[renderFeature.Index]; // Copy ViewProjection to PerFrame cbuffer foreach (var viewLayout in viewFeature.Layouts) { var resourceGroup = viewLayout.Entries[MainRenderView.Index].Resources; var depthLogicalGroup = viewLayout.GetLogicalGroup(depthLogicalKey); if (depthLogicalGroup.Hash == ObjectId.Empty) continue; // Might want to use ProcessLogicalGroup if more than 1 Recource resourceGroup.DescriptorSet.SetShaderResourceView(depthLogicalGroup.DescriptorSlotStart, depthStencilSRV); } } depthStencilROCached = context.Resolver.GetDepthStencilAsRenderTarget(currentRenderFrame.DepthStencil, depthStencilROCached); currentRenderFrame.Activate(context, depthStencilROCached); context.PopRenderTargets(); return depthStencilSRV; }