Distance/Occlusion Culling?


The world I am loading is pretty large, and right now it seems like bs:f is trying to render all objects, regardless of how far they are away. At least that is what I’m guessing as the performance is pretty bad when you look into the distance.

Is there any way to do simple distance culling? And if not, if I were to implement it, where would I start?

Also, I’ve seen there is some code regarding occlusion culling, but I haven’t found out how to use it yet. There is also this issue (https://github.com/GameFoundry/bsf/issues/31) which suggests it hasn’t been fully implemented yet?


Occlusion culling hasn’t been implemented at all yet. “large world” update is planned in the future once the essential features are in, and will include things like occlusion culling, LOD and texture streaming.

Distance culling should not be difficult to implement. In Source/Plugins/bsfRenderBeast/BsRendererView.cpp check the various RendererView::determineVisible methods that are currently responsible for doing frustum culling and culling based on visibility masks.

Eventually I want to move all culling logic to their own sub-system, so it’s easier to implement custom culling schemes, as well as parallelize the process across multiple threads, but that’s not something you need to worry about unless you really want to dig into this.


What would you prefer:

Have each Renderable have a “Cull Distance” value …

  1. … with the maximum absolute distance to the camera?
  2. … which is a factor of a globally defined cull distance?

Also, I seem to have some trouble with the linker. I added a getter/setter to the Renderable-Class and to the CRenderable class. In my own application Visual Studio then complains about undefined references to the new methods in CRenderable. I can however access them over _getInternal():

renderable->_getInternal()->setCullDistance(10.0f); // works
renderable->setCullDistance(10.0f); // does not

This is how I defined those in BSCRenderable.h:

		/** @copydoc Renderable::setCullDistance() */
	BS_SCRIPT_EXPORT(n:CullDistance, pr:setter)
	void setCullDistance(float maxDistanceToCamera) { mInternal->setCullDistance(maxDistanceToCamera); }

	/** @copydoc Renderable::getCullDistance() */
	BS_SCRIPT_EXPORT(n:CullDistance, pr:getter)
	float getCullDistance() const { return mInternal->getCullDistance(); }

There shouldn’t be any problems since they are declared and defined in the header file anyways…


Option #2 is better as it allows the cull distance to be tweaked easily in just one place (e.g. user could do it on the Options screen if needed).

The factor can be a percent of the camera’s cull distance as you suggest.
It can also be defined as object's screen space bounding box height / screen height. It’s a bit more complex approach but allows you to say “Hide the object when it’s taking up less than 5% of the screen height, by setting the factor to 0.05”, which feels like a more intuitive way of defining it + it’s resolution independent + automatically takes object’s size into account.

I’m not sure about the linking issue, the code looks fine. Try doing a full rebuild, visual studio can sometimes throw linker errors for no reason.