Performance questions

hi guys,



in my project i have to deal with a heavy and complex building model and i need to find some tricks to increase the performance.



here it is:





I’ve created a simpleGame class in order to do some tests on performance;



the model has 96000 Tris and 2100 Objs and without ANY kind of performance improvement it runs near 20 fps (considering the whole building inside the camera frustum);



then i tried to use the lock() method on the model spatial and it gained 30 fps. (50 total fps)



Here some (noob  :D) questions for you:


  1. i thought that backFace culling could reduce the number of tris to be rendered but when i enable it the fps number does not change. why?


  2. changing the display resolution seems not to affect the fps number. why?


  3. can you suggest me other methods in order to increase the performance?



    thanks in advance and sorry for the english :slight_smile:


You should use "level of distance". There is an automatic way that tries to reduce triangle count with an algorithm but theres also the cleaner way of defining separate models for certain distances. Look at AreaClodMesh for automatic and DiscreteLodNode/DistanceSwitchModel for separate models.

I guess the model is not animated and such? then you can lock() it. Take a look at the various lock() and lock*() methods in Spatial.



Considering your object count, especially lockBranch on your rootNode should give you a HUGE boost. Level of detail is not necessary at these triangle counts, its the object count (updating them, not the rendering) that keeps your fps down (answers 2.).



how do you apply backface culling? it should be like that:


CullState cs = createCullStateFromDisplaySystemRendererStuff ;-);
cs.setEnable(true);
cs.setFace(CullState.Face.Back);
rootNode.setRenderState(cs);
rootNode.updateRenderState();



excuse any spelling mistakes, the code is on the fly  :P

thanks for the help guys!



while i'm still working on "level of distance" method, i've tried the triks that dhdd suggested; unfortunately the "lockBranch()" method did not give the boost you expected  :(  (calling the lock() method AND the lockBranch() method has the same result (in terms of fps) of calling the lock() method alone).



i checked the cullState usage and it seems right; but still i don't see any changes neither in the fps number neither in the number of tris while it's active. is this right?



here's the code:


public class PerformanceTest extends SimpleGame
{
   Node modelNode;
   
   private ZBufferState zbufferState;
   private CullState cullState;
   
   protected void simpleInitGame()
   {   
      zbufferState = display.getRenderer().createZBufferState();
      zbufferState.setEnabled(true);
      zbufferState.setFunction(TestFunction.LessThanOrEqualTo);
      rootNode.setRenderState(zbufferState);
      rootNode.updateRenderState();
      
      cullState = display.getRenderer().createCullState();
      cullState.setEnabled(true);
      cullState.setCullFace(CullState.Face.Back);
      rootNode.setRenderState(cullState);
      rootNode.updateRenderState();

      modelNode = (Node)ModelLoader.load3ds("C:/Users/Simo/Desktop/NuoviTest/U14_prova_rotated.3DS",null);
      modelNode.setName("model_node");
      modelNode.setLocalScale(0.01f);
      modelNode.setModelBound(new BoundingBox());
      modelNode.updateModelBound();   
      modelNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
      
      rootNode.attachChild(modelNode);
      
      modelNode.lock();
      modelNode.lockBranch();

   }
   
   public static void main(String[]asd)
   {
      PerformanceTest perfTest = new PerformanceTest();
      perfTest.setConfigShowMode(ConfigShowMode.AlwaysShow);
      perfTest.start();
   }
}



and here is the data:


Maybe the problem is the materials… I had some issues when importing models that have transparent windows or something like that… Maybe some of the models material properties are converted into something very comutation intensive on the jme side.

2100 Objs

Your problem is here. More meshes means less performance, especially on modern video cards. Merge all of these into several meshes in your modeling tool, there's no reason you would need that many if you're only using 5 textures.

i'm afraid but i can't, cause in my application i need to RayPick every component (like window, walls…etc) separately  :frowning:



anyway, i still don't get the backface culling function; shouldn't i expect to see the Avg.Tris value falling drastically when i activate it? (since more or less half of the triangles are backfaces)


sbtyreal said:

i'm afraid but i can't, cause in my application i need to RayPick every component (like window, walls..etc) separately  :(

You can merge all meshes, then determine, based on the triangle index, to which mesh it originally belonged. Why don't you try merging the meshes, and see what it does to performance? Then you'll know for sure where the problem is.

anyway, i still don't get the backface culling function; shouldn't i expect to see the Avg.Tris value falling drastically when i activate it? (since more or less half of the triangles are backfaces)

Your video card is more than capable handling that many triangles, so the issue isn't there. The bottleneck is due to the video card having to restart for each mesh you're trying to draw.