Sign in to follow this  

Frustum Culling

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

Hey, Just looking for a bit of advice about rendering an FPS scene, im using DirectX (native) with C++ and so far ive got my map which is in a single .x file. Now ive come to do some view frustum culling ive hit a snag, since im using D3DXLoadMeshFromX to import the mesh info all the seperate meshes from the map (in 3d Studio Max) are getting placed into one big one.. So when i come to view frustum culling its litrally the whole map or nothing, heres the code ive made for the creation of the bounding spheres and the view frustum culling (its pretty basic), what i want to know is if its possible to take a subset of the mesh, create a bounding sphere for it and then use that to test each piece if its inside the view frustum:

LoadTerrain()
{
...
//
	// Extract the materials, and load textures.
	//

	if( mtrlBuffer != 0 && numMtrls != 0 )
	{
		D3DXMATERIAL* mtrls = (D3DXMATERIAL*)mtrlBuffer->GetBufferPointer();

		for(int i = 0; i < numMtrls; i++)
		{
			// the MatD3D property doesn't have an ambient value set
			// when its loaded, so set it now:
			mtrls[i].MatD3D.Ambient = mtrls[i].MatD3D.Diffuse;

			// save the ith material
			Mtrls.push_back( mtrls[i].MatD3D );

			// check if the ith material has an associative texture
			if( mtrls[i].pTextureFilename != 0 )
			{
				// yes, load the texture for the ith subset
			std::wstring TexFilename = CA2W(mtrls[i].pTextureFilename);
			std::wstring path = TEXT("Ancients\\");
			std::wstring finalPath;

			finalPath = path + TexFilename;
			IDirect3DTexture9* tex = 0;
				
				D3DXCreateTextureFromFile(
					Device,
					finalPath.c_str(),
					&tex);

				// save the loaded texture
				Textures.push_back( tex );
			}
			else
			{
				// no texture for the ith subset
				Textures.push_back( 0 );
			}
           }

...

        //Do Bounding sphere
        LPD3DXMESH pD3DXMesh = ancientsMesh;
        DWORD numVertices = ancientsMesh->GetNumVertices();
        DWORD fvfSize = D3DXGetFVFVertexSize( pD3DXMesh->GetFVF() );
        char* pData = NULL;
        if ( FAILED( pD3DXMesh->LockVertexBuffer( 0, (void**)&pData ) ) )
        {
            //error
        }
        D3DXComputeBoundingSphere( (D3DXVECTOR3*)pData, numVertices, fvfSize, ¢er, &m_boundingRadius );
        if ( FAILED( pD3DXMesh->UnlockVertexBuffer() ) )
        {
           //error
        }

}

RenderTerrain()
{

....
for(int i = 0; i < Mtrls.size(); i++)
		{
			if ( TheCamera.SphereInFrustum(¢er, m_boundingRadius ))
            {
			Device->SetMaterial( &Mtrls[i] );
			Device->SetTexture(0, Textures[i]);
			ancientsMesh->DrawSubset(i);
			}
			
		}

....
}
Is there a simple solution to this? such as breaking my big ancientsMesh into subsets within DirectX and using bounding spheres/checking on them? or do i need to break down the big .x file into smaller seperate ones and have many meshes? Look forward to your replies :). O and finally i will proberbly be doing something like BSP tree later on, right now im just trying to get some decent VFC working. Thanks, Chett

Share this post


Link to post
Share on other sites
If your main problem is with exporting from 3ds Max to .x file format, you could use the panda x exporter, which will export the submeshes in a hierarchal tree, which will be the same subsets that you have set in Max. Then you could use the class in the utilities of the sdk "CDXUTMeshFile", found ofcourse in "DXUTMesh.h" :), this class will load each subset as a single mesh linked together in the same hierarchal way that you've originally created in max. Then you can compute each submesh's bounding sphere with the same code that you have provided.

Hope this helps.

Atef Hashem

Share this post


Link to post
Share on other sites

This topic is 3731 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this