TerrnBatcher: an in-game tool to boost terrain FPS

only_a_ptr

Infamous Developer
Administrator
Developer
Joined
Jan 31, 2018
Messages
169
Location
Prague, CZ
Ladies and gentlemen,
I'd like to introduce you to the TerrnBatcher, a script with the ability to reduce batch count (thus boosting FPS) in just a few clicks. Our maps have large FPS issues due to the fact we use hundreds low-poly meshes with hundreds of individual materials containing simple textures, and that makes graphics card & driver unhappy. GPU likes huge meshes covered by a single material with a complex texture. The TerrnBatcher satisfies this by merging meshes and materials into larger units.

How to get it: (UPDATED) The branch is now merged, so the script is included with itch devbuild, see https://forum.rigsofrods.org/threads/ror-development-builds-for-windows-and-linux.696/ for instructions.

How to start it: open console (Hotkey [`] as usual in games - or use Tools/Toggle console in top menubar) and type `loadscript example_ogre_terrnBatcher.as`.

How to use it: On the screenshot, you see the tool and a test terrain I created for it - there are just 3 meshes (1 material each) but they have various transforms applied (rotation in .tobj, scaling in .odef). The tool lists them all directly from OGRE's scene graph and user can pick which entities (instances of mesh) are to be merged. To find out which entity is which, you can use the [GOTO] button which moves rorbot to the object, or the '[x]Visible' checkbox which hides/shows the entity. When happy, press the [>>>BATCH<<<] button.
1709781241036.png


How it works: it hides the original separate meshes and generates a new, combined one. This change is done entirely in system memory, the terrain files on disk are untouched. The mesh generation is very fast and results are immediatelly visible on the FPS monitor panel - see the "Batch count". Beware that the 'chatbox' GUI info messages on bottom left also increase batch count - each visible message is 1 batch, and the TerrnBatcher tool logs many debug messages, so you may notice a sudden spike in BatchCount after you press the >>>BATCH<<< button, but it will get back to normal when the messages fade out. I recommend keeping the console window open while testing the tool, because that way the debug messages show there and not the chatbox.

Bugs and limitations: Merging materials isn't implemented yet, only merging meshes. This means everything will work OK when you batch together entities using the same material, but if you mix different materilals one of them will be ignored and the new geometry will use the other one. The tool also rejects materials which are more complicated than just one texture (diffuse).

What's the plan: Add the ability to set up a 'schedule' for making several batches. Let user save and load the schedule as file. Let modders attach the script & schedule to terrains so that it auto-optimizes for everyone on start. Possibly (if there is interest) I could code an export of the optimized meshes and materials, creating a compact ready-to-go optimized terrain for playing (not editable anymore though).

What can you do: Give the tool a try and tell me how it works for you. Report glitches and bugs you find. Tell me your results - how much FPS improvement did you archieve?

The test terrain: I've attached the terrain on screenshot. Note it comes in 2 files because I used it to also test the [AssetPacks] feature, see https://github.com/RigsOfRods/rigs-of-rods/pull/3129. If you omit the 'crazycones' ZIP, you will not have the funny cones.
 

Attachments

  • terrnbatcher_testmap.zip
    6.6 MB · Views: 28
  • testpack-crazycones.zip
    121.4 KB · Views: 18
Last edited:
1709799328139.png


I added the option to dump the generated meshes as regular .mesh files. The [dump] button only becomes visible if you check the "Enable dumping..." checkbox.
 
Back
Top