Can someone explain to me the purpose of mesh batching and when to use it?

In my game I have a static, and purely aesthetic forest outside of my main play area. So if I use mesh batching for those trees, it would increase performance by joining all those trees into a singular object?

Also, how could I use LODs that I made for the individual trees if the game joins them together?

Would joining all the trees into a single object be better than having them separate to start with? Then again, what would the purpose in having LODs be?

Hey again Leanardoe,

Here’s a great demonstration by ThaTimst3r (credits to ThaTimst3r) for using LOD in the bge.

A basic analysis for using mesh batching with LODs is like so:

Having LOD in the bge will increase rendering/scene performance for objects that are rendered with less detail when necessary. If you mesh batch several objects, then as you approach any part of that object, the entire group will be rendered with less detail (unless you have other ways of making LOD such as rendering parts of the mesh, which would likely defeat the purpose of mesh batching).

One main drawback for mesh batching could be how the mesh(es) look (visual appeal). For example, if instead you used a bunch of smaller objects as opposed to mesh batching, each individual mesh would be evaluated with LOD, and even though you could have a drop in render performance, the visuals could look more appealing due to a high degree of detail on farther objects.

Another thing to consider for mesh batching:
Your player constantly views the background at a distance. If you use mesh batching, then the entire mesh would constantly be rendered (instead of just some small part of it) in a high LOD, decreasing render performance. But if your player constantly views the background close up, the player triggers LOD for the entire background, instead of just a fraction of objects, which would theoretically bring performance up.

This is just a simple analysis (without CPU time calculations, etc.) that would still be good to keep in mind.

P.S. Your game on indiedb looks pretty cool. Looks like a survival/horror.

I understand LODs, but not mesh batching. I’m just trying to figure out whether or not mesh batching would be good for this scenario. My current understanding is that LODs cannot be used with mesh batching effectively without a complex system. So would it be worth not using LODs, and instead batching the high detail meshes together? Would that yield a better performance compared to LODs on each individual tree?

Simply, would it be worth using mesh batching on 50-100 trees? Or would fine tuning my current system of LODs work better?

I’ve only seen one demonstration of a system that uses LODs and mesh batching, but the system is very complicated. Here’s the video:

Hi,

My current understanding is that LODs cannot be used with mesh batching effectively without a complex system.

You raise a good point. Unless you have a complex system in place as you suggest, it would be better to not utilize mesh batching with LOD for performance purposes. It is because, as I have outlined, your player could constantly be viewing the mesh batch at a distance and not triggering the LOD calculations, but rather triggering rendering for the entire batch as opposed to small, individual trees for your case (which would take less time to render in comparison).

So would it be worth not using LODs, and instead batching the high detail meshes together? Would that yield a better performance compared to LODs on each individual tree?

For your question, “would that yield a better performance”: there is no yes/no answer. You have to consider a number of things, including how your trees are modelled, how they are positioned, how much LOD you are putting in, etc.
What I can tell you though is LOD is ideal for big objects (like mesh batched objects) for processing time. If you have a small number of objects, LOD will mostly take longer than for one big object filling the space of those small objects.

Simply, would it be worth using mesh batching on 50-100 trees? Or would fine tuning my current system of LODs work better?

If you get near the trees often, try mesh batching to reduce draw calls, and keeping LOD. If you are constantly viewing the objects at a distance, try just leaving out both LOD and mesh batching altogether. For the latter consideration, if your trees are complex, use mesh batching.

https://docs.blender.org/manual/en/dev/game_engine/settings/object.html

By the way, when I say ‘mesh batching’, I am referring to ‘joining/merging objects together.’

There’s a mix of the two. There are some trees that are at a distance, but some that are right next to a window, and the player can get close to them. Do you think it’d be best to have a few separate batches? Perhaps for the distant trees, and have the closer trees set to a higher detail, then utilize the LODs?

For your question, “would that yield a better performance”: there is no yes/no answer. You have to consider a number of things, including how your trees are modelled, how they are positioned, how much LOD you are putting in, etc.
What I can tell you though is LOD is ideal for big objects (like mesh batched objects) for processing time. If you have a small number of objects, LOD will mostly take longer than for one big object filling the space of those small objects.

So for complex objects, use LOD, but for an object that has many duplicates, use batching? Hmm. Well, what about when the player is in the forest? They could go right up to a tree, but be far away from another identical tree. Would batching be ideal here? Or could what I mention above still be good? I could even make LOD batches, such as one batch is low poly, and that is replaces with a batch that has a higher poly when the player is close.

If you get near the trees often, try mesh batching to reduce draw calls. If you are constantly viewing the objects at a distance, try just leaving both LOD and mesh batching altogether.

What do you mean by leaving them altogether? Batching the trees at a constant level of detail? Or not being batched at all?

There’s a mix of the two. There are some trees that are at a distance, but some that are right next to a window, and the player can get close to them. Do you think it’d be best to have a few separate batches? Perhaps for the distant trees, and have the closer trees set to a higher detail, then utilize the LODs?

With the detail you have provided me, yes to both questions. And as I don’t know the full layout of your game nor how you are implementing your LOD, I leave it to your discretion to decide what kinds of batches you should make and when you utilize LOD. Please refer to my posts on this thread for advice on when and how to use the batches/LOD.

So for complex objects, use LOD, but for an object that has many duplicates, use batching?

Sorry, I retract what I said about “LOD is ideal for big objects”, as I was erroneously thinking of occlusion culling instead of LOD. You raise a good point. I never said LOD is for complex objects, however. Use of LOD depends on what you want. It works for big and small objects. The question to ask is: “am I using LOD frequently enough/to my advantage in my game?” Basically, your concern is turning on LOD without having to use it, or unnecessary LOD calculations (such as for a batched mesh every time the player is looking at just one part of the mesh - a lot of calculations), which will bring performance down.

What do you mean by leaving them altogether? Batching the trees at a constant level of detail? Or not being batched at all?

Ah, you’re quick to reply - I edited the original to say “leaving out…”

Hope that helps. Please continue to ask if you need more advice.

Mesh batching feature of Upbge? If so, then it only works with static meshes no lods.

Okay, thanks.

Sorry, I retract what I said about “LOD is ideal for big objects”, as I was erroneously thinking of occlusion culling instead of LOD. You raise a good point. I never said LOD is for complex objects, however. Use of LOD depends on what you want. It works for big and small objects. The question to ask is: “am I using LOD frequently enough/to my advantage in my game?” Basically, your concern is turning on LOD without having to use it, or unnecessary LOD calculations (such as for a batched mesh every time the player is looking at just one part of the mesh - a lot of calculations), which will bring performance down.

Alright. I’ll experiment with it then raise mroe questions if I have some.

Ah, you’re quick to reply - I edited the original to say “leaving out…”

Ah, okay.

Hope that helps. Please continue to ask if you need more advice.

Thanks!

I originally assumed that the process of mesh batching would improve performance for vanilla, is that not the case? I will probably end up using upbge since I read that it has optimization for it, though.

Okay, thanks.

You’re welcome!

Additional resources for joining objects/LOD/general tips:

Edit for a previous post: What I meant to say for object/mesh batching for player viewing at a distance: Do use mesh batching. Sorry about that.

If you want info on how to mesh batch in Upbge, I have no idea. But this idea is for the regular bge.

Well Upbge have raster optimization, animations and etc… Also the lod is optimized too. Mesh batching is a feature of upbge, that allows you to batch static meshes in realtime. So you could merge(), split() and destroy(). Batching is basically joining objects and materials into one, so you get one draw call. The notes are here: https://doc.upbge.org/releases.php?id=0.1.4
But in the end everything depends of the number of objects, polys, lights, mat/textures, that are been rendered from the camera. Feel free to test UPBGE and report. :slight_smile:

Thanks for all the help!

So with those python calls, it might be possible to script a complex solution that isn’t available to vanilla? Do you think something similar to the above video could be achieved?

The batching, that have been implemented works the in the same principle as moerdn, but different code. Try this file: https://drive.google.com/open?id=0B6yNvVGWiWysM3NIbWpWdDVCY00
But yes. Its best to test.