Feature/enable lod autocompute (#3970)

* Enable LoD autocompute

* bring back the autocompute lod function

* Add the area as main function to compute the lod level

* Bring back the area based auto lod computation

Co-authored-by: samuncle <samuncle06@gmail.com>
This commit is contained in:
samuncle 2021-02-12 04:16:38 +01:00 committed by GitHub
parent f136c6fe36
commit 5cb36e38cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 2 deletions

View File

@ -50,6 +50,7 @@ LODNode::LODNode(std::string group_name, scene::ISceneNode* parent,
m_forced_lod = -1;
m_last_tick = 0;
m_area = 0;
}
LODNode::~LODNode()
@ -249,8 +250,44 @@ void LODNode::OnRegisterSceneNode()
scene::ISceneNode::OnRegisterSceneNode();
}
void LODNode::autoComputeLevel(float scale)
{
m_area *= scale;
// Amount of details based on user's input
float agressivity = 1.0;
if(UserConfigParams::m_geometry_level == 0) agressivity = 1.25;
if(UserConfigParams::m_geometry_level == 1) agressivity = 1.0;
if(UserConfigParams::m_geometry_level == 2) agressivity = 0.75;
// First we try to estimate how far away we need to draw
float max_draw = 0.0;
max_draw = sqrtf((0.5 * m_area + 10) * 200) - 10;
// If the draw distance is too big we artificially reduce it
if(max_draw > 250)
{
max_draw = 250 + (max_draw * 0.06);
}
max_draw *= agressivity;
int step = (int) (max_draw * max_draw) / m_detail.size();
// Then we recompute the level of detail culling distance
int biais = m_detail.size();
for(int i = 0; i < m_detail.size(); i++)
{
m_detail[i] = ((step / biais) * (i + 1));
biais--;
}
}
void LODNode::add(int level, scene::ISceneNode* node, bool reparent)
{
Box = node->getBoundingBox();
m_area = Box.getArea();
// samuncle suggested to put a slight randomisation in LOD
// I'm not convinced (Auria) but he's the artist pro, so I listen ;P
// The last level should not be randomized because after that the object disappears,

View File

@ -62,6 +62,9 @@ private:
* m_forced_lod is >=0, only this level is be used. */
int m_forced_lod;
// Area of the bounding box (for autoLOD computation)
float m_area;
enum PreviousVisibility
{
FIRST_PASS,
@ -104,6 +107,11 @@ public:
*/
void add(int level, scene::ISceneNode* node, bool reparent);
/**
* This method can be used to automatically compute LoD level
*/
void autoComputeLevel(float scale);
void forceLevelOfDetail(int n);
/** Get the highest level of detail node */

View File

@ -151,8 +151,7 @@ LODNode* ModelDefinitionLoader::instanciateAsLOD(const XMLNode* node, scene::ISc
}
vector3df scale = vector3df(1.f, 1.f, 1.f);
node->get("scale", &scale);
// TODO samuncle: can be enabled after RC
//lod_node->autoComputeLevel(scale.getLength());
lod_node->autoComputeLevel(scale.getLength());
#ifdef DEBUG
std::string debug_name = groupname+" (LOD track-object)";