LODManager uses new settings

This commit is contained in:
Atlante45 2015-01-19 21:27:21 -08:00
parent d0d16e088e
commit 23bab601c5
2 changed files with 66 additions and 51 deletions

View file

@ -16,6 +16,29 @@
#include "LODManager.h"
namespace SettingsKey {
const SettingHandle<int> boundaryLevelAdjust("boundaryLevelAdjust", 0);
const SettingHandle<float> octreeSizeScale("octreeSizeScale", DEFAULT_OCTREE_SIZE_SCALE);
}
float LODManager::getOctreeSizeScale() const {
return SettingsKey::octreeSizeScale.get();
}
void LODManager::setOctreeSizeScale(float sizeScale) {
SettingsKey::octreeSizeScale.set(sizeScale);
_shouldRenderTableNeedsRebuilding = true;
}
int LODManager::getBoundaryLevelAdjust() const {
return SettingsKey::boundaryLevelAdjust.get();
}
void LODManager::setBoundaryLevelAdjust(int boundaryLevelAdjust) {
SettingsKey::boundaryLevelAdjust.set(boundaryLevelAdjust);
_shouldRenderTableNeedsRebuilding = true;
}
void LODManager::autoAdjustLOD(float currentFPS) {
// NOTE: our first ~100 samples at app startup are completely all over the place, and we don't
// really want to count them in our average, so we will ignore the real frame rates and stuff
@ -31,54 +54,63 @@ void LODManager::autoAdjustLOD(float currentFPS) {
quint64 now = usecTimestampNow();
const quint64 ADJUST_AVATAR_LOD_DOWN_DELAY = 1000 * 1000;
if (_automaticAvatarLOD) {
if (_fastFPSAverage.getAverage() < _avatarLODDecreaseFPS) {
bool automaticAvatarLOD = SettingHandles::automaticAvatarLOD.get();
if (automaticAvatarLOD) {
float avatarLODIncreaseFPS = SettingHandles::avatarLODIncreaseFPS.get();
float avatarLODDecreaseFPS = SettingHandles::avatarLODDecreaseFPS.get();
float avatarLODDistanceMultiplier = SettingHandles::avatarLODDistanceMultiplier.get();
if (_fastFPSAverage.getAverage() < avatarLODDecreaseFPS) {
if (now - _lastAvatarDetailDrop > ADJUST_AVATAR_LOD_DOWN_DELAY) {
// attempt to lower the detail in proportion to the fps difference
float targetFps = (_avatarLODDecreaseFPS + _avatarLODIncreaseFPS) * 0.5f;
float targetFps = (avatarLODDecreaseFPS + avatarLODIncreaseFPS) * 0.5f;
float averageFps = _fastFPSAverage.getAverage();
const float MAXIMUM_MULTIPLIER_SCALE = 2.0f;
_avatarLODDistanceMultiplier = qMin(MAXIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER, _avatarLODDistanceMultiplier *
(averageFps < EPSILON ? MAXIMUM_MULTIPLIER_SCALE :
qMin(MAXIMUM_MULTIPLIER_SCALE, targetFps / averageFps)));
avatarLODDistanceMultiplier = qMin(MAXIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER,
avatarLODDistanceMultiplier * (averageFps < EPSILON ?
MAXIMUM_MULTIPLIER_SCALE :
qMin(MAXIMUM_MULTIPLIER_SCALE,
targetFps / averageFps)));
_lastAvatarDetailDrop = now;
}
} else if (_fastFPSAverage.getAverage() > _avatarLODIncreaseFPS) {
} else if (_fastFPSAverage.getAverage() > avatarLODIncreaseFPS) {
// let the detail level creep slowly upwards
const float DISTANCE_DECREASE_RATE = 0.05f;
_avatarLODDistanceMultiplier = qMax(MINIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER,
_avatarLODDistanceMultiplier - DISTANCE_DECREASE_RATE);
avatarLODDistanceMultiplier = qMax(MINIMUM_AVATAR_LOD_DISTANCE_MULTIPLIER,
avatarLODDistanceMultiplier - DISTANCE_DECREASE_RATE);
}
SettingHandles::avatarLODDistanceMultiplier.set(avatarLODDistanceMultiplier);
}
bool changed = false;
quint64 elapsed = now - _lastAdjust;
float octreeSizeScale = getOctreeSizeScale();
if (elapsed > ADJUST_LOD_DOWN_DELAY && _fpsAverage.getAverage() < ADJUST_LOD_DOWN_FPS
&& _octreeSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) {
&& octreeSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) {
_octreeSizeScale *= ADJUST_LOD_DOWN_BY;
octreeSizeScale *= ADJUST_LOD_DOWN_BY;
if (_octreeSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) {
_octreeSizeScale = ADJUST_LOD_MIN_SIZE_SCALE;
if (octreeSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) {
octreeSizeScale = ADJUST_LOD_MIN_SIZE_SCALE;
}
changed = true;
_lastAdjust = now;
qDebug() << "adjusting LOD down... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage()
<< "_octreeSizeScale=" << _octreeSizeScale;
<< "_octreeSizeScale=" << octreeSizeScale;
}
if (elapsed > ADJUST_LOD_UP_DELAY && _fpsAverage.getAverage() > ADJUST_LOD_UP_FPS
&& _octreeSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) {
_octreeSizeScale *= ADJUST_LOD_UP_BY;
if (_octreeSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) {
_octreeSizeScale = ADJUST_LOD_MAX_SIZE_SCALE;
&& octreeSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) {
octreeSizeScale *= ADJUST_LOD_UP_BY;
if (octreeSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) {
octreeSizeScale = ADJUST_LOD_MAX_SIZE_SCALE;
}
changed = true;
_lastAdjust = now;
qDebug() << "adjusting LOD up... average fps for last approximately 5 seconds=" << _fpsAverage.getAverage()
<< "_octreeSizeScale=" << _octreeSizeScale;
<< "_octreeSizeScale=" << octreeSizeScale;
}
setOctreeSizeScale(octreeSizeScale);
if (changed) {
_shouldRenderTableNeedsRebuilding = true;
@ -129,16 +161,6 @@ QString LODManager::getLODFeedbackText() {
return result;
}
void LODManager::setOctreeSizeScale(float sizeScale) {
_octreeSizeScale = sizeScale;
_shouldRenderTableNeedsRebuilding = true;
}
void LODManager::setBoundaryLevelAdjust(int boundaryLevelAdjust) {
_boundaryLevelAdjust = boundaryLevelAdjust;
_shouldRenderTableNeedsRebuilding = true;
}
// 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) {

View file

@ -14,6 +14,7 @@
#include <DependencyManager.h>
#include <OctreeConstants.h>
#include <Settings.h>
#include <SharedUtil.h>
#include <SimpleMovingAverage.h>
@ -37,26 +38,26 @@ const float DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER = 1.0f;
const int ONE_SECOND_OF_FRAMES = 60;
const int FIVE_SECONDS_OF_FRAMES = 5 * ONE_SECOND_OF_FRAMES;
namespace SettingHandles {
const SettingHandle<bool> automaticAvatarLOD("automaticAvatarLOD", true);
const SettingHandle<float> avatarLODDecreaseFPS("avatarLODDecreaseFPS", DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS);
const SettingHandle<float> avatarLODIncreaseFPS("avatarLODIncreaseFPS", ADJUST_LOD_UP_FPS);
const SettingHandle<float> avatarLODDistanceMultiplier("avatarLODDistanceMultiplier",
DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER);
}
class LODManager : public Dependency {
SINGLETON_DEPENDENCY
public:
void setAutomaticAvatarLOD(bool automaticAvatarLOD) { _automaticAvatarLOD = automaticAvatarLOD; }
bool getAutomaticAvatarLOD() const { return _automaticAvatarLOD; }
void setAvatarLODDecreaseFPS(float avatarLODDecreaseFPS) { _avatarLODDecreaseFPS = avatarLODDecreaseFPS; }
float getAvatarLODDecreaseFPS() const { return _avatarLODDecreaseFPS; }
void setAvatarLODIncreaseFPS(float avatarLODIncreaseFPS) { _avatarLODIncreaseFPS = avatarLODIncreaseFPS; }
float getAvatarLODIncreaseFPS() const { return _avatarLODIncreaseFPS; }
void setAvatarLODDistanceMultiplier(float multiplier) { _avatarLODDistanceMultiplier = multiplier; }
float getAvatarLODDistanceMultiplier() const { return _avatarLODDistanceMultiplier; }
// TODO: Once the SettingWatcher is implemented, replace them with normal SettingHandles.
float getOctreeSizeScale() const;
void setOctreeSizeScale(float sizeScale);
int getBoundaryLevelAdjust() const;
void setBoundaryLevelAdjust(int boundaryLevelAdjust);
// User Tweakable LOD Items
QString getLODFeedbackText();
void setOctreeSizeScale(float sizeScale);
float getOctreeSizeScale() const { return _octreeSizeScale; }
void setBoundaryLevelAdjust(int boundaryLevelAdjust);
int getBoundaryLevelAdjust() const { return _boundaryLevelAdjust; }
void autoAdjustLOD(float currentFPS);
void resetLODAdjust();
@ -66,14 +67,6 @@ public:
private:
LODManager() {}
bool _automaticAvatarLOD = true;
float _avatarLODDecreaseFPS = DEFAULT_ADJUST_AVATAR_LOD_DOWN_FPS;
float _avatarLODIncreaseFPS = ADJUST_LOD_UP_FPS;
float _avatarLODDistanceMultiplier = DEFAULT_AVATAR_LOD_DISTANCE_MULTIPLIER;
float _octreeSizeScale = DEFAULT_OCTREE_SIZE_SCALE;
int _boundaryLevelAdjust = 0;
quint64 _lastAdjust = 0;
quint64 _lastAvatarDetailDrop = 0;
SimpleMovingAverage _fpsAverage = FIVE_SECONDS_OF_FRAMES;