• Advertisement
Sign in to follow this  

Slow rendering speeds - what's up wit dat?

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

When I render my scene I get a decent FPS rate. As soon as I start placing buildings (it's a simcity type game) my rendering speeds drop dramatically. I am rendering a .x file that I created myself, and it contains 438 vertices and 800 faces. For each building that I render, my fps drops by something like 10-15, which seems like a LOT. Is this a problem with my rendring code, or is it that the .x file is too complex? BTW I am on a mobile Radeon X300.

Share this post


Link to post
Share on other sites
Advertisement
What is your frame rate dropping to and from? If you're losing 10FPS at 1000FPS, it's not a problem. If you're losing 10FPS at 60FPS, it's a much bigger problem.

Whatdoes your scene contain apart from buildings? If you're just calling BeginScene() then EndScene(), then losing 10FPS isn't a big deal at all.

How many DrawSubset() or DrawPrimitive() calls are you making per building? Any chance of seeing your building rendering code?

Share this post


Link to post
Share on other sites
The FPS is around 120 FPS. I appreciate your help, I would be glad to show you my rendering code. If you go to my site www.piebert.com, you can see somewhat what is being rendered (several blocks to compose a level)


int gameclass::rendermodel(model mod,float x=0,float y=0,float z=0, float rx=0, float ry=0, float rz=0,float sc=0, bool tr=false)
{
D3DXMATRIX matWorld,matTrans;

D3DXMatrixTransformation( &matTrans,NULL,NULL,NULL,NULL,NULL,
&D3DXVECTOR3(x,y,z));

D3DXMatrixRotationYawPitchRoll(&matWorld,(float)rad(ry),(float)rad(rx),(float)rad(rz));

D3DXMatrixMultiply( &matWorld, &matWorld, &matTrans );

D3DXMatrixScaling( &matTrans,sc,sc,sc);
D3DXMatrixMultiply( &matWorld, &matWorld, &matTrans );

d3ddevice->SetTransform( D3DTS_WORLD, &matWorld );


//d3ddevice->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL );


for( DWORD i=0; i<mod.num; i++ )
{
//Set the material and texture for this subset
D3DMATERIAL9 m = mod.materials;
//if (infront)
D3DCOLORVALUE c;

c.r =mod.materials.Diffuse.r;
c.g=mod.materials.Diffuse.g;
c.b=mod.materials.Diffuse.b;

if (tr==1) c.a= .5; else c.a=1;

m.Diffuse=c;

c.r =mod.materials.Ambient.r+.02;
c.g=mod.materials.Ambient.g+.02;
c.b=mod.materials.Ambient.b+.02;

if (tr==1) c.a= .5; else c.a=1;
/* c.r =1;
c.g=1;
c.b=1;
*/

m.Ambient=c;

c.r =mod.materials.Specular.r;
c.g=mod.materials.Specular.g;
c.b=mod.materials.Specular.b;
if (tr==1) c.a= .5; else c.a=1;
m.Specular=c;


//d3ddevice->SetMaterial( &mod.materials );
d3ddevice->SetMaterial( &m);
// d3ddevice->SetTexture( 0, mod.textures );
if (tr==1) d3ddevice->SetTextureStageState(0,D3DTSS_ALPHAOP,.5);
//Draw the mesh subset
mod.mesh->DrawSubset( i );
}
if (tr==1) d3ddevice->SetTextureStageState(0,D3DTSS_ALPHAOP,1);
return 0;
}


Share this post


Link to post
Share on other sites
I can only advise that you look into rendering using DrawIndexedPrimitive() TRIANGLE_STRIPS. Until i did this i found i wasn't getting great throughput. Now get 80,000,000 tris per second ish.

Dave

Share this post


Link to post
Share on other sites
Is each cuboid a different model? How many subsets does each building have?

Another thing you could try is PIX, that'll give you a lot more information about why it's going so slowly.

EDIT: You shouldn't be calling Draw[Indexed]Primitive() and/or DrawSubset() more than 300-500 times a frame. Any more than that is going to give you some pretty big performace problems.

Share this post


Link to post
Share on other sites
Profile-profile-PROFILE [smile]

As Steve pointed out - frames per second is not always a good measure (frame time is a better choice), and without more hard facts it's still going to be largely guess work.

Not only that, but without those hard facts it'll be extremely difficult to tell if any changes you make have actually had a positive impact. A few times I've managed to "optimize" something and it ended up running slightly slower despite my thinking it was a very clever change.

I would highly recommend getting familiar with some PIX tracing (possibly using my little utility class).

hth
Jack

Share this post


Link to post
Share on other sites
This is what I use to load in a model.
I will have to look at how to do draw indexed triangle strips. I thought that you had to use drawsubset with loaded in model data. Do I need to sort it in some way so that i can make that call?


So how could I optimize this? Is there some way I can sort the data to make less calls?


int gameclass::createmesh(model &mod, char *file)
{
LPD3DXBUFFER pD3DXMtrlBuffer;

if( FAILED( D3DXLoadMeshFromX( file, D3DXMESH_SYSTEMMEM,
d3ddevice, NULL,
&pD3DXMtrlBuffer,NULL, &mod.num,
&mod.mesh)))
{
return 1;
}

D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
mod.materials = new D3DMATERIAL9[mod.num];
mod.textures = new LPDIRECT3DTEXTURE9[mod.num];
_chdir("textures");
for( DWORD i=0; i<mod.num; i++ )
{
mod.materials = d3dxMaterials.MatD3D;

//mod.materials.Ambient = mod.materials.Diffuse;

if( FAILED( D3DXCreateTextureFromFile( d3ddevice,
d3dxMaterials.pTextureFilename,
&mod.textures ) ) )
{
mod.textures = NULL;
}
}


pD3DXMtrlBuffer->Release();

D3DXComputeNormals(mod.mesh,NULL);

DWORD *pAdj=new DWORD[mod.mesh->GetNumFaces()*3];


mod.mesh->GenerateAdjacency(0.0f,pAdj);


mod.mesh->OptimizeInplace(D3DXMESHOPT_COMPACT || D3DXMESHOPT_ATTRSORT ||
D3DXMESHOPT_STRIPREORDER,pAdj,NULL,NULL,NULL);


D3DXCleanMesh(
mod.mesh,
pAdj,
&mod.mesh,
pAdj,
NULL);
/*

D3DXSimplifyMesh(mod.mesh,
pAdj,
NULL,
NULL,
(mod.mesh->GetNumVertices()/5)*4,
D3DXMESHSIMP_FACE,
&mod.mesh);
*/

delete pAdj;
_chdir("..");
return 0;
}

Share this post


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

  • Advertisement