From 4806f901b4a5be00bba601d11c57774aa78b1fe7 Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Thu, 16 Nov 2023 22:24:13 -0800 Subject: [PATCH] wip --- .../src/RenderableEntityItem.cpp | 3 +- libraries/render/src/render/CullTask.cpp | 67 ------------------- libraries/render/src/render/CullTask.h | 23 ------- libraries/shared/src/ViewFrustum.cpp | 5 ++ libraries/shared/src/ViewFrustum.h | 4 +- 5 files changed, 10 insertions(+), 92 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableEntityItem.cpp b/libraries/entities-renderer/src/RenderableEntityItem.cpp index b80b39c08c..d0891d16b1 100644 --- a/libraries/entities-renderer/src/RenderableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableEntityItem.cpp @@ -308,6 +308,7 @@ void EntityRenderer::computeMirrorView(ViewFrustum& viewFrustum) const { projection[3][2] = c.w; viewFrustum.setProjection(projection); + viewFrustum.setIsOblique(true); } void EntityRenderer::render(RenderArgs* args) { @@ -596,7 +597,7 @@ graphics::MaterialPointer EntityRenderer::getTopMaterial() { } EntityRenderer::Pipeline EntityRenderer::getPipelineType(const graphics::MultiMaterial& materials) { - if (_mirrorMode != MirrorMode::NONE) { + if (_mirrorMode == MirrorMode::MIRROR || (_mirrorMode == MirrorMode::PORTAL && !_portalExitID.isNull())) { return Pipeline::MIRROR; } diff --git a/libraries/render/src/render/CullTask.cpp b/libraries/render/src/render/CullTask.cpp index aeb7572746..cd69114bbf 100644 --- a/libraries/render/src/render/CullTask.cpp +++ b/libraries/render/src/render/CullTask.cpp @@ -325,73 +325,6 @@ void CullSpatialSelection::run(const RenderContextPointer& renderContext, std::static_pointer_cast(renderContext->jobConfig)->numItems = (int)outItems.size(); } -void CullShapeBounds::run(const RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { - assert(renderContext->args); - assert(renderContext->args->hasViewFrustum()); - RenderArgs* args = renderContext->args; - - const auto& inShapes = inputs.get0(); - const auto& cullFilter = inputs.get1(); - const auto& boundsFilter = inputs.get2(); - ViewFrustumPointer antiFrustum; - auto& outShapes = outputs.edit0(); - auto& outBounds = outputs.edit1(); - - if (!inputs[3].isNull()) { - antiFrustum = inputs.get3(); - } - outShapes.clear(); - outBounds = AABox(); - - if (!cullFilter.selectsNothing() || !boundsFilter.selectsNothing()) { - auto& details = args->_details.edit(_detailType); - CullTest test(_cullFunctor, args, details, antiFrustum); - auto scene = args->_scene; - - for (auto& inItems : inShapes) { - auto key = inItems.first; - auto outItems = outShapes.find(key); - if (outItems == outShapes.end()) { - outItems = outShapes.insert(std::make_pair(key, ItemBounds{})).first; - outItems->second.reserve(inItems.second.size()); - } - - details._considered += (int)inItems.second.size(); - - if (antiFrustum == nullptr) { - for (auto& item : inItems.second) { - if (test.solidAngleTest(item.bound) && test.frustumTest(item.bound)) { - const auto shapeKey = scene->getItem(item.id).getKey(); - if (cullFilter.test(shapeKey)) { - outItems->second.emplace_back(item); - } - if (boundsFilter.test(shapeKey)) { - outBounds += item.bound; - } - } - } - } else { - for (auto& item : inItems.second) { - if (test.solidAngleTest(item.bound) && test.frustumTest(item.bound) && test.antiFrustumTest(item.bound)) { - const auto shapeKey = scene->getItem(item.id).getKey(); - if (cullFilter.test(shapeKey)) { - outItems->second.emplace_back(item); - } - if (boundsFilter.test(shapeKey)) { - outBounds += item.bound; - } - } - } - } - details._rendered += (int)outItems->second.size(); - } - - for (auto& items : outShapes) { - items.second.shrink_to_fit(); - } - } -} - void ApplyCullFunctorOnItemBounds::run(const RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) { assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); diff --git a/libraries/render/src/render/CullTask.h b/libraries/render/src/render/CullTask.h index 9a7466223d..9e214fd988 100644 --- a/libraries/render/src/render/CullTask.h +++ b/libraries/render/src/render/CullTask.h @@ -121,29 +121,6 @@ namespace render { void run(const RenderContextPointer& renderContext, const Inputs& inputs, ItemBounds& outItems); }; - class CullShapeBounds { - public: - using Inputs = render::VaryingSet4; - using Outputs = render::VaryingSet2; - using JobModel = Job::ModelIO; - - CullShapeBounds(CullFunctor cullFunctor, RenderDetails::Type type) : - _cullFunctor{ cullFunctor }, - _detailType(type) {} - - CullShapeBounds(CullFunctor cullFunctor) : - _cullFunctor{ cullFunctor } { - } - - void run(const RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs); - - private: - - CullFunctor _cullFunctor; - RenderDetails::Type _detailType{ RenderDetails::OTHER }; - - }; - class ApplyCullFunctorOnItemBounds { public: using Inputs = render::VaryingSet2; diff --git a/libraries/shared/src/ViewFrustum.cpp b/libraries/shared/src/ViewFrustum.cpp index e925ef960d..3ed42df59b 100644 --- a/libraries/shared/src/ViewFrustum.cpp +++ b/libraries/shared/src/ViewFrustum.cpp @@ -208,6 +208,11 @@ bool ViewFrustum::sphereIntersectsFrustum(const glm::vec3& center, float radius) } bool ViewFrustum::boxIntersectsFrustum(const AABox& box) const { + // FIXME: remove once we fix culling + if (_isOblique) { + return true; + } + // only check against frustum for(int i = 0; i < NUM_FRUSTUM_PLANES; i++) { const glm::vec3& normal = _planes[i].getNormal(); diff --git a/libraries/shared/src/ViewFrustum.h b/libraries/shared/src/ViewFrustum.h index 9c80538e60..a81c646673 100644 --- a/libraries/shared/src/ViewFrustum.h +++ b/libraries/shared/src/ViewFrustum.h @@ -51,6 +51,7 @@ public: void setProjection(float cameraFov, float cameraAspectRatio, float cameraNearClip, float cameraFarClip); void setFocalLength(float focalLength) { _focalLength = focalLength; } bool isPerspective() const; + void setIsOblique(bool isOblique) { _isOblique = isOblique; } // getters for lens attributes const glm::mat4& getProjection() const { return _projection; } @@ -103,7 +104,6 @@ public: bool pointIntersectsFrustum(const glm::vec3& point) const; bool sphereIntersectsFrustum(const glm::vec3& center, float radius) const; - bool cubeIntersectsFrustum(const AACube& box) const; bool boxIntersectsFrustum(const AABox& box) const; bool boxInsideFrustum(const AABox& box) const; @@ -175,6 +175,8 @@ private: float _nearClip { DEFAULT_NEAR_CLIP }; float _farClip { DEFAULT_FAR_CLIP }; + bool _isOblique { false }; + const char* debugPlaneName (int plane) const; // Used to project points