Jump to content
  • Advertisement
Sign in to follow this  
widmowyfox

Frustum culling, profit or loss?

This topic is 883 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

I have some problems with frustum culling, it should save fps for me but:

 

 

28cjd4g.jpg

 

 

 

 

ie4eq0.jpg

 

 

And frustum culling code (if necessery-I am using instancing):

if(mFrustumCullingEnabled==true)
	{
		XMVECTOR detView = XMMatrixDeterminant(mCam.View());
		XMMATRIX invView = XMMatrixInverse(&detView, mCam.View());
	
		D3D11_MAPPED_SUBRESOURCE mappedData; 
		md3dImmediateContext->Map(mInstancedBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData);

		InstancedData* dataView = reinterpret_cast<InstancedData*>(mappedData.pData);

		for(UINT i = 0; i < mInstancedData.size(); ++i)
		{
			XMMATRIX W = XMLoadFloat4x4(&mInstancedData[i].World);
			XMMATRIX invWorld = XMMatrixInverse(&XMMatrixDeterminant(W), W);

			
			XMMATRIX toLocal = XMMatrixMultiply(invView, invWorld);
		
		
			XMVECTOR scale;
			XMVECTOR rotQuat;
			XMVECTOR translation;
			XMMatrixDecompose(&scale, &rotQuat, &translation, toLocal);


			XNA::Frustum localspaceFrustum;
			XNA::TransformFrustum(&localspaceFrustum, &mCamFrustum, XMVectorGetX(scale), rotQuat, translation);

	
			if(XNA::IntersectAxisAlignedBoxFrustum(&mSkullBox, &localspaceFrustum) != 0)
			{

				dataView[mVisibleObjectCount++] = mInstancedData[i];
			}
		}

		md3dImmediateContext->Unmap(mInstancedBuffer, 0);
	}
	else 
	{
		D3D11_MAPPED_SUBRESOURCE mappedData; 
		md3dImmediateContext->Map(mInstancedBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData);

		InstancedData* dataView = reinterpret_cast<InstancedData*>(mappedData.pData);

		for(UINT i = 0; i < mInstancedData.size(); ++i)
		{
			dataView[mVisibleObjectCount++] = mInstancedData[i];
		}

		md3dImmediateContext->Unmap(mInstancedBuffer, 0);
	}

I'm counting on help :)

Share this post


Link to post
Share on other sites
Advertisement

Are you somehow CPU bound? If so, adding Frustum Culling to the work the CPU has to do has just made the problem worse.

 

Do you know where your current bottleneck lies?

Are you running in Debug or with the Debug layer turned on by any chance?

Share this post


Link to post
Share on other sites

Very thanks vinterberg, now I have about 1000-1500 fps on frustum culling, probably too many calculations smile.png and  @Adam Miles no I wasnt at debug when screenshots captured.  Does it matter?

Edited by widmowyfox

Share this post


Link to post
Share on other sites

It mattered only because I couldn't come up with any other reasonable explanation for drawing 100 objects per frame causing you to be CPU bound and running in Debug might have been one reason. But since it's fixed we needn't delve into it any further!

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!