History

cleanup + fixing mirrors

HifiExperiments committed 2 years ago

Commit c4cf2ba1 parent ce7c30412 files · +67 −33Browse files

Showing the changes to libraries/render-utils/src/RenderCommonTask.cpp (1 of 12 files). Show all

Unified · Split

libraries/render-utils/src/RenderCommonTask.cpp+40−12
@@ -52,7 +52,7 @@ void EndGPURangeTimer::run(const render::RenderContextPointer& renderContext, co · 51 unmodified lines
5252 config->setGPUBatchRunTime(timer->getGPUAverage(), timer->getBatchAverage());
5353 }
5454
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) :
5656 _shapePlumber(shapePlumber),
5757 _transformSlot(transformSlot),
5858 _opaquePass(opaque),
@@ -343,7 +343,7 @@ public: · 284 unmodified lines
343343 using Inputs = SetupMirrorTask::Outputs;
344344 using JobModel = render::Job::ModelI<DrawMirrorTask, Inputs>;
345345
346− DrawMirrorTask() {
346+ DrawMirrorTask(uint transformSlot) : _transformSlot(transformSlot) {
347347 static std::once_flag once;
348348 std::call_once(once, [this] {
349349 auto state = std::make_shared<gpu::State>();
@@ -379,13 +379,7 @@ public: · 29 unmodified lines
379379 batch.setViewportTransform(args->_viewport);
380380 batch.setStateScissorRect(args->_viewport);
381381
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);
389383
390384 batch.setResourceTexture(gr::Texture::MaterialMirror, args->_blitFramebuffer->getRenderBuffer(0));
391385
@@ -406,20 +400,54 @@ public: · 14 unmodified lines
406400 private:
407401 static ShapePlumberPointer _forwardPipelines;
408402 static ShapePlumberPointer _deferredPipelines;
403+
404+ uint _transformSlot;
409405 };
410406
411407 ShapePlumberPointer DrawMirrorTask::_forwardPipelines = std::make_shared<ShapePlumber>();
412408 ShapePlumberPointer DrawMirrorTask::_deferredPipelines = std::make_shared<ShapePlumber>();
413409
414410 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) {
416412 size_t nextDepth = depth + 1;
417413 const auto setupOutput = task.addJob<SetupMirrorTask>("SetupMirror" + std::to_string(mirrorIndex) + "Depth" + std::to_string(depth), inputs, mirrorIndex, nextDepth);
418414
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+
419446 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);
421448
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);
423451 }
424452
425453 void RenderSimulateTask::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) {