| 261 | } |
| 262 | |
| 263 | void ReflectionsPass::Render(RenderContext& renderContext, GPUTextureView* lightBuffer) |
| 264 | { |
| 265 | auto device = GPUDevice::Instance; |
| 266 | auto context = device->GetMainContext(); |
| 267 | if (checkIfSkipPass()) |
| 268 | { |
| 269 | // Skip pass (just clear buffer when doing debug preview) |
| 270 | if (renderContext.View.Mode == ViewMode::Reflections) |
| 271 | context->Clear(lightBuffer, Color::Black); |
| 272 | return; |
| 273 | } |
| 274 | |
| 275 | // Cache data |
| 276 | auto& view = renderContext.View; |
| 277 | bool useReflections = EnumHasAnyFlags(view.Flags, ViewFlags::Reflections); |
| 278 | bool useSSR = EnumHasAnyFlags(view.Flags, ViewFlags::SSR) && renderContext.List->Settings.ScreenSpaceReflections.Intensity > ZeroTolerance; |
| 279 | int32 probesCount = renderContext.List->EnvironmentProbes.Count(); |
| 280 | bool renderProbes = probesCount > 0; |
| 281 | auto shader = _shader->GetShader(); |
| 282 | auto cb = shader->GetCB(0); |
| 283 | |
| 284 | // Check if no need to render reflection environment |
| 285 | if (!useReflections || !(renderProbes || useSSR)) |
| 286 | return; |
| 287 | PROFILE_GPU_CPU("Reflections"); |
| 288 | |
| 289 | // Setup data |
| 290 | const int32 width = renderContext.Buffers->GetWidth(); |
| 291 | const int32 height = renderContext.Buffers->GetHeight(); |
| 292 | Data data; |
| 293 | GBufferPass::SetInputs(view, data.GBuffer); |
| 294 | auto& ssrSettings = renderContext.List->Settings.ScreenSpaceReflections; |
| 295 | data.SSRTexelSize = Float2(1.0f / (float)RenderTools::GetResolution(width, ssrSettings.ResolvePassResolution), 1.0f / (float)RenderTools::GetResolution(height, ssrSettings.ResolvePassResolution)); |
| 296 | |
| 297 | // Bind GBuffer inputs |
| 298 | GPUTexture* depthBuffer = renderContext.Buffers->DepthBuffer; |
| 299 | const bool depthBufferReadOnly = EnumHasAnyFlags(depthBuffer->Flags(), GPUTextureFlags::ReadOnlyDepthView); |
| 300 | GPUTextureView* depthBufferRTV = depthBufferReadOnly ? depthBuffer->ViewReadOnlyDepth() : nullptr; |
| 301 | GPUTextureView* depthBufferSRV = depthBufferReadOnly ? depthBuffer->ViewReadOnlyDepth() : depthBuffer->View(); |
| 302 | context->BindSR(0, renderContext.Buffers->GBuffer0); |
| 303 | context->BindSR(1, renderContext.Buffers->GBuffer1); |
| 304 | context->BindSR(2, renderContext.Buffers->GBuffer2); |
| 305 | context->BindSR(3, depthBufferSRV); |
| 306 | |
| 307 | auto tempDesc = GPUTextureDescription::New2D(renderContext.Buffers->GetWidth(), renderContext.Buffers->GetHeight(), PixelFormat::R11G11B10_Float); |
| 308 | auto reflectionsBuffer = RenderTargetPool::Get(tempDesc); |
| 309 | RENDER_TARGET_POOL_SET_NAME(reflectionsBuffer, "Reflections"); |
| 310 | context->Clear(*reflectionsBuffer, Color::Black); |
| 311 | |
| 312 | // Reflection Probes pass |
| 313 | if (!useSSR && renderContext.View.Mode == ViewMode::Reflections) |
| 314 | context->Clear(lightBuffer, Color::Black); |
| 315 | if (renderProbes) |
| 316 | { |
| 317 | PROFILE_GPU_CPU("Env Probes"); |
| 318 | |
| 319 | context->SetRenderTarget(depthBufferRTV, *reflectionsBuffer); |
| 320 |
nothing calls this directly
no test coverage detected