Question (or a lot of questions) about performance and optimisations

No need to ping me, I read all posts :slight_smile:
Reducing the materials save a lot using caching, it does not change the draw calls as draw calls depend only on the number of meshes.

merging is great:) What is your question then? Instances must be used every time an object is duplicated and need to be animated independently (like bullets)

1 Like

I’ve been playing with it a bit more and was eventually quite happy, the video below shows performance with 8 same rooms - it’s pretty good, a few hiccups here and there.

Now the video below shows performance with 30 rooms - unfortunately totally unplayable, but I believe there is definitely something I am doing wrong because:

  1. Draw calls is THE SAME as with 8 rooms, around 300.
  2. There are max 70 materials on at the same time
  3. There is around 1000 meshes, but only 100 active

The one that bugs me most, as you can see near the end, I switch to free camera and move out of the camera’s maxZ, so that the screen is eventually black, rendering nothing - still 30 fps.

I had the understanding that maxZ prevents rendering of stuff outside of the camera’s view?

Any help is greatly appreciated :frowning:

Have you tried profiling? It might hopefully lead you to something which you might be doing wrong in your code as well.

BTW, can’t wait to play your game. Looks awesome!

You mean in devtools?

Thanks! Hopefully it will come to that :confused:

Yes, it has certainly helped me a lot when trying to optimize performance. Another question, do you merge all the furniture in one mesh? Or do you merge them per room?

Per room, so they can be hidden based on player’s position.

What I have implemented in one of my games where I had a lot npcs in the same 500*500 map was some custom culling. What I did was I removed the mesh from the scene when out of frustrum and added them back when in frustrum. Helped me get a consistent 30 fps with over 2000 npcs in the map. Maybe this can help, worth trying anyway :slight_smile:

Not sure I can make anything out of the profiler, there is massive amounts of calls.

Mostly SubMesh.render and I believe I have at least 10000 submeshes?

Only detail that comes up is that GPU is mostly not used at all…

I thought that’s what camera.maxZ does?

Also what do you mean by removed the mesh from the scene, literally mesh.dispose() ?

Removing from scene? I don’t think it does that. No, I meant scene.removeMesh(mesh);. Adding back with scene.meshes.push(mesh). Checked frustrum with camera.isInFrustum(mesh)

1 Like

That sounds very interesting, thanks a lot mate! I am gonna try that right away.

1 Like

Oh, something which probably affects it. Since mine was a multiplayer game, I had positions coming from the server for the npcs. I had to manually compute the world matrix with mesh.computeWorldMatrix() when the mesh was not in the scene. Not sure how it affects you but just so you know :slight_smile:

I will not remove the players, just the static meshes, so all should be fine :slight_smile: It will probably affect bullets tho (you shoot at a wall, turn around, wall disappears, bullet moves through lol), but I wanna try it and and see if it helps the FPS.

I did not use it for static meshes. Instead I used LOD for static meshes. Use LOD - Babylon.js Documentation . Now that I think of it, I am not sure why I never did. Anyway, let me know if it helps.

That looks interesting as well, thanks.

Also, I saw you have animated robots. Not sure if you already do it, but, when out of view, stop the animations. Nobody sees it and it gets real expensive real quick in terms of fps.

Wait, how do you check that something is back in frustrum when it was removed from the scene?

The same function works for me. I don’t think it even cares whether the mesh is in the scene or not. All it does is check the bounding box.

Ok that helped a ton, standing still back to 60fps, but when moving around, it drops a lot. So definitely not rendering stuff when out of view is the key. Good call!

Occlusion Queries - Babylon.js Documentation looks like there is a built in method for this

Funnily enough, the occlusionType doesn’t really do anything :smiley: