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
52 config->setGPUBatchRunTime(timer->getGPUAverage(), timer->getBatchAverage());52 config->setGPUBatchRunTime(timer->getGPUAverage(), timer->getBatchAverage());
53}53}
54 54
55DrawLayered3D::DrawLayered3D(const render::ShapePlumberPointer& shapePlumber, bool opaque, bool jitter, unsigned int transformSlot) :55DrawLayered3D::DrawLayered3D(const render::ShapePlumberPointer& shapePlumber, bool opaque, bool jitter, uint transformSlot) :
56 _shapePlumber(shapePlumber),56 _shapePlumber(shapePlumber),
57 _transformSlot(transformSlot),57 _transformSlot(transformSlot),
58 _opaquePass(opaque),58 _opaquePass(opaque),
@@ -343,7 +343,7 @@ public: · 284 unmodified lines
343 using Inputs = SetupMirrorTask::Outputs;343 using Inputs = SetupMirrorTask::Outputs;
344 using JobModel = render::Job::ModelI<DrawMirrorTask, Inputs>;344 using JobModel = render::Job::ModelI<DrawMirrorTask, Inputs>;
345 345
346 DrawMirrorTask() {346 DrawMirrorTask(uint transformSlot) : _transformSlot(transformSlot) {
347 static std::once_flag once;347 static std::once_flag once;
348 std::call_once(once, [this] {348 std::call_once(once, [this] {
349 auto state = std::make_shared<gpu::State>();349 auto state = std::make_shared<gpu::State>();
@@ -379,13 +379,7 @@ public: · 29 unmodified lines
379 batch.setViewportTransform(args->_viewport);379 batch.setViewportTransform(args->_viewport);
380 batch.setStateScissorRect(args->_viewport);380 batch.setStateScissorRect(args->_viewport);
381 381
382 glm::mat4 projMat;382 batch.setSavedViewProjectionTransform(_transformSlot);
383 Transform viewMat;
384 args->getViewFrustum().evalProjectionMatrix(projMat);
385 args->getViewFrustum().evalViewTransform(viewMat);
386
387 batch.setProjectionTransform(projMat);
388 batch.setViewTransform(viewMat);
389 383
390 batch.setResourceTexture(gr::Texture::MaterialMirror, args->_blitFramebuffer->getRenderBuffer(0));384 batch.setResourceTexture(gr::Texture::MaterialMirror, args->_blitFramebuffer->getRenderBuffer(0));
391 385
@@ -406,20 +400,54 @@ public: · 14 unmodified lines
406private:400private:
407 static ShapePlumberPointer _forwardPipelines;401 static ShapePlumberPointer _forwardPipelines;
408 static ShapePlumberPointer _deferredPipelines;402 static ShapePlumberPointer _deferredPipelines;
403
404 uint _transformSlot;
409};405};
410 406
411ShapePlumberPointer DrawMirrorTask::_forwardPipelines = std::make_shared<ShapePlumber>();407ShapePlumberPointer DrawMirrorTask::_forwardPipelines = std::make_shared<ShapePlumber>();
412ShapePlumberPointer DrawMirrorTask::_deferredPipelines = std::make_shared<ShapePlumber>();408ShapePlumberPointer DrawMirrorTask::_deferredPipelines = std::make_shared<ShapePlumber>();
413 409
414void RenderMirrorTask::build(JobModel& task, const render::Varying& inputs, render::Varying& output, size_t mirrorIndex, render::CullFunctor cullFunctor,410void 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 size_t nextDepth = depth + 1;412 size_t nextDepth = depth + 1;
417 const auto setupOutput = task.addJob<SetupMirrorTask>("SetupMirror" + std::to_string(mirrorIndex) + "Depth" + std::to_string(depth), inputs, mirrorIndex, nextDepth);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 task.addJob<RenderViewTask>("RenderMirrorView" + std::to_string(mirrorIndex) + "Depth" + std::to_string(depth), cullFunctor, render::ItemKey::TAG_BITS_1,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
425void RenderSimulateTask::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) {453void RenderSimulateTask::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) {