0
$\begingroup$

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

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

$\endgroup$
1
$\begingroup$

Hello and welcome Jonek2208!

Unity specific questions probably are better suited for the Unity Graphics Forum. 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! :)

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.