nodes to be rendered are sorted by distance to camera plane

This commit is contained in:
devZoGok
2022-12-27 14:45:23 +02:00
parent 41de623a66
commit cc2f6dc29b
3 changed files with 29 additions and 5 deletions
-3
View File
@@ -58,9 +58,6 @@ namespace vb01{
for(Skeleton *sk : skeletons)
sk->update();
for(Node *c : children)
c->update();
}
for(Driver *driver : drivers)
+28 -2
View File
@@ -153,7 +153,7 @@ namespace vb01{
AnimationController::getSingleton()->update();
rootNode->update();
updateNodeTree(rootNode);
LineRenderer::getSingleton()->drawLines();
@@ -167,12 +167,38 @@ namespace vb01{
updateGuiPlane();
glEnable(GL_DEPTH_TEST);
guiNode->update();
updateNodeTree(guiNode);
glfwSwapBuffers(window);
glfwPollEvents();
}
//TODO replace sorting algorithm and sort only transparent objects
void Root::updateNodeTree(Node *node){
vector<Node*> descendants;
node->getDescendants(descendants);
int numDesc = descendants.size();
for(int i = 0; i < numDesc; i++){
Vector3 v1 = descendants[i]->getPosition() - camera->getPosition();
float a1 = v1.norm().getAngleBetween(camera->getDirection());
float d1 = v1.getLength() * cos(a1);
for(int j = i; j < numDesc; j++){
Vector3 v2 = descendants[j]->getPosition() - camera->getPosition();
float a2 = v2.norm().getAngleBetween(camera->getDirection());
float d2 = v2.getLength() * cos(a2);
if(d1 < d2)
swap(descendants[i], descendants[j]);
}
}
for(Node *desc : descendants)
desc->update();
}
void Root::updateBloomFramebuffer(){
bool horizontal = false;
blurShader->use();
+1
View File
@@ -69,6 +69,7 @@ namespace vb01{
void initGuiPlane(Texture*, Texture*);
void updateBloomFramebuffer();
void updateGuiPlane();
void updateNodeTree(vb01::Node*);
};
}