christian.wolf2 Posted December 6, 2020 Posted December 6, 2020 Hi there, I am currently looking in a way to detect, if a surface is visible or not. I found this thread, but I am more convinced if there is a way to just get access to an already implemented variable. When debugging, I can see that the object-class already holds some data about each surface, one is "visible" which is true or false, based on its LOD-data. It would be nice if you can have access to those variable (and maybe "faded" would be also a nice to have). The reason is, that there are multiple AI logic based on the object distance to the player or camera. So closer entities get a more frequent or more complex AI update than entities further away. For now I can only calculate the distance between player and object and using getMinVisibleDistance/getMaxVisibleDistance() to fit my needs. But this does an unnecessary distance-check, the engine has already done. So a more convenient way (at least for me) is to have access to those data and thread those values by myself. Cheers Christian
silent Posted December 7, 2020 Posted December 7, 2020 Hi Christian, Can you elaborate which API you need and what is the expected usage (a code snippets would be great). We'll see if that's possible to expose without a significat performance loss. Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
christian.wolf2 Posted December 7, 2020 Author Posted December 7, 2020 Hi silent, actually it is pretty straightforward for a C++API. I have an object with 3 LODs, so LOD0, LOD1 and LOD2. My current code is something like that: void Entity::update(float iFPS) { Scalar doubleDistance = Unigine::Math::length2(object->getWorldPosition() - player->getWorldPosition()); if (object->getMaxVisibleDistance(0) * object->getMaxVisibleDistance(0) < doubleDistance) { //LOD-0 updateCloseLogic(iFPS); } else if (object->getMaxVisibleDistance(1) * object->getMaxVisibleDistance(1) < doubleDistance) { //LOD-1 updateMediumLogic(iFPS); } else if (object->getMaxVisibleDistance(2) * object->getMaxVisibleDistance(2) < doubleDistance) { //LOD-2 updateFarLogic(iFPS); } else { //object is out of range updateOffScreenLogic(iFPS); } } I have to make an distance calculation and decide on that, which LOD will be active or if the object is completely not drawn. When implementing access to the already existing variables, the code changes to something like: void Entity::update(float iFPS) { if (node->isSurfaceVisible(0)) { //LOD-0 updateCloseLogic(iFPS); } else if (node->isSurfaceVisible(1)) { //LOD-1 updateMediumLogic(iFPS); } else if (node->isSurfaceVisible(2)) { //LOD-2 updateFarLogic(iFPS); } else { //object is out of range updateOffScreenLogic(iFPS); } } This avoids the distance calculation and safes a couple of CPU-cycles. I know it is not much but trying to render and update a large amount of entities may safe some performance. And it is (from an outside-view) not very performance critical, because the variables are already there and the engine already needs to know which surface will be currently rendered or not. Best Christian
silent Posted December 7, 2020 Posted December 7, 2020 Hi Christian, Thanks for the update. We will think of exposing these parameters (or maybe some kind another way) in the future releases. 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
Recommended Posts