• Advertisement
Sign in to follow this  

Culling and objects management

This topic is 1281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


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.

Edited by belfegor

Share this post


Link to post
Share on other sites
Advertisement

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;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement