Performance issue when changing terrain alpha maps.

Good day Unity3d!

So I’m trying to incorporate seasons into my game. Here is a very crude implementation that I have so far: http://pastebin.com/qaBSpg5S

So right now nothing fancy, I take my terrain and cover it all in either snow or grass. I’m not even doing height/slope testing to properly shift the textures which I suppose will add even more to the computation times.

There are two main problems I see with this implementation. The first one is the terrain goes from lush grass to dense snow in 200ms. I’m wondering if there is a way I could gradually blend both textures to make the snow kind of “build” on the terrain. I thought about getting my values, and slowly increment during update() or a coroutine then apply the maps until all values are at the desired range. While this would technically work the main problem is the lockup setAlphaMaps() creates.

My terrain is 1500 x 1500, there’s 1000 x 1000 that’s playable, the rest is simply to make the world more believable. Updating the splatmaps this way locks the execution for about half a second, it’s really abrupt. I can probably deal with that either just leaving the lag there or fading to black when switching seasons. But for a RTS I think fading to black will break the rythm of the game.

Now imagine if I want to slowly blend the textures it means I’ll need to call setAplhaMaps 20-30 times, the game will be unplayable during the transition so there’s no point. I tried reading online about ways to do this smoothly and without locking up the main thread. My initial thought was to call triggerWinter() from a different thread, great! Nope, I get get_Alpha_Maps can only be called from the main thread.

So that’s not possible, I found a package that looks super neat called UniStorm, it looks a bit overkill for what I want (especially since you never actually see the sky in my game) but they have dynamic snow. I believe they achieved this using a shader though. I unfortunately know nothing about shaders so I don’t even know what to search for.

Anyone is familliar on how to update/change the alphamaps on the terrain without locking the main thread?

Thanks a lot!

Ok I couldn’t find a reliable solution using the alphamaps on such a big terrain without fading to black and I find it breaks the rythm too much.

For anyone interested I ended up using ats-snow suite from the asset store. It’s free and apparently this is the shader that UniStorm uses. It’s extremely easy to setup and use. Here is my new seasonControl script: SeasonControl - Pastebin.com

Nothing much has changed except now I just set two booleans in the snowControl script (which is just the terrain script provided with ats)
Here is my version of the modified script, now I just increment or decrement the snow value directly from within update. larsbertram1's CustomTerrainScriptAtsV3Snow - Pastebin.com

Works great for the terrain! Now he also offers a script to get snow on the gameobject using a normalmap. My gameobjects can be selected and when they are they show an outline. So I combined his shader with an outline/bumped/diffuse shader I found on the unity forums earlier. Here is the shader that allows for a normal map, snow accumulation, and outline : TestSnowOutline Shader - Pastebin.com

I know nothing about shaders so this thing could probably be optimized alot!! So I now have extremely fluid season transitions!