Showing the changes to libraries/render-utils/src/RenderDeferredTask.cpp (1 of 1213 files). Show all
Unified · Split
| @@ -12,6 +12,8 @@ · 11 unmodified lines | |||
| 12 | 12 | ||
| 13 | #include "RenderDeferredTask.h" | 13 | #include "RenderDeferredTask.h" |
| 14 | 14 | ||
| 15 | #include <DependencyManager.h> | ||
| 16 | |||
| 15 | #include <PerfStat.h> | 17 | #include <PerfStat.h> |
| 16 | #include <PathUtils.h> | 18 | #include <PathUtils.h> |
| 17 | #include <ViewFrustum.h> | 19 | #include <ViewFrustum.h> |
| @@ -25,6 +27,7 @@ · 7 unmodified lines | |||
| 25 | #include <render/DrawSceneOctree.h> | 27 | #include <render/DrawSceneOctree.h> |
| 26 | #include <render/BlurTask.h> | 28 | #include <render/BlurTask.h> |
| 27 | 29 | ||
| 30 | #include "RenderCommonTask.h" | ||
| 28 | #include "LightingModel.h" | 31 | #include "LightingModel.h" |
| 29 | #include "StencilMaskPass.h" | 32 | #include "StencilMaskPass.h" |
| 30 | #include "DebugDeferredBuffer.h" | 33 | #include "DebugDeferredBuffer.h" |
| @@ -172,8 +175,11 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren · 141 unmodified lines | |||
| 172 | // Similar to light stage, background stage has been filled by several potential render items and resolved for the frame in this job | 175 | // Similar to light stage, background stage has been filled by several potential render items and resolved for the frame in this job |
| 173 | task.addJob<DrawBackgroundStage>("DrawBackgroundDeferred", lightingModel); | 176 | task.addJob<DrawBackgroundStage>("DrawBackgroundDeferred", lightingModel); |
| 174 | 177 | ||
| 178 | const auto drawHazeInputs = render::Varying(DrawHaze::Inputs(hazeModel, lightingFramebuffer, linearDepthTarget, deferredFrameTransform, lightingFramebuffer)); | ||
| 179 | task.addJob<DrawHaze>("DrawHazeDeferred", drawHazeInputs); | ||
| 180 | |||
| 175 | // Render transparent objects forward in LightingBuffer | 181 | // Render transparent objects forward in LightingBuffer |
| 176 | const auto transparentsInputs = DrawDeferred::Inputs(transparents, lightingModel).asVarying(); | 182 | const auto transparentsInputs = DrawDeferred::Inputs(transparents, lightingModel, lightClusters).asVarying(); |
| 177 | task.addJob<DrawDeferred>("DrawTransparentDeferred", transparentsInputs, shapePlumber); | 183 | task.addJob<DrawDeferred>("DrawTransparentDeferred", transparentsInputs, shapePlumber); |
| 178 | 184 | ||
| 179 | // Light Cluster Grid Debuging job | 185 | // Light Cluster Grid Debuging job |
| @@ -182,9 +188,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren · 2 unmodified lines | |||
| 182 | task.addJob<DebugLightClusters>("DebugLightClusters", debugLightClustersInputs); | 188 | task.addJob<DebugLightClusters>("DebugLightClusters", debugLightClustersInputs); |
| 183 | } | 189 | } |
| 184 | 190 | ||
| 185 | const auto drawHazeInputs = render::Varying(DrawHaze::Inputs(hazeModel, lightingFramebuffer, linearDepthTarget, deferredFrameTransform, lightingFramebuffer)); | ||
| 186 | task.addJob<DrawHaze>("DrawHaze", drawHazeInputs); | ||
| 187 | |||
| 188 | const auto toneAndPostRangeTimer = task.addJob<BeginGPURangeTimer>("BeginToneAndPostRangeTimer", "PostToneOverlaysAntialiasing"); | 191 | const auto toneAndPostRangeTimer = task.addJob<BeginGPURangeTimer>("BeginToneAndPostRangeTimer", "PostToneOverlaysAntialiasing"); |
| 189 | 192 | ||
| 190 | // Add bloom | 193 | // Add bloom |
| @@ -214,9 +217,14 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren · 23 unmodified lines | |||
| 214 | task.addJob<DrawBounds>("DrawZones", zones); | 217 | task.addJob<DrawBounds>("DrawZones", zones); |
| 215 | const auto frustums = task.addJob<ExtractFrustums>("ExtractFrustums"); | 218 | const auto frustums = task.addJob<ExtractFrustums>("ExtractFrustums"); |
| 216 | const auto viewFrustum = frustums.getN<ExtractFrustums::Output>(ExtractFrustums::VIEW_FRUSTUM); | 219 | const auto viewFrustum = frustums.getN<ExtractFrustums::Output>(ExtractFrustums::VIEW_FRUSTUM); |
| 217 | const auto shadowFrustum = frustums.getN<ExtractFrustums::Output>(ExtractFrustums::SHADOW_FRUSTUM); | ||
| 218 | task.addJob<DrawFrustum>("DrawViewFrustum", viewFrustum, glm::vec3(1.0f, 1.0f, 0.0f)); | 220 | task.addJob<DrawFrustum>("DrawViewFrustum", viewFrustum, glm::vec3(1.0f, 1.0f, 0.0f)); |
| 219 | task.addJob<DrawFrustum>("DrawShadowFrustum", shadowFrustum, glm::vec3(0.0f, 0.0f, 1.0f)); | 221 | for (auto i = 0; i < ExtractFrustums::SHADOW_CASCADE_FRUSTUM_COUNT; i++) { |
| 222 | const auto shadowFrustum = frustums.getN<ExtractFrustums::Output>(ExtractFrustums::SHADOW_CASCADE0_FRUSTUM+i); | ||
| 223 | float tint = 1.0f - i / float(ExtractFrustums::SHADOW_CASCADE_FRUSTUM_COUNT - 1); | ||
| 224 | char jobName[64]; | ||
| 225 | sprintf(jobName, "DrawShadowFrustum%d", i); | ||
| 226 | task.addJob<DrawFrustum>(jobName, shadowFrustum, glm::vec3(0.0f, tint, 1.0f)); | ||
| 227 | } | ||
| 220 | 228 | ||
| 221 | // Render.getConfig("RenderMainView.DrawSelectionBounds").enabled = true | 229 | // Render.getConfig("RenderMainView.DrawSelectionBounds").enabled = true |
| 222 | task.addJob<DrawBounds>("DrawSelectionBounds", selectedItems); | 230 | task.addJob<DrawBounds>("DrawSelectionBounds", selectedItems); |
| @@ -245,7 +253,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren · 22 unmodified lines | |||
| 245 | // Debugging stages | 253 | // Debugging stages |
| 246 | { | 254 | { |
| 247 | // Debugging Deferred buffer job | 255 | // Debugging Deferred buffer job |
| 248 | const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer)); | 256 | const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(deferredFramebuffer, linearDepthTarget, surfaceGeometryFramebuffer, ambientOcclusionFramebuffer, velocityBuffer, deferredFrameTransform)); |
| 249 | task.addJob<DebugDeferredBuffer>("DebugDeferredBuffer", debugFramebuffers); | 257 | task.addJob<DebugDeferredBuffer>("DebugDeferredBuffer", debugFramebuffers); |
| 250 | 258 | ||
| 251 | const auto debugSubsurfaceScatteringInputs = DebugSubsurfaceScattering::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, | 259 | const auto debugSubsurfaceScatteringInputs = DebugSubsurfaceScattering::Inputs(deferredFrameTransform, deferredFramebuffer, lightingModel, |
| @@ -294,23 +302,6 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren · 42 unmodified lines | |||
| 294 | task.addJob<Blit>("Blit", primaryFramebuffer); | 302 | task.addJob<Blit>("Blit", primaryFramebuffer); |
| 295 | } | 303 | } |
| 296 | 304 | ||
| 297 | void BeginGPURangeTimer::run(const render::RenderContextPointer& renderContext, gpu::RangeTimerPointer& timer) { | ||
| 298 | timer = _gpuTimer; | ||
| 299 | gpu::doInBatch("BeginGPURangeTimer::run", renderContext->args->_context, [&](gpu::Batch& batch) { | ||
| 300 | _gpuTimer->begin(batch); | ||
| 301 | }); | ||
| 302 | } | ||
| 303 | |||
| 304 | void EndGPURangeTimer::run(const render::RenderContextPointer& renderContext, const gpu::RangeTimerPointer& timer) { | ||
| 305 | gpu::doInBatch("EndGPURangeTimer::run", renderContext->args->_context, [&](gpu::Batch& batch) { | ||
| 306 | timer->end(batch); | ||
| 307 | }); | ||
| 308 | |||
| 309 | auto config = std::static_pointer_cast<Config>(renderContext->jobConfig); | ||
| 310 | config->setGPUBatchRunTime(timer->getGPUAverage(), timer->getBatchAverage()); | ||
| 311 | } | ||
| 312 | |||
| 313 | |||
| 314 | void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& inputs) { | 305 | void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& inputs) { |
| 315 | assert(renderContext->args); | 306 | assert(renderContext->args); |
| 316 | assert(renderContext->args->hasViewFrustum()); | 307 | assert(renderContext->args->hasViewFrustum()); |
| @@ -319,6 +310,8 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& · 2 unmodified lines | |||
| 319 | 310 | ||
| 320 | const auto& inItems = inputs.get0(); | 311 | const auto& inItems = inputs.get0(); |
| 321 | const auto& lightingModel = inputs.get1(); | 312 | const auto& lightingModel = inputs.get1(); |
| 313 | const auto& lightClusters = inputs.get2(); | ||
| 314 | auto deferredLightingEffect = DependencyManager::get<DeferredLightingEffect>(); | ||
| 322 | 315 | ||
| 323 | RenderArgs* args = renderContext->args; | 316 | RenderArgs* args = renderContext->args; |
| 324 | 317 | ||
| @@ -340,6 +333,21 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& · 15 unmodified lines | |||
| 340 | // Setup lighting model for all items; | 333 | // Setup lighting model for all items; |
| 341 | batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer()); | 334 | batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer()); |
| 342 | 335 | ||
| 336 | deferredLightingEffect->setupLocalLightsBatch(batch, | ||
| 337 | render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, | ||
| 338 | render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT, | ||
| 339 | render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT, | ||
| 340 | lightClusters); | ||
| 341 | |||
| 342 | // Setup haze if current zone has haze | ||
| 343 | auto hazeStage = args->_scene->getStage<HazeStage>(); | ||
| 344 | if (hazeStage && hazeStage->_currentFrame._hazes.size() > 0) { | ||
| 345 | graphics::HazePointer hazePointer = hazeStage->getHaze(hazeStage->_currentFrame._hazes.front()); | ||
| 346 | if (hazePointer) { | ||
| 347 | batch.setUniformBuffer(render::ShapePipeline::Slot::HAZE_MODEL, hazePointer->getHazeParametersBuffer()); | ||
| 348 | } | ||
| 349 | } | ||
| 350 | |||
| 343 | // From the lighting model define a global shapKey ORED with individiual keys | 351 | // From the lighting model define a global shapKey ORED with individiual keys |
| 344 | ShapeKey::Builder keyBuilder; | 352 | ShapeKey::Builder keyBuilder; |
| 345 | if (lightingModel->isWireframeEnabled()) { | 353 | if (lightingModel->isWireframeEnabled()) { |
| @@ -353,6 +361,11 @@ void DrawDeferred::run(const RenderContextPointer& renderContext, const Inputs& · 7 unmodified lines | |||
| 353 | 361 | ||
| 354 | args->_batch = nullptr; | 362 | args->_batch = nullptr; |
| 355 | args->_globalShapeKey = 0; | 363 | args->_globalShapeKey = 0; |
| 364 | |||
| 365 | deferredLightingEffect->unsetLocalLightsBatch(batch, | ||
| 366 | render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_GRID_SLOT, | ||
| 367 | render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_CLUSTER_CONTENT_SLOT, | ||
| 368 | render::ShapePipeline::Slot::LIGHT_CLUSTER_GRID_FRUSTUM_GRID_SLOT); | ||
| 356 | }); | 369 | }); |
| 357 | 370 | ||
| 358 | config->setNumDrawn((int)inItems.size()); | 371 | config->setNumDrawn((int)inItems.size()); |
| @@ -408,174 +421,3 @@ void DrawStateSortDeferred::run(const RenderContextPointer& renderContext, const · 49 unmodified lines | |||
| 408 | config->setNumDrawn((int)inItems.size()); | 421 | config->setNumDrawn((int)inItems.size()); |
| 409 | } | 422 | } |
| 410 | 423 | ||
| 411 | DrawOverlay3D::DrawOverlay3D(bool opaque) : | ||
| 412 | _shapePlumber(std::make_shared<ShapePlumber>()), | ||
| 413 | _opaquePass(opaque) { | ||
| 414 | initOverlay3DPipelines(*_shapePlumber); | ||
| 415 | } | ||
| 416 | |||
| 417 | void DrawOverlay3D::run(const RenderContextPointer& renderContext, const Inputs& inputs) { | ||
| 418 | assert(renderContext->args); | ||
| 419 | assert(renderContext->args->hasViewFrustum()); | ||
| 420 | |||
| 421 | auto config = std::static_pointer_cast<Config>(renderContext->jobConfig); | ||
| 422 | |||
| 423 | const auto& inItems = inputs.get0(); | ||
| 424 | const auto& lightingModel = inputs.get1(); | ||
| 425 | |||
| 426 | config->setNumDrawn((int)inItems.size()); | ||
| 427 | emit config->numDrawnChanged(); | ||
| 428 | |||
| 429 | if (!inItems.empty()) { | ||
| 430 | RenderArgs* args = renderContext->args; | ||
| 431 | |||
| 432 | // Clear the framebuffer without stereo | ||
| 433 | // Needs to be distinct from the other batch because using the clear call | ||
| 434 | // while stereo is enabled triggers a warning | ||
| 435 | if (_opaquePass) { | ||
| 436 | gpu::doInBatch("DrawOverlay3D::run::clear", args->_context, [&](gpu::Batch& batch){ | ||
| 437 | batch.enableStereo(false); | ||
| 438 | batch.clearFramebuffer(gpu::Framebuffer::BUFFER_DEPTH, glm::vec4(), 1.f, 0, false); | ||
| 439 | }); | ||
| 440 | } | ||
| 441 | |||
| 442 | // Render the items | ||
| 443 | gpu::doInBatch("DrawOverlay3D::run", args->_context, [&](gpu::Batch& batch) { | ||
| 444 | args->_batch = &batch; | ||
| 445 | batch.setViewportTransform(args->_viewport); | ||
| 446 | batch.setStateScissorRect(args->_viewport); | ||
| 447 | |||
| 448 | glm::mat4 projMat; | ||
| 449 | Transform viewMat; | ||
| 450 | args->getViewFrustum().evalProjectionMatrix(projMat); | ||
| 451 | args->getViewFrustum().evalViewTransform(viewMat); | ||
| 452 | |||
| 453 | batch.setProjectionTransform(projMat); | ||
| 454 | batch.setViewTransform(viewMat); | ||
| 455 | |||
| 456 | // Setup lighting model for all items; | ||
| 457 | batch.setUniformBuffer(render::ShapePipeline::Slot::LIGHTING_MODEL, lightingModel->getParametersBuffer()); | ||
| 458 | |||
| 459 | renderShapes(renderContext, _shapePlumber, inItems, _maxDrawn); | ||
| 460 | args->_batch = nullptr; | ||
| 461 | }); | ||
| 462 | } | ||
| 463 | } | ||
| 464 | |||
| 465 | void CompositeHUD::run(const RenderContextPointer& renderContext) { | ||
| 466 | assert(renderContext->args); | ||
| 467 | assert(renderContext->args->_context); | ||
| 468 | |||
| 469 | // We do not want to render HUD elements in secondary camera | ||
| 470 | if (renderContext->args->_renderMode == RenderArgs::RenderMode::SECONDARY_CAMERA_RENDER_MODE) { | ||
| 471 | return; | ||
| 472 | } | ||
| 473 | |||
| 474 | // Grab the HUD texture | ||
| 475 | gpu::doInBatch("CompositeHUD::run", renderContext->args->_context, [&](gpu::Batch& batch) { | ||
| 476 | if (renderContext->args->_hudOperator) { | ||
| 477 | renderContext->args->_hudOperator(batch, renderContext->args->_hudTexture, renderContext->args->_renderMode == RenderArgs::RenderMode::MIRROR_RENDER_MODE); | ||
| 478 | } | ||
| 479 | }); | ||
| 480 | } | ||
| 481 | |||
| 482 | void Blit::run(const RenderContextPointer& renderContext, const gpu::FramebufferPointer& srcFramebuffer) { | ||
| 483 | assert(renderContext->args); | ||
| 484 | assert(renderContext->args->_context); | ||
| 485 | |||
| 486 | RenderArgs* renderArgs = renderContext->args; | ||
| 487 | auto blitFbo = renderArgs->_blitFramebuffer; | ||
| 488 | |||
| 489 | if (!blitFbo) { | ||
| 490 | qCWarning(renderutils) << "Blit::run - no blit frame buffer."; | ||
| 491 | return; | ||
| 492 | } | ||
| 493 | |||
| 494 | // Determine size from viewport | ||
| 495 | int width = renderArgs->_viewport.z; | ||
| 496 | int height = renderArgs->_viewport.w; | ||
| 497 | |||
| 498 | // Blit primary to blit FBO | ||
| 499 | auto primaryFbo = srcFramebuffer; | ||
| 500 | |||
| 501 | gpu::doInBatch("Blit::run", renderArgs->_context, [&](gpu::Batch& batch) { | ||
| 502 | batch.setFramebuffer(blitFbo); | ||
| 503 | |||
| 504 | if (renderArgs->_renderMode == RenderArgs::MIRROR_RENDER_MODE) { | ||
| 505 | if (renderArgs->isStereo()) { | ||
| 506 | gpu::Vec4i srcRectLeft; | ||
| 507 | srcRectLeft.z = width / 2; | ||
| 508 | srcRectLeft.w = height; | ||
| 509 | |||
| 510 | gpu::Vec4i srcRectRight; | ||
| 511 | srcRectRight.x = width / 2; | ||
| 512 | srcRectRight.z = width; | ||
| 513 | srcRectRight.w = height; | ||
| 514 | |||
| 515 | gpu::Vec4i destRectLeft; | ||
| 516 | destRectLeft.x = srcRectLeft.z; | ||
| 517 | destRectLeft.z = srcRectLeft.x; | ||
| 518 | destRectLeft.y = srcRectLeft.y; | ||
| 519 | destRectLeft.w = srcRectLeft.w; | ||
| 520 | |||
| 521 | gpu::Vec4i destRectRight; | ||
| 522 | destRectRight.x = srcRectRight.z; | ||
| 523 | destRectRight.z = srcRectRight.x; | ||
| 524 | destRectRight.y = srcRectRight.y; | ||
| 525 | destRectRight.w = srcRectRight.w; | ||
| 526 | |||
| 527 | // Blit left to right and right to left in stereo | ||
| 528 | batch.blit(primaryFbo, srcRectRight, blitFbo, destRectLeft); | ||
| 529 | batch.blit(primaryFbo, srcRectLeft, blitFbo, destRectRight); | ||
| 530 | } else { | ||
| 531 | gpu::Vec4i srcRect; | ||
| 532 | srcRect.z = width; | ||
| 533 | srcRect.w = height; | ||
| 534 | |||
| 535 | gpu::Vec4i destRect; | ||
| 536 | destRect.x = width; | ||
| 537 | destRect.y = 0; | ||
| 538 | destRect.z = 0; | ||
| 539 | destRect.w = height; | ||
| 540 | |||
| 541 | batch.blit(primaryFbo, srcRect, blitFbo, destRect); | ||
| 542 | } | ||
| 543 | } else { | ||
| 544 | gpu::Vec4i rect; | ||
| 545 | rect.z = width; | ||
| 546 | rect.w = height; | ||
| 547 | |||
| 548 | batch.blit(primaryFbo, rect, blitFbo, rect); | ||
| 549 | } | ||
| 550 | }); | ||
| 551 | } | ||
| 552 | |||
| 553 | void ExtractFrustums::run(const render::RenderContextPointer& renderContext, Output& output) { | ||
| 554 | assert(renderContext->args); | ||
| 555 | assert(renderContext->args->_context); | ||
| 556 | |||
| 557 | RenderArgs* args = renderContext->args; | ||
| 558 | |||
| 559 | // Return view frustum | ||
| 560 | auto& viewFrustum = output[VIEW_FRUSTUM].edit<ViewFrustumPointer>(); | ||
| 561 | if (!viewFrustum) { | ||
| 562 | viewFrustum = std::make_shared<ViewFrustum>(args->getViewFrustum()); | ||
| 563 | } else { | ||
| 564 | *viewFrustum = args->getViewFrustum(); | ||
| 565 | } | ||
| 566 | |||
| 567 | // Return shadow frustum | ||
| 568 | auto& shadowFrustum = output[SHADOW_FRUSTUM].edit<ViewFrustumPointer>(); | ||
| 569 | auto lightStage = args->_scene->getStage<LightStage>(LightStage::getName()); | ||
| 570 | if (lightStage) { | ||
| 571 | auto globalShadow = lightStage->getCurrentKeyShadow(); | ||
| 572 | |||
| 573 | if (globalShadow) { | ||
| 574 | shadowFrustum = globalShadow->getFrustum(); | ||
| 575 | } else { | ||
| 576 | shadowFrustum.reset(); | ||
| 577 | } | ||
| 578 | } else { | ||
| 579 | shadowFrustum.reset(); | ||
| 580 | } | ||
| 581 | } | ||