Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 7 developers from Canada and 18 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Culling and objects management


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 belfegor   Crossbones+   -  Reputation: 2799

Like
0Likes
Like

Posted 20 July 2014 - 01:27 PM


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, 20 July 2014 - 01:28 PM.


Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 21350

Like
5Likes
Like

Posted 20 July 2014 - 04:28 PM

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

#3 cozzie   Members   -  Reputation: 3433

Like
0Likes
Like

Posted 21 July 2014 - 12:12 AM

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS