No announcement yet.

Altering depth buffer, and extra render passes?

  • Filter
  • Time
  • Show
Clear All
new posts

    Altering depth buffer, and extra render passes?

    First up - my ultimate goal here is to render some nice portals (similar to valves game "Portal") - in a fairly optimal manner, using a similar method to the game "Budget Cuts" instead of render targets.

    The plan is:
    1. render scene normally (this works)
    2. clear depth buffer, setting to "nearest", so nothing can be drawn (this does not work - and is main subject of this question)
    3. render portal mesh at maximum depth, punching a hole in the depth buffer to render the portal in (not yet started on this)
    4. render scene again "from the portals point of view" (this also works)
    Worth noting, I've altered the renderer to optionally skip clearing the screen in its prepass (and indeed skip the clear on my second render pass)

    if I just run step (1) and (4) - the results are as I'd expect - the second render still reads the depth buffer from the first, and occludes objects.

    My current issue is that if I add a DrawClearQuad between the two renders - there is no change in my result..
    However - if I disable the second render (by setting doSecondRendering below to false) I indeed get a clear screen, with the colour passed to DrawClearQuad.

    Rendering thread code below:

        FMemMark MemStackMark(FMemStack::Get());
        //Clear screen
        FIntRect trect(0, 0, 0, 0);
            FRHIRenderPassInfo RPInfo(SceneRenderer->ViewFamily.RenderTarget->GetRenderTargetTexture(), ERenderTargetActions::Load_Store);
            //FRHIRenderPassInfo RPInfo(SceneRenderer->ViewFamily.RenderTarget->GetRenderTargetTexture(), ERenderTargetActions::DontLoad_Store);
            //FRHIRenderPassInfo RPInfo(SceneRenderer->ViewFamily.RenderTarget->GetRenderTargetTexture(), EDepthStencilTargetActions::LoadDepthStencil_StoreDepthStencil);
            //FRHIRenderPassInfo(FRHITexture * DepthRT, EDepthStencilTargetActions DepthActions, FRHITexture * ResolveDepthRT = nullptr, FExclusiveDepthStencil InEDS = FExclusiveDepthStencil::DepthWrite_StencilWrite)
            RHICmdList.BeginRenderPass(RPInfo, TEXT("ClearSceneCaptureContent"));
            pDrawClearQuad(RHICmdList, true, FLinearColor::Blue, true, 0, false, 0, SceneRenderer->ViewFamily.RenderTarget->GetSizeXY(), trect);
        //RHICmdList.TransitionResource(EResourceTransitionAccess::EReadable, SceneRenderer->ViewFamily.RenderTarget->GetRenderTargetTexture());
        bool doSecondRendering = true;
            SCOPED_DRAW_EVENT(RHICmdList, RenderScene);
        FSceneRenderer::WaitForTasksClearSnapshotsAndDeleteSceneRenderer(RHICmdList, SceneRenderer);
    I've left most of my commented out code in to give an idea of what I've been attempting.

    What I find particularly mysterious is that when I have the second render enabled, the data from the first render is not cleared - feels like I may be missing something fairly fundamental about rendering passes.

    Right now, I'd be happy if I could clear/(set to min/max) the depth buffer before the second render.

    Could anyone offer any guidance, hints, suggestions or questions?
    Last edited by Alex Chozabu P-B; 07-26-2019, 05:22 PM.
    See my PortalsBP on the marketplace
    Currently working on Wheelz2 and Zario

    OK solved - after reading through how the basepass uses DrawClearQuad I've altered my FRHIRenderPassInfo to let me alter the depth buffer

            FRHIRenderPassInfo RPInfo(SceneRenderer->ViewFamily.RenderTarget->GetRenderTargetTexture(), ERenderTargetActions::Load_Store);
            RPInfo.DepthStencilRenderTarget.Action = MakeDepthStencilTargetActions(ERenderTargetActions::Clear_Store, ERenderTargetActions::Clear_Store);
            RPInfo.DepthStencilRenderTarget.DepthStencilTarget = FSceneRenderTargets::Get(RHICmdList).GetSceneDepthSurface();
            RPInfo.DepthStencilRenderTarget.ExclusiveDepthStencil = FExclusiveDepthStencil::DepthWrite_StencilWrite;
    still quite some way to get everything I want working, but am at least back on track
    See my PortalsBP on the marketplace
    Currently working on Wheelz2 and Zario