<p>Hello and welcome Jonek2208! </p>

<p>Unity specific questions probably are better suited for the <a href="https://forum.unity.com/categories/graphics.75/" rel="nofollow noreferrer">Unity Graphics Forum</a>. However, I'll try to give you an answer as I do have some experience with the engine.</p>

<p>In my opinion, the only way of knowing for sure which method is the best would be to implement both and profile them on your target device. Do not fool yourself in thinking that some basic algorithmic analysis is all you need to do. Always profile and compare your solutions, no matter the circumstances.</p>

<p>One thing I can do is to tell you the trade-offs between the two methods, and also provide a hint at another possible solution. Let's go!</p>

<p>When using the built-in rendering pipeline, Unity batches objects by materials. A batch is considered to be a change in GPU state followed by one or more draw calls. In other words, if you have four materials, you increase the number of batches when compared to having just one. </p>

<p>If you are targeting mobile devices, reducing the batch count is one of the keys for achieving good performance, and most mobile developers would choose to use a single material. On the other hand, duplicating vertices incurs a cost in memory, and hence you get better batching at the expense of using more memory. If you are targeting consoles or PCs, you can have a much higher batch count and memory budget, so the solution that you think is simpler to implement, expand, and maintain should be your best bet.</p>

<p>Another solution would be to use textures instead of vertex colors. For this, you would need to compute the uv-map procedurally when generating the vertices. You could place all textures into an atlas and try to use a single material. This is the usual solution for mobile. If you are targeting PCs/consoles, you could even afford procedural textures in your fragment shader.</p>

<p>If you are using the latest version of Unity, you can use the SRP Batcher, which batches per shader instead of per material. Hence, you can use 4 materials, but have a single batch if all of them use the same shader. Note some devices may not have this capability, especially on mobile.</p>

<p>All in all, there are a lot of things to consider in any kind of application. That is why I started talking about profiling on your target device. Honestly, it is the only way of knowing for sure which method is the best. You should build a test scene with thousands of generated meshes and then profile each method. Select the one that fits best in your budget (FPS/memory/etc) and the long-term goals of your project.</p>

<p>Good luck! :)</p>

CC BY-SA 4.0
2019-09-09T04:30:00.433Z
2019-09-09T04:30:00.433Z
vgs
<p>I am making ski jumping game (in Unity) with procedurally generated hill mesh. I want to add lines on hill like this (mesh is created by script, but I've manually assigned materials in Blender) <a href="https://i.sstatic.net/g502s.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/g502s.png" alt="enter image description here"></a></p>

<p>Because this is procedurally generated (on runtime) (hills can have different sizes) I cannot bake texture in Blender. Mesh for large hill has around 800 vertices. There is my question - is it better to duplicate vertices and then use one material or use four different materials without duplicating vertices?
<a href="https://i.sstatic.net/k0CJH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/k0CJH.png" alt="enter image description here"></a></p>

<3d><mesh><unity>
What is performance better - add four materials to mesh or duplicate every vertex and use packed texture?
Jonek2208
# What is performance better - add four materials to mesh or duplicate every vertex and use packed texture?

(Asked by: username_0 on 2019-09-07)

I am making ski jumping game (in Unity) with procedurally generated hill mesh. I want to add lines on hill like this (mesh is created by script, but I've manually assigned materials in Blender) [![enter image description here](https://i.sstatic.net/g502s.png)](https://i.sstatic.net/g502s.png)

Because this is procedurally generated (on runtime) (hills can have different sizes) I cannot bake texture in Blender. Mesh for large hill has around 800 vertices. There is my question - is it better to duplicate vertices and then use one material or use four different materials without duplicating vertices?
[![enter image description here](https://i.sstatic.net/k0CJH.png)](https://i.sstatic.net/k0CJH.png)

**Tags:** 3d, mesh, unity


---

## 1 answers

### Answer by username_1 on 2019-09-09. Score: 1

Hello and welcome username_0!

Unity specific questions probably are better suited for the [Unity Graphics Forum](https://forum.unity.com/categories/graphics.75/). However, I'll try to give you an answer as I do have some experience with the engine.

In my opinion, the only way of knowing for sure which method is the best would be to implement both and profile them on your target device. Do not fool yourself in thinking that some basic algorithmic analysis is all you need to do. Always profile and compare your solutions, no matter the circumstances.

One thing I can do is to tell you the trade-offs between the two methods, and also provide a hint at another possible solution. Let's go!

When using the built-in rendering pipeline, Unity batches objects by materials. A batch is considered to be a change in GPU state followed by one or more draw calls. In other words, if you have four materials, you increase the number of batches when compared to having just one.

If you are targeting mobile devices, reducing the batch count is one of the keys for achieving good performance, and most mobile developers would choose to use a single material. On the other hand, duplicating vertices incurs a cost in memory, and hence you get better batching at the expense of using more memory. If you are targeting consoles or PCs, you can have a much higher batch count and memory budget, so the solution that you think is simpler to implement, expand, and maintain should be your best bet.

Another solution would be to use textures instead of vertex colors. For this, you would need to compute the uv-map procedurally when generating the vertices. You could place all textures into an atlas and try to use a single material. This is the usual solution for mobile. If you are targeting PCs/consoles, you could even afford procedural textures in your fragment shader.

If you are using the latest version of Unity, you can use the SRP Batcher, which batches per shader instead of per material. Hence, you can use 4 materials, but have a single batch if all of them use the same shader. Note some devices may not have this capability, especially on mobile.

All in all, there are a lot of things to consider in any kind of application. That is why I started talking about profiling on your target device. Honestly, it is the only way of knowing for sure which method is the best. You should build a test scene with thousands of generated meshes and then profile each method. Select the one that fits best in your budget (FPS/memory/etc) and the long-term goals of your project.

Good luck! :)


---

