Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Q: Space Partitioning Trees.

  1. #11
    Intern Contributor
    Join Date
    Apr 2015
    Posts
    75
    Well, so rebuilding the VBO is not a practice with culling ? What is then ? I am just looking for a definitive answer, method.
    Can you elaborate
    ... unnecessary. You can use glMultiDrawElements to draw 5-6 separate ranges from the (static) VBO. The octree search would append one element onto the count and indices arrays for each node which passes.
    Also the other obvious solution to that is maybe to have a VBO/VAO for each leaf , then only rebind the leaves which intersect the frustum. So here arises the Question is rebinding bettter than rebuilding ? Guess yes ?

    Code :
     
    bool view_Culling(CFrustum& frusrum, COctree *node)
    {
    if (!node)
        return false;
     
    if (frusrum.CubeInFrustum(node->GetCenter().x, node->GetCenter().y, node-       >GetCenter().z,(node->GetWidth()/2.0f)))
    {
        if (node->IsSubDivided())
        {
            view_Culling(frusrum, node->OctreeNodes()[TOP_LEFT_FRONT]);
            view_Culling(frusrum, node->OctreeNodes()[TOP_LEFT_BACK]);
            view_Culling(frusrum, node->OctreeNodes()[TOP_RIGHT_BACK]);
            view_Culling(frusrum, node->OctreeNodes()[TOP_RIGHT_FRONT]);
            view_Culling(frusrum, node->OctreeNodes()[BOTTOM_LEFT_FRONT]);
            view_Culling(frusrum, node->OctreeNodes()[BOTTOM_LEFT_BACK]);
            view_Culling(frusrum, node->OctreeNodes()[BOTTOM_RIGHT_BACK]);
            view_Culling(frusrum, node->OctreeNodes()[BOTTOM_RIGHT_FRONT]);
        }
        else
        {
            //use prebuilded vbo here
            //or push these vertices here in a list later build a dynamic vbo
            //from them
            node->DrawOctree(node);
            return true;
        }
    }
    return false;
    }
    Last edited by Asmodeus; 08-27-2015 at 04:28 AM.

  2. #12
    Intern Contributor
    Join Date
    Apr 2015
    Posts
    75
    I will post this as a final note at what i want to acomplish, using multiple levels of tests.
    The idea is that i have some kind of a BVH(maybe octree of AABBs) which will contain the Bounding Volumes of each object in a given scene. Then i will perfrom frustum tests on that structure to determine the nodes (and respectivly the models in that node) that are visible or not. Those that are not visible are simply not drawn, Those that are visible have 2 options:
    - They are Partly visible (their bounding volume is bigger than the frusum but still visible - Terrains,Big Buildings etc...) - Here is where the Octree from above comes into play. They will be tested against an Octree to determine exaclty which parts of them are visible. I wont go deep into my implementation but to clarify i can say that each object has modeldata property , modeldata can be reused among many objects. Each modeldata contains - vbo,ibo, vertices. Now it will contain prebuilt octree from the vertices so i can use it when i need to determine what to draw when the model is partly visible. I will probably test in object space since the vertices are already there and i will need to translate the frustum also in object space.
    - They are entirely visible (their bounding volume is smaller than the frusum) - Directly sent to be drawn
    Currently that is going to be applied to static , non-moving objects.

    ALSO: How would i fit multiple objects bounding boxes in an octree (leaf/node?!) for the first test pass, where i should test against the objects as a whole. I cant actually grasp how i can devide the world space and put the bounding boxes(spheres) of the objects inside that octree

  3. #13
    Intern Contributor
    Join Date
    Apr 2015
    Posts
    75
    I worked out the above Questions after some time. But i was wondering, since my geometry is split between all leaves, so each leaf has some chunk of the terrain vertices (for now just vertices,no indices involved to avoid complications). So i am using flat out buffer where all vertices are ordered according to the indices, ready to be drawn. But since my geometry is split , how sould i specifiy offsets to the glVertexAttribPointer (or rather how would one obtain those offsets per leaf)
    I want to draw with just specifying offset to the buffer without having to rebind or recreate a vbo for each leaf every time.
    Thanks in Advance !

    EDIT: What i have tried so far:
    - prebuilding 1 VBO per Leaf - Relatively Fast but i feel i can do better
    * bind VBO
    * render VBO
    * repeat for every visible leaf in Frustum (getting about 20-25 bind/draw calls on average depends on where i am looking ofc)
    - getting list of all visible nodes , rebuild a new vbo every frame containing all visible node's vertices - Very Slow (even with gl_dynamic_draw)
    *get a list of all visible nodes
    *push each node's vertices in an array
    *dynamicly create VBO with all vertices
    * bind the big VBO , render (1 bind , 1 Draw)
    - Here is the next option i want to try But dont really know how
    * bind the main/global Model's vbo
    * for each visible leaf drawArrays/Elements with some offset and vertex count from the global Model vbo

    I realize i cant very well avoid multiple draw calls but i can avoid dynamicly building buffers or rebinding each time i want to draw which maybe just enought to improve the perfromance.
    Last edited by Asmodeus; 08-31-2015 at 11:39 AM.

  4. #14
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,526
    Quote Originally Posted by Asmodeus View Post
    I realize i cant very well avoid multiple draw calls
    If you're using OpenGL 3.2 or later, you can draw as many sub-ranges of a VBO as you wish with a single glMultiDrawArrays() call.

    With earlier versions, you can generate an index array dynamically then use a single glDrawElements() call; whether or not that's faster than multiple draw calls will probably depend upon the number of primitives per draw call.

  5. #15
    Intern Contributor
    Join Date
    Apr 2015
    Posts
    75
    Quote Originally Posted by GClements View Post
    If you're using OpenGL 3.2 or later, you can draw as many sub-ranges of a VBO as you wish with a single glMultiDrawArrays() call.

    With earlier versions, you can generate an index array dynamically then use a single glDrawElements() call; whether or not that's faster than multiple draw calls will probably depend upon the number of primitives per draw call.
    Great yea, glMultiDrawArrays may be what i am looking for. But yet again i am stumbled upon finding the offsets in each leaf.

  6. #16
    Junior Member Regular Contributor
    Join Date
    Mar 2009
    Location
    Seattle, WA
    Posts
    214
    If you use such approaches with arbitrary geometry, you either have to "cut" the geometry along the partition planes so that each portion lies within a specific region, or you have to allow for the fact that each object (or triangle) lies within multiple regions.

    Objects don't have to only exist in terminal nodes. You can just assign that object to the next level up node that completely encloses it. That's what I do in Leadwerks.

  7. #17
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,526
    Quote Originally Posted by JoshKlint View Post
    Objects don't have to only exist in terminal nodes. You can just assign that object to the next level up node that completely encloses it.
    While true, that can result in the object's bounding box being orders of magnitude larger than is necessary (e.g. an object at the very centre of the octree would belong to the top-level node and thus always be "visible").

  8. #18
    Intern Contributor
    Join Date
    Apr 2015
    Posts
    75
    Just out of curiousity. If i have an octree which divides certain geometry in leaves and i have a number of vertices per leaves that represent part of the model. How would one use one general VBO (that contains the entire model's vertex data) to draw the visible leaves (using offsets in drawElements/Arrays).
    I want to avoid having 1 VBO per leaf rather i want to have one general VBO that contains the entire model and just draw ranges from that VBO. But how would i generate the offset needed per leaf ???

  9. #19
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,526
    Quote Originally Posted by Asmodeus View Post
    But how would i generate the offset needed per leaf ???
    The data for each node would be a (start,count) pair (or perhaps multiple such pairs) indicating the range(s) of indices corresponding to the geometry for that node. So to draw a given node, you'd append the node's values to the indices and count arrays passed to glMultiDrawElements().

    However, if you can have geometry belonging to multiple nodes, you'd first want to remove any duplicates prior to rendering.

  10. #20
    Intern Contributor
    Join Date
    Apr 2015
    Posts
    75
    Yea thats what i figured , but how would one find start. I have the count available, but how about the start. Should i get the first vertex from the node to be the start vertex ?
    Also cant i use glDrawElements/Arrays to specify offset such as:
    glDrawArrays(GL_TRIANGLES,first,count) ?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •