Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] View Frustrum Culling using Octrees #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ACapo
Copy link

@ACapo ACapo commented Nov 11, 2015

Hello @mosra,
this is what I've been working on together with @Squareys for the last few months. It's in a working state but there's still some cleanup work to do. I'd appreciate if you could take a look at the code and point out major issues you find.

Greetings,
@ACapo

# ${CMAKE_CURRENT_BINARY_DIR}/configure.h)

set(MagnumOctree_SRCS
Octree.hpp)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library is empty (there are just templates which are not instantiated anywhere) and thus both MSVC and Clang/OSX build is failing. I'm not sure whether doing an instantiation.cpp file like in SceneGraph would make any sense, so I guess just not creating any library (and only installing/including the headers) will be enough.

Similarly for the DrawableGroup library below.

Oh, and I guess the *.hpp file has to be included by the users, so it should be in MagnumOctree_HEADERS I think?

@ACapo ACapo force-pushed the octree branch 3 times, most recently from e51be56 to 2beaaaf Compare November 20, 2015 23:54
@Squareys
Copy link
Contributor

Squareys commented Sep 16, 2016

So, here's an overview of what is left TODO:

  • Enable SceneGraph on CI since MagnumExtras::SceneGraph depends on it
  • Remove Shapes dependency
  • Cleanup Math::Geometry::Intersections namespace in Octree.h, maybe move some functions to Magnum::Math instead.
  • Use new Math::Frustum class
  • Adapt FindMagnumExtras
  • Think about how to handle the big amounts of allocations going on more efficiently. (I saw some kind of "OctreeNodePool" on another implemenation?)
  • Documentation, Documentation, Documentation
  • Cleanup test cases
  • Add more (and especially transparent, easily understandable) tests.
  • Possibly extend to QuadTrees (should could is be possible without too much hassle)
  • Squash some of the commits for nicer git history

That's still quite alot, but maybe, if we skip a few things (like allocation optimization or QuadTree) for now and mark this as experimental API, we can get this ancient PR finally merged.

Copy link
Owner

@mosra mosra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Squareys I roughly went over the changes, trying not to complain over things that are still in the TODO list of yours. Hopefully it's not too much to ask :)


set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CORRADE_CXX_FLAGS}")

include_directories(${MAGNUM_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the above should be needed anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

target_include_directories(MagnumOctree PUBLIC
${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src
$<TARGET_PROPERTY:Magnum::Magnum,INTERFACE_INCLUDE_DIRECTORIES>)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Magnum include directories were already added by the target_link_libraries() call above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's due to moving from the old CMake files to the new system, seems I forgot to clean up quite alot.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

if(BUILD_TESTS)
add_subdirectory(Test)
endif()

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superfluous newline? :P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

/** @file
* @brief Class @ref Magnum::Octree::Octree
*
* @author Andrea Capobianco
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use the @author command. Author names will be mentioned in the CREDITS.md file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

#include <Magnum/Shapes/AxisAlignedBox.h>

#include <vector>
#include "visibility.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use absolute includes, i.e. Magnum/Octree/visibility.h.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

const Vector4 bottom{mvp.row(3) + mvp.row(1)};
const Vector4 top{mvp.row(3) - mvp.row(1)};
const Vector4 near{mvp.row(3) + mvp.row(2)};
const Vector4 far{mvp.row(3) - mvp.row(2)};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't there a function for this somewhere? If not, can there be such a function? Or the Frustum class we were talking about?

# DEALINGS IN THE SOFTWARE.
#

corrade_add_test(OctreeDrawableGroupTest OctreeDrawableGroupTest.cpp LIBRARIES MagnumOctreeDrawableGroup ${MAGNUM_LIBRARY} ${MAGNUM_SCENEGRAPH_LIBRARIES})
Copy link
Owner

@mosra mosra Sep 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, don't use old-style CMake. Both of these libraries should be linked by the MagnumOctreeDrawableGroup library anyway so no need to specify them implicitly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

Copyright © 2010, 2011, 2012, 2013, 2014, 2015
Vladimír Vondruš <[email protected]>
Copyright © 2015
Andrea Capobianco <[email protected]>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation is wrong here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

#include "Magnum/SceneGraph/OctreeDrawableGroup.hpp"

using namespace std;
using namespace Corrade;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No and no ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This header doesn't look like it should, making automated updates very hard to do.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever went wrong there 😅
✔️

Copy link
Owner

@mosra mosra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to look into the Find module, so here you have a few more comments :)

@@ -12,7 +12,7 @@
#
# This command alone is useless without specifying the components:
#
# (none yet)
# Octree - Octree BSP structure for Magnum::SceneGraph
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just say "Octree library" here and align the - ... at the same column as the above list

@@ -65,6 +66,7 @@

# Corrade library dependencies
set(_MAGNUMEXTRAS_CORRADE_DEPENDENCIES )

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?


if(_component MATCHES SceneGraph)
set(_MAGNUMEXTRAS_${_COMPONENT}_MAGNUM_DEPENDENCIES SceneGraph)
endif()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how the SceneGraph component of extras will interact with SceneGraph component of Magnum, so please just merge all that into the Octree library as I said in the previous review.


# Mark the dependencies as required if the component is also required
if(MagnumExtras_FIND_REQUIRED_${_component})
foreach(_dependency ${_MAGNUMEXTRAS_${_COMPONENT}_DEPENDENCIES})
foreach(_dependency ${})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@@ -117,7 +128,7 @@ endif()

# Component distinction (listing them explicitly to avoid mistakes with finding
# components from other repositories)
set(_MAGNUMEXTRAS_LIBRARY_COMPONENTS "^$")
set(_MAGNUMEXTRAS_LIBRARY_COMPONENTS "(Octree|SceneGraph)")
Copy link
Owner

@mosra mosra Sep 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ^$ are important here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@codecov-io
Copy link

codecov-io commented Mar 30, 2018

Codecov Report

Merging #1 into master will increase coverage by 7.89%.
The diff coverage is 96.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #1      +/-   ##
==========================================
+ Coverage   19.24%   27.13%   +7.89%     
==========================================
  Files          35       39       +4     
  Lines        1408     1566     +158     
==========================================
+ Hits          271      425     +154     
- Misses       1137     1141       +4
Impacted Files Coverage Δ
src/Magnum/Octree/OctreeDrawableGroup.h 100% <100%> (ø)
src/Magnum/Octree/OctreeDrawableGroup.hpp 91.3% <91.3%> (ø)
src/Magnum/Octree/Octree.h 96.15% <96.15%> (ø)
src/Magnum/Octree/Octree.hpp 97.16% <97.16%> (ø)
src/Magnum/Ui/Style.cpp 1.52% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update abed046...0f9314a. Read the comment docs.

int corners = 0;

for(UnsignedByte c = 0; c < 8; ++c) {
const Math::Vector3<T> corner = Math::lerp(min, max, Math::BoolVector<3>{c});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If doing intersection test between an AABB and a Frustum, only 2 vertices is needed. This is an optimization you can consider.
For technical details, you can read the chapter, Geometric Approach - Testing Boxes II in this article.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can directly use aabbFrustum from Magnum\Math\Intersection.h

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bigbike!

Currently neither @ACapo nor I am actively working on this PR, especially since we figured out that using aabbFrustum (which I contributed btw :) mosra/magnum@04ca48c) directly was just as fast for our use case (we only had around 60-80 objects) and building the octree actually caused more overhead...

This is still in the back of my mind and I really want to finish it, but at the moment I can't take the time.

Best, Jonathan.

Copy link

@bigbike bigbike Dec 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Squareys ,

Good to see your reply!
Before commenting yesterday, I read the source code of aabbFrustum, which was implemented in a very elegant, efficient manner. A pieces of very high-quality code. Did not know the author was you. I like it a lot. :-)

I like the code in this PR as well. Do not give up! Such functionality is rather necessary and important especially when rendering large-scale, static, geometrically-complex models.

Nice meeting you in this PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

5 participants