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:
parent
f136c6fe36
commit
5cb36e38cf
@ -50,6 +50,7 @@ LODNode::LODNode(std::string group_name, scene::ISceneNode* parent,
|
|||||||
|
|
||||||
m_forced_lod = -1;
|
m_forced_lod = -1;
|
||||||
m_last_tick = 0;
|
m_last_tick = 0;
|
||||||
|
m_area = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LODNode::~LODNode()
|
LODNode::~LODNode()
|
||||||
@ -249,8 +250,44 @@ void LODNode::OnRegisterSceneNode()
|
|||||||
scene::ISceneNode::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)
|
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
|
// samuncle suggested to put a slight randomisation in LOD
|
||||||
// I'm not convinced (Auria) but he's the artist pro, so I listen ;P
|
// 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,
|
// The last level should not be randomized because after that the object disappears,
|
||||||
|
@ -62,6 +62,9 @@ private:
|
|||||||
* m_forced_lod is >=0, only this level is be used. */
|
* m_forced_lod is >=0, only this level is be used. */
|
||||||
int m_forced_lod;
|
int m_forced_lod;
|
||||||
|
|
||||||
|
// Area of the bounding box (for autoLOD computation)
|
||||||
|
float m_area;
|
||||||
|
|
||||||
enum PreviousVisibility
|
enum PreviousVisibility
|
||||||
{
|
{
|
||||||
FIRST_PASS,
|
FIRST_PASS,
|
||||||
@ -104,6 +107,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void add(int level, scene::ISceneNode* node, bool reparent);
|
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);
|
void forceLevelOfDetail(int n);
|
||||||
|
|
||||||
/** Get the highest level of detail node */
|
/** Get the highest level of detail node */
|
||||||
|
@ -151,8 +151,7 @@ LODNode* ModelDefinitionLoader::instanciateAsLOD(const XMLNode* node, scene::ISc
|
|||||||
}
|
}
|
||||||
vector3df scale = vector3df(1.f, 1.f, 1.f);
|
vector3df scale = vector3df(1.f, 1.f, 1.f);
|
||||||
node->get("scale", &scale);
|
node->get("scale", &scale);
|
||||||
// TODO samuncle: can be enabled after RC
|
lod_node->autoComputeLevel(scale.getLength());
|
||||||
//lod_node->autoComputeLevel(scale.getLength());
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::string debug_name = groupname+" (LOD track-object)";
|
std::string debug_name = groupname+" (LOD track-object)";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user