mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 15:59:57 +02:00
build a cached lookup table for the shouldRenderMesh() LOD method
This commit is contained in:
parent
bf77adc4bc
commit
d238d06df5
2 changed files with 38 additions and 15 deletions
|
@ -122,7 +122,8 @@ Menu::Menu() :
|
|||
_hasLoginDialogDisplayed(false),
|
||||
_snapshotsLocation(),
|
||||
_scriptsLocation(),
|
||||
_walletPrivateKey()
|
||||
_walletPrivateKey(),
|
||||
_shouldRenderTableNeedsRebuilding(true)
|
||||
{
|
||||
Application *appInstance = Application::getInstance();
|
||||
|
||||
|
@ -1551,6 +1552,7 @@ void Menu::autoAdjustLOD(float currentFPS) {
|
|||
&& _voxelSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) {
|
||||
|
||||
_voxelSizeScale *= ADJUST_LOD_DOWN_BY;
|
||||
|
||||
if (_voxelSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) {
|
||||
_voxelSizeScale = ADJUST_LOD_MIN_SIZE_SCALE;
|
||||
}
|
||||
|
@ -1573,6 +1575,7 @@ void Menu::autoAdjustLOD(float currentFPS) {
|
|||
}
|
||||
|
||||
if (changed) {
|
||||
_shouldRenderTableNeedsRebuilding = true;
|
||||
if (_lodToolsDialog) {
|
||||
_lodToolsDialog->reloadSliders();
|
||||
}
|
||||
|
@ -1587,36 +1590,53 @@ void Menu::resetLODAdjust() {
|
|||
|
||||
void Menu::setVoxelSizeScale(float sizeScale) {
|
||||
_voxelSizeScale = sizeScale;
|
||||
_shouldRenderTableNeedsRebuilding = true;
|
||||
bumpSettings();
|
||||
}
|
||||
|
||||
void Menu::setBoundaryLevelAdjust(int boundaryLevelAdjust) {
|
||||
_boundaryLevelAdjust = boundaryLevelAdjust;
|
||||
_shouldRenderTableNeedsRebuilding = true;
|
||||
bumpSettings();
|
||||
}
|
||||
|
||||
// TODO: This could be optimized to be a table, or something that doesn't require recalculation on every
|
||||
// render call for every entity
|
||||
// TODO: This is essentially the same logic used to render voxels, but since models are more detailed then voxels
|
||||
// I've added a voxelToModelRatio that adjusts how much closer to a model you have to be to see it.
|
||||
bool Menu::shouldRenderMesh(float largestDimension, float distanceToCamera) const {
|
||||
bool Menu::shouldRenderMesh(float largestDimension, float distanceToCamera) {
|
||||
const float voxelToMeshRatio = 4.0f; // must be this many times closer to a mesh than a voxel to see it.
|
||||
float voxelSizeScale = getVoxelSizeScale();
|
||||
int boundaryLevelAdjust = getBoundaryLevelAdjust();
|
||||
float maxScale = (float)TREE_SCALE;
|
||||
float visibleDistanceAtMaxScale = boundaryDistanceForRenderLevel(boundaryLevelAdjust, voxelSizeScale) / voxelToMeshRatio;
|
||||
|
||||
float scale = (float)TREE_SCALE;
|
||||
float visibleDistanceAtScale = boundaryDistanceForRenderLevel(boundaryLevelAdjust, voxelSizeScale) / voxelToMeshRatio;
|
||||
if (_shouldRenderTableNeedsRebuilding) {
|
||||
_shouldRenderTable.clear();
|
||||
|
||||
while (scale > largestDimension) {
|
||||
scale /= 2.0f;
|
||||
visibleDistanceAtScale /= 2.0f;
|
||||
}
|
||||
|
||||
if (scale < largestDimension) {
|
||||
visibleDistanceAtScale *= 2.0f;
|
||||
float SMALLEST_SCALE_IN_TABLE = 0.001f; // 1mm is plenty small
|
||||
float scale = maxScale;
|
||||
float visibleDistanceAtScale = visibleDistanceAtMaxScale;
|
||||
|
||||
while (scale > SMALLEST_SCALE_IN_TABLE) {
|
||||
scale /= 2.0f;
|
||||
visibleDistanceAtScale /= 2.0f;
|
||||
_shouldRenderTable[scale] = visibleDistanceAtScale;
|
||||
}
|
||||
_shouldRenderTableNeedsRebuilding = false;
|
||||
}
|
||||
|
||||
return (distanceToCamera <= visibleDistanceAtScale);
|
||||
float closestScale = maxScale;
|
||||
float visibleDistanceAtClosestScale = visibleDistanceAtMaxScale;
|
||||
QMap<float, float>::const_iterator lowerBound = _shouldRenderTable.lowerBound(largestDimension);
|
||||
if (lowerBound != _shouldRenderTable.constEnd()) {
|
||||
closestScale = lowerBound.key();
|
||||
visibleDistanceAtClosestScale = lowerBound.value();
|
||||
}
|
||||
|
||||
if (closestScale < largestDimension) {
|
||||
visibleDistanceAtClosestScale *= 2.0f;
|
||||
}
|
||||
|
||||
return (distanceToCamera <= visibleDistanceAtClosestScale);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ public:
|
|||
void setBoundaryLevelAdjust(int boundaryLevelAdjust);
|
||||
int getBoundaryLevelAdjust() const { return _boundaryLevelAdjust; }
|
||||
|
||||
bool shouldRenderMesh(float largestDimension, float distanceToCamera) const;
|
||||
bool shouldRenderMesh(float largestDimension, float distanceToCamera);
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
SpeechRecognizer* getSpeechRecognizer() { return &_speechRecognizer; }
|
||||
|
@ -312,6 +312,9 @@ private:
|
|||
QString _snapshotsLocation;
|
||||
QString _scriptsLocation;
|
||||
QByteArray _walletPrivateKey;
|
||||
|
||||
bool _shouldRenderTableNeedsRebuilding;
|
||||
QMap<float, float> _shouldRenderTable;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue