From c012a581a6b5f8238254ba6a28518ed53f8c3e36 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 2 Jun 2015 19:26:39 +0200 Subject: [PATCH] Set shouldRender method --- interface/src/Application.cpp | 1 + interface/src/LODManager.cpp | 41 +++++++++++++++++++++++++++++++++++ interface/src/LODManager.h | 3 +++ 3 files changed, 45 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e436c25d09..83da9c1854 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3434,6 +3434,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se { PerformanceTimer perfTimer("EngineRun"); render::RenderContext renderContext; + renderArgs->_shouldRender = LODManager::shouldRender; renderContext.args = renderArgs; _renderEngine->setRenderContext(renderContext); diff --git a/interface/src/LODManager.cpp b/interface/src/LODManager.cpp index cfc1c94995..79d49fd6f1 100644 --- a/interface/src/LODManager.cpp +++ b/interface/src/LODManager.cpp @@ -217,6 +217,47 @@ QString LODManager::getLODFeedbackText() { return result; } +bool LODManager::shouldRender(const RenderArgs* args, const AABox& bounds) { + const float maxScale = (float)TREE_SCALE; + const float octreeToMeshRatio = 4.0f; // must be this many times closer to a mesh than a voxel to see it. + float octreeSizeScale = args->_sizeScale; + int boundaryLevelAdjust = args->_boundaryLevelAdjust; + float visibleDistanceAtMaxScale = boundaryDistanceForRenderLevel(boundaryLevelAdjust, octreeSizeScale) / octreeToMeshRatio; + float distanceToCamera = glm::length(bounds.calcCenter() - args->_viewFrustum->getPosition()); + float largestDimension = bounds.getLargestDimension(); + + static bool shouldRenderTableNeedsBuilding = true; + static QMap shouldRenderTable; + if (shouldRenderTableNeedsBuilding) { + + float SMALLEST_SCALE_IN_TABLE = 0.001f; // 1mm is plenty small + float scale = maxScale; + float factor = 1.0f; + + while (scale > SMALLEST_SCALE_IN_TABLE) { + scale /= 2.0f; + factor /= 2.0f; + shouldRenderTable[scale] = factor; + } + + shouldRenderTableNeedsBuilding = false; + } + + float closestScale = maxScale; + float visibleDistanceAtClosestScale = visibleDistanceAtMaxScale; + QMap::const_iterator lowerBound = shouldRenderTable.lowerBound(largestDimension); + if (lowerBound != shouldRenderTable.constEnd()) { + closestScale = lowerBound.key(); + visibleDistanceAtClosestScale = visibleDistanceAtMaxScale * lowerBound.value(); + } + + if (closestScale < largestDimension) { + visibleDistanceAtClosestScale *= 2.0f; + } + + return distanceToCamera <= visibleDistanceAtClosestScale; +}; + // TODO: This is essentially the same logic used to render octree cells, but since models are more detailed then octree cells // I've added a voxelToModelRatio that adjusts how much closer to a model you have to be to see it. bool LODManager::shouldRenderMesh(float largestDimension, float distanceToCamera) { diff --git a/interface/src/LODManager.h b/interface/src/LODManager.h index 615bcec24d..98ababbda0 100644 --- a/interface/src/LODManager.h +++ b/interface/src/LODManager.h @@ -49,6 +49,8 @@ const float ADJUST_LOD_MAX_SIZE_SCALE = DEFAULT_OCTREE_SIZE_SCALE; // do. But both are still culled using the same angular size logic. const float AVATAR_TO_ENTITY_RATIO = 2.0f; +class RenderArgs; +class AABox; class LODManager : public QObject, public Dependency { Q_OBJECT @@ -79,6 +81,7 @@ public: Q_INVOKABLE float getLODDecreaseFPS(); Q_INVOKABLE float getLODIncreaseFPS(); + static bool shouldRender(const RenderArgs* args, const AABox& bounds); bool shouldRenderMesh(float largestDimension, float distanceToCamera); void autoAdjustLOD(float currentFPS);