| 72 | } |
| 73 | |
| 74 | void ForwardPass::Render(RenderContext& renderContext, GPUTexture*& input, GPUTexture*& output) |
| 75 | { |
| 76 | PROFILE_GPU_CPU("Forward"); |
| 77 | auto context = GPUDevice::Instance->GetMainContext(); |
| 78 | auto& view = renderContext.View; |
| 79 | auto mainCache = renderContext.List; |
| 80 | |
| 81 | context->ResetRenderTarget(); |
| 82 | context->ResetSR(); |
| 83 | |
| 84 | // Try to use read-only depth if supported |
| 85 | GPUTexture* depthBuffer = renderContext.Buffers->DepthBuffer; |
| 86 | GPUTextureView* depthBufferHandle = depthBuffer->View(); |
| 87 | if (EnumHasAnyFlags(depthBuffer->Flags(), GPUTextureFlags::ReadOnlyDepthView)) |
| 88 | depthBufferHandle = depthBuffer->ViewReadOnlyDepth(); |
| 89 | |
| 90 | // Check if there is no objects to render or no resources ready |
| 91 | auto& forwardList = mainCache->DrawCallsLists[(int32)DrawCallsListType::Forward]; |
| 92 | auto& distortionList = mainCache->DrawCallsLists[(int32)DrawCallsListType::Distortion]; |
| 93 | if ((forwardList.IsEmpty() && distortionList.IsEmpty()) |
| 94 | #if USE_EDITOR |
| 95 | || renderContext.View.Mode == ViewMode::PhysicsColliders |
| 96 | #endif |
| 97 | ) |
| 98 | { |
| 99 | // Skip rendering |
| 100 | Swap(input, output); |
| 101 | return; |
| 102 | } |
| 103 | if (distortionList.IsEmpty() || checkIfSkipPass()) |
| 104 | { |
| 105 | // Copy frame |
| 106 | context->SetRenderTarget(output->View()); |
| 107 | context->Draw(input); |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | PROFILE_GPU_CPU("Distortion"); |
| 112 | |
| 113 | // Peek temporary render target for the distortion pass |
| 114 | // TODO: render distortion in half-res? |
| 115 | const int32 width = renderContext.Buffers->GetWidth(); |
| 116 | const int32 height = renderContext.Buffers->GetHeight(); |
| 117 | const int32 distortionWidth = width; |
| 118 | const int32 distortionHeight = height; |
| 119 | const auto tempDesc = GPUTextureDescription::New2D(distortionWidth, distortionHeight, PixelFormat::R8G8B8A8_UNorm); |
| 120 | auto distortionRT = RenderTargetPool::Get(tempDesc); |
| 121 | RENDER_TARGET_POOL_SET_NAME(distortionRT, "Forward.Distortion"); |
| 122 | |
| 123 | // Clear distortion vectors |
| 124 | context->Clear(distortionRT->View(), Color::Transparent); |
| 125 | context->SetViewportAndScissors((float)distortionWidth, (float)distortionHeight); |
| 126 | context->SetRenderTarget(depthBufferHandle, distortionRT->View()); |
| 127 | |
| 128 | // Render distortion pass |
| 129 | view.Pass = DrawPass::Distortion; |
| 130 | mainCache->ExecuteDrawCalls(renderContext, distortionList); |
| 131 |
nothing calls this directly
no test coverage detected