I’ve successfully implemented my own runtime texture painter. At the first test it works as desired but when it comes to more frequent texture painting, there is a unacceptable drop in framerate. After running profiler, I can see that the main bottle neck is the SetAlphamaps method. In the test there were just 3 objects in the scene (while the game can have up to 20) but SetAlphamaps consumes about 5-6 ms per single frame.
I thought of breaking the SetAlphamaps into pieces and use coroutine by updating a pixel in each frame (there are just about 12x12 pixels to be painted at a time). This time the performance dropped even much more, with just 1 object (with much lower shooting rate) but the framerate dropped to just 15 fps. The Camera.Render somehow takes part in that lag and the SetAlphamaps is even much worse consuming up to about 35 ms per single frame.
I don’t have any clue on how to reduce the SetAlphamaps cost. It seems to be the only way to paint the terrain texture. It looks like atomic and not very friendly with coroutine. Have anyone here experienced with fast terrain texture painting problem and could give me some suggestion to solve this? I could reduce the size of terrain block more (currently it’s 5x5 in world space) to save more framerate but of course that won’t create very good effect. Anyway the current performance is not acceptable at all even after reducing the size. Thank you all for your help.
6 years later, same problem. SetAlphamaps is too expensive. Applying the method to 1 texel takes me about 7ms. I’m shocked that changing just 1 texel results in such a huge load.
I need to color 9 texels per frame. In total there are 9 calls to SetAlphamaps and about 60 ms. I can combine all 9 changes into 1 array and call SetAlphamaps 1 time, but not always. I use multiple terrains, so if the painting area falls on the seam between two or four terrains, I will have to call two or four SetAlphamaps methods. It may happen that there will be several editing areas in 1 frame, and they all fall on the seam between terrains.
Is there a better performing alternative to the SetAlphamaps method?
I’m currently struggling with the same issue.
Building a game where I occasionally need to alter the splatmap of a terrain to draw roads or patches of grass.
And whenever I execute SetAlphamaps(), and pass the new alphamap float array to the terrain, it takes a huge toll on the frame rate, and there is noticeable stutter, even though the game otherwise runs at a constant 90 frames per second.
From what I’ve heard, there is still no cheaper replacement or workaround for SetAlphamaps(), and the function should not be called more than once per second.
But what I also heard is that you can apparently pass partial splatmaps to the function, meaning only the areas that were actually changed, and supposedly that increases performance quite a bit.
So if anybody could share exactly how that is done, I’d be more than grateful, and so would a lot of other people.
Have a terrain made up of many tiles. Try to reduce the resolution of the splatmaps as much as possible. So that even if the edit zone falls on the junction of 4 adjacent terrains, so that the performance remains acceptable. You will also have to write the code for sewing the seams yourself, because the built-in TerrainPaintUtility function is undocumented garbage that no one knows how to use. I also installed MicroSplat core module and used the “Custom splatmaps” function, which allowed me to have direct control over the splatmaps: edit, save and load as I please. It was a long time ago, so I don’t remember much.