| 358 | } |
| 359 | |
| 360 | void RenderList::RunPostFxPass(GPUContext* context, RenderContext& renderContext, MaterialPostFxLocation locationA, PostProcessEffectLocation locationB, GPUTexture*& inputOutput) |
| 361 | { |
| 362 | // Note: during this stage engine is using additive rendering to the light buffer (given as inputOutput parameter). |
| 363 | // Materials PostFx and Custom PostFx prefer sampling the input texture while rendering to the output. |
| 364 | // So we need to allocate a temporary render target (or reuse from cache) and use it as a ping pong buffer. |
| 365 | |
| 366 | bool skipPass = true; |
| 367 | bool needTempTarget = true; |
| 368 | for (int32 i = 0; i < Settings.PostFxMaterials.Materials.Count(); i++) |
| 369 | { |
| 370 | const auto material = Settings.PostFxMaterials.Materials[i].Get(); |
| 371 | if (material && material->IsReady() && material->IsPostFx() && material->GetInfo().PostFxLocation == locationA) |
| 372 | { |
| 373 | skipPass = false; |
| 374 | needTempTarget = true; |
| 375 | } |
| 376 | } |
| 377 | if (EnumHasAnyFlags(renderContext.View.Flags, ViewFlags::CustomPostProcess)) |
| 378 | { |
| 379 | for (const PostProcessEffect* fx : renderContext.List->PostFx) |
| 380 | { |
| 381 | if (fx->Location == locationB) |
| 382 | { |
| 383 | skipPass = false; |
| 384 | needTempTarget |= !fx->UseSingleTarget; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | if (skipPass) |
| 389 | return; |
| 390 | |
| 391 | auto tempDesc = inputOutput->GetDescription(); |
| 392 | auto temp = needTempTarget ? RenderTargetPool::Get(tempDesc) : nullptr; |
| 393 | if (needTempTarget) |
| 394 | { |
| 395 | RENDER_TARGET_POOL_SET_NAME(temp, "RenderList.RunPostFxPassTemp"); |
| 396 | } |
| 397 | |
| 398 | auto input = inputOutput; |
| 399 | auto output = temp; |
| 400 | |
| 401 | context->ResetRenderTarget(); |
| 402 | |
| 403 | MaterialBase::BindParameters bindParams(context, renderContext); |
| 404 | for (int32 i = 0; i < Settings.PostFxMaterials.Materials.Count(); i++) |
| 405 | { |
| 406 | auto material = Settings.PostFxMaterials.Materials[i].Get(); |
| 407 | if (material && material->IsReady() && material->IsPostFx() && material->GetInfo().PostFxLocation == locationA) |
| 408 | { |
| 409 | context->ResetSR(); |
| 410 | ASSERT(needTempTarget); |
| 411 | context->SetRenderTarget(*output); |
| 412 | bindParams.Input = *input; |
| 413 | material->Bind(bindParams); |
| 414 | context->DrawFullscreenTriangle(); |
| 415 | context->ResetRenderTarget(); |
| 416 | Swap(output, input); |
| 417 | } |
no test coverage detected