Culling and objects management

Started by
1 comment, last by cozzie 9 years, 9 months ago


Let say I have couple of thousands moving objects in my scene and i want to use frustum-sphere test to cull invisible ones.
Then in my code i have something like this:


struct BoundingSphere
{
   float x, y, z, radius;
};

struct ObjectsDetailPool
{
    BoundingSphere bs[MAX_OBJECTS];
    uint64_t visible[MAX_OBJECTS]; // 64 possible views
    DrawableThing dt[MAX_OBJECTS]; // mesh data
};

struct Object
{
    BoundingSphere* pbs;
    uint64_t* pvisible;
    DrawableThing* pdt;
};

vector<Object> vobjs;

... //here cull for all views

// draw
if(vobjs.empty())
   return;

...//set shader...
for(auto& obj : vobjs)
{
    if(obj.pvisible ...) // this is bad?
        obj.draw();
}

...// repeat draw for each view

But lot of texts say this is bad because of branch mispredictions and what not, usually there is a lot of criticism but none of the solutions shown.

I dont understand how should i construct/manage this list then?
Should i partition the vector? So i swap-back invisible objects and store iterator where visible ends, but then again i have a branch because i need to check if it is visible.
Create a new vector and push_back only visible objects? But then again i have a branch because i need to check if it is visible.

Advertisement
The results of culling should be stored in a separate vector. You don’t go over the main vector and mark things, you add pointers to them to a second vector.

The new list contains pointers to objects that are known to be visible, reducing the length of following for-loops and eliminating all of your concerns over branching.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I'd say the same and do it like this:

- cull and save visibility state per mesh instance's renderables

- save just an index with the ID's of the ones that are visible

- then render the 'bucket' using the ID list


/**************************************************************************************/
/***								CREATE BUCKET OPAQUE							***/
/*** ==> usage: to generate index (render bucket) with visible opaque renderables 	***/
/*** ==> refills the index/bucket with ID's of visible renderables					***/
/**************************************************************************************/

bool CRenderQueue::CreateBucketOpaque()
{
	mBucketOpaque.resize(0);

	for(size_t rend=0;rend<mRenderablesOpaque.size();++rend)
	{
		if(mRenderablesOpaque[rend].Visible) 
			mBucketOpaque.push_back(rend);
	}
	return true;
}

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

This topic is closed to new replies.

Advertisement