Showing the changes to libraries/render-utils/src/RenderCommonTask.cpp (1 of 12 files). Show all
Unified · Split
| @@ -52,7 +52,7 @@ void EndGPURangeTimer::run(const render::RenderContextPointer& renderContext, co · 51 unmodified lines | ||
| 52 | 52 | config->setGPUBatchRunTime(timer->getGPUAverage(), timer->getBatchAverage()); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | −DrawLayered3D::DrawLayered3D(const render::ShapePlumberPointer& shapePlumber, bool opaque, bool jitter, unsigned int transformSlot) : | |
| 55 | +DrawLayered3D::DrawLayered3D(const render::ShapePlumberPointer& shapePlumber, bool opaque, bool jitter, uint transformSlot) : | |
| 56 | 56 | _shapePlumber(shapePlumber), |
| 57 | 57 | _transformSlot(transformSlot), |
| 58 | 58 | _opaquePass(opaque), |
| @@ -343,7 +343,7 @@ public: · 284 unmodified lines | ||
| 343 | 343 | using Inputs = SetupMirrorTask::Outputs; |
| 344 | 344 | using JobModel = render::Job::ModelI<DrawMirrorTask, Inputs>; |
| 345 | 345 | |
| 346 | − DrawMirrorTask() { | |
| 346 | + DrawMirrorTask(uint transformSlot) : _transformSlot(transformSlot) { | |
| 347 | 347 | static std::once_flag once; |
| 348 | 348 | std::call_once(once, [this] { |
| 349 | 349 | auto state = std::make_shared<gpu::State>(); |
| @@ -379,13 +379,7 @@ public: · 29 unmodified lines | ||
| 379 | 379 | batch.setViewportTransform(args->_viewport); |
| 380 | 380 | batch.setStateScissorRect(args->_viewport); |
| 381 | 381 | |
| 382 | − glm::mat4 projMat; | |
| 383 | − Transform viewMat; | |
| 384 | − args->getViewFrustum().evalProjectionMatrix(projMat); | |
| 385 | − args->getViewFrustum().evalViewTransform(viewMat); | |
| 386 | − | |
| 387 | − batch.setProjectionTransform(projMat); | |
| 388 | − batch.setViewTransform(viewMat); | |
| 382 | + batch.setSavedViewProjectionTransform(_transformSlot); | |
| 389 | 383 | |
| 390 | 384 | batch.setResourceTexture(gr::Texture::MaterialMirror, args->_blitFramebuffer->getRenderBuffer(0)); |
| 391 | 385 | |
| @@ -406,20 +400,54 @@ public: · 14 unmodified lines | ||
| 406 | 400 | private: |
| 407 | 401 | static ShapePlumberPointer _forwardPipelines; |
| 408 | 402 | static ShapePlumberPointer _deferredPipelines; |
| 403 | + | |
| 404 | + uint _transformSlot; | |
| 409 | 405 | }; |
| 410 | 406 | |
| 411 | 407 | ShapePlumberPointer DrawMirrorTask::_forwardPipelines = std::make_shared<ShapePlumber>(); |
| 412 | 408 | ShapePlumberPointer DrawMirrorTask::_deferredPipelines = std::make_shared<ShapePlumber>(); |
| 413 | 409 | |
| 414 | 410 | void RenderMirrorTask::build(JobModel& task, const render::Varying& inputs, render::Varying& output, size_t mirrorIndex, render::CullFunctor cullFunctor, |
| 415 | − uint8_t transformOffset, size_t depth) { | |
| 411 | + uint transformOffset,size_t depth) { | |
| 416 | 412 | size_t nextDepth = depth + 1; |
| 417 | 413 | const auto setupOutput = task.addJob<SetupMirrorTask>("SetupMirror" + std::to_string(mirrorIndex) + "Depth" + std::to_string(depth), inputs, mirrorIndex, nextDepth); |
| 418 | 414 | |
| 415 | + // Our primary view starts at transformOffset 0, and the secondary camera starts at transformOffset 2 | |
| 416 | + // Our primary mirror views thus start after the secondary camera, at transformOffset 4, and the secondary | |
| 417 | + // camera mirror views start after all of the primary camera mirror views, at 4 + NUM_MAIN_MIRROR_SLOTS | |
| 418 | + static uint NUM_MAIN_MIRROR_SLOTS = 0; | |
| 419 | + static std::once_flag once; | |
| 420 | + std::call_once(once, [] { | |
| 421 | + for (size_t mirrorDepth = 0; mirrorDepth < MAX_MIRROR_DEPTH; mirrorDepth++) { | |
| 422 | + NUM_MAIN_MIRROR_SLOTS += pow(MAX_MIRRORS_PER_LEVEL, mirrorDepth + 1); | |
| 423 | + } | |
| 424 | + NUM_MAIN_MIRROR_SLOTS *= 2; | |
| 425 | + }); | |
| 426 | + | |
| 427 | + uint mirrorOffset; | |
| 428 | + if (transformOffset == RenderViewTask::TransformOffset::MAIN_VIEW) { | |
| 429 | + mirrorOffset = RenderViewTask::TransformOffset::FIRST_MIRROR_VIEW - 2; | |
| 430 | + } else if (transformOffset == RenderViewTask::TransformOffset::SECONDARY_VIEW) { | |
| 431 | + mirrorOffset = RenderViewTask::TransformOffset::FIRST_MIRROR_VIEW + NUM_MAIN_MIRROR_SLOTS - 2; | |
| 432 | + } else { | |
| 433 | + mirrorOffset = transformOffset; | |
| 434 | + } | |
| 435 | + | |
| 436 | + // To calculate our transformSlot, we take the transformSlot of our parent and add numSubSlots (the number of slots | |
| 437 | + // taken up by a sub-tree starting at this depth) per preceding mirrorIndex | |
| 438 | + uint numSubSlots = 0; | |
| 439 | + for (size_t mirrorDepth = depth; mirrorDepth < MAX_MIRROR_DEPTH; mirrorDepth++) { | |
| 440 | + numSubSlots += pow(MAX_MIRRORS_PER_LEVEL, mirrorDepth + 1 - nextDepth); | |
| 441 | + } | |
| 442 | + numSubSlots *= 2; | |
| 443 | + | |
| 444 | + mirrorOffset += 2 + numSubSlots * (uint)mirrorIndex; | |
| 445 | + | |
| 419 | 446 | task.addJob<RenderViewTask>("RenderMirrorView" + std::to_string(mirrorIndex) + "Depth" + std::to_string(depth), cullFunctor, render::ItemKey::TAG_BITS_1, |
| 420 | − render::ItemKey::TAG_BITS_1, (RenderViewTask::TransformOffset) transformOffset, nextDepth); | |
| 447 | + render::ItemKey::TAG_BITS_1, (RenderViewTask::TransformOffset) mirrorOffset, nextDepth); | |
| 421 | 448 | |
| 422 | − task.addJob<DrawMirrorTask>("DrawMirrorTask" + std::to_string(mirrorIndex) + "Depth" + std::to_string(depth), setupOutput); | |
| 449 | + task.addJob<DrawMirrorTask>("DrawMirrorTask" + std::to_string(mirrorIndex) + "Depth" + std::to_string(depth), setupOutput, | |
| 450 | + render::RenderEngine::TS_MAIN_VIEW + transformOffset); | |
| 423 | 451 | } |
| 424 | 452 | |
| 425 | 453 | void RenderSimulateTask::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) { |