- Home /
Why are multiple terrains slower?
In my attempt at procedural terrain generation, I'm forced to divide my world into many small terrains with 129x129 heightmap resolution each, because spawning larger terrains at runtime causes a noticable lag.
However, for some reason, having multiple small terrains seems to be a big hit on performance. In the example pictures below I compare a scene of 6x6 terrains with a scene of 12x12. Although the second gives only a slight increase in polygon count and draw calls, the fps is more than halved. Unless it's related to some kind of camera culling or similar, the reason must be that having multiple terrains causes an overhead by itself.
What's the reason for this overhead? Any ideas how I can improve the performance?
6x6 terrains: http://i.imgur.com/eKDMNv7.jpg
12x12 terrains: http://i.imgur.com/jan0JYn.jpg
Answer by BMayne · Dec 10, 2014 at 02:38 AM
Hey there,
(This might not be the prefect answer but it gives you a direction to look at)
It's not the amount of polygons that causes big performance issues it's the texture looks ups.
If your not fermiler with shaders a texture lookup is what it sounds like. Every time the shader has to look at a texture and read a pixel that has an over head (it has to do this for every pixel on screen).
Saying this I have a question. How many textures are you feeding your shader?
Regards,
Hi! Ahh, I didn't think about that! Thanks! I'm currently only using one and the same texture for all terrains, no normal maps or anything. I kind of assumed that the texture was re-used, but because there's no "material" used, I guess it isn't.
I'm currently setting the texture by this code:
SplatPrototype[] terrainSplats = new SplatPrototype[1];
terrainSplats[0] = new SplatPrototype();
terrainSplats[0].texture = terrainTexture;
terrainSplats[0].tileSize = new Vector2(3, 3);
terrainData.splatPrototypes = terrainSplats;
I'll look into improving this. $$anonymous$$aybe I can work with the "$$anonymous$$aterial" slot that's found in the terrain settings directly ins$$anonymous$$d, so that I can use the same $$anonymous$$aterial for all terrains and apply textures to the material ins$$anonymous$$d of the terrain.
But if I need more detailed texturing through splatmaps I guess there's no other way than to have unique textures for each terrain. I'm also planning to combine it with RTP terrain shaders from the Asset Store later, which will multiply the texture count by a lot.
Another solution would be to use fewer but bigger terrains, but then the main problem is that terrain.setHeights causes a lag and there's no way around that from what I've heard. Really hope Unity improves on that part.
After experimenting some more, I'm afraid this might not be related to texture lookups either. Even after I disable the above texturing code, which makes the terrains completely white without any texturing, I get the same frame rate. Reducing poly count does nothing for the frame rate either.
There just seems to be some strange performance overhead on using multiple built-in terrains that I can't get rid of. This is very unfortunate as it means I'll either have to sacrifice a lot of viewing distance or suffer from lag when generating larger terrain chunks procedurally.
Answer by CJGames · Dec 10, 2014 at 02:58 AM
Well, every type of generation is performed by your computer processor, if you generate 12x12 terrains, you'll have bigger terrains (but less), and if you generate 6x6 terrains, you'll have smaller terrains (and more). Maybe (for some reason) a single 12x12 terrain costs less memory than 2 6x6 terrains, so generating 12x12 terrains will make the game run "faster". However this depends on the USER processor, so if the player's processor is more powerfull than your's, the game will not lag (or will have less lag). I think there are some changes you can do to improve the performance, such as ajusting the shader and all shadows options (cuz they cause big performance impact) and making each terrain as big as possible.
Your answer
Follow this Question
Related Questions
Bizarre Terrain-Drawcalls inconsistency? 0 Answers
Terrain setdetaillayer performance 1 Answer
Overdraw problem, how to fix it? (Android) 0 Answers
Scripts on Terrain Trees 2 Answers
Performance - is raycasting for ground on Update() optimal? 1 Answer