Dynamic Vegetation System
Hi guys! Paul and Cyrille join me to wish you all a Happy New Year! 🙂
This update is going to be essentially a technical one (it’s been a while I haven’t done any of those). I received many questions regarding the new vegetation system in Ghost of a Tale, which was introduced in the latest build. So I will now attempt to answer them.
Caveat Emptor: this technique is used on PC and Xbox One/PS4 (I haven’t applied it to any other platform yet).
(Also: yes, the game is running on Unity 🙂 )
The reason why I developed this system is because I don’t like it when I see vegetation behaving like the vertex are warping and stretching unnaturally around a sphere or capsule shape (even in AAA games). If I were a shader wizard maybe I would have come up with a super smart shader that would give me what I need, alas I’m not. So I had to find another way… 🙂
The main idea is what happens around Tilo should be high quality while the rest should stay as cheap as possible (nothing new here).
In this example the fern objects are made of two models:
- A static one (a simple mesh with usual LODs)
- A dynamic one (same model as LOD0 but the stems are skinned to a couple of joints). Technically each stem only uses 2 bones (the end one is not part of the skinning).
The dynamic models are deactivated by default, leaving only the cheap static ferns visible. No script is running in the background so there’s no overhead.
The root game object has a simple static box collider trigger. When Tilo enters the trigger that’s the signal that we should switch to the dynamic model.
Since the static and dynamic models have the same pivot point it means the wind animation (vegetation shader) is exactly the same on both meshes. So there is no visual pop whatsoever when switching between the models.
The dynamic model has a kind of “fake physics” (using this great asset) which acts as colliders on the stems’ joints. Those colliders collide with the actors’ limbs (head, chest, waist, etc…). Note: In this case I reuse the actor’s colliders from the game’s dynamic props system, so there’s no additional colliders to create (always reuse whenever possible!).
What this gives me is more accurate detection in that if a character plays an idle animation while remaining in contact with the fern, the stems will still react fairly precisely. In other words this is not a simple “capsule” avoidance.
So when Tilo is within the trigger the fern’s dynamic (skinned) model is visible, but when Tilo leaves the trigger then after a second or so -long enough for the fern to settle down- we switch back to the cheap static model.
Again, there is absolutely no visible pop during the change because the “rested” dynamic model and the static one have perfectly matching vertices positions.
There is a couple more details to keep in mind: I use a special vegetation shader (written by shader wizard Larsbertram) that produces translucency but uses the deferred rendering path (whereas normally you would have to use a slower forward rendering path).
A second important point is that I don’t use OnTriggerStay in the trigger detection process. I only use OntriggerEnter and OnTriggerExit. The reason is OnTriggerStay can prove quite heavy (depending on your physics matrix) and we don’t really need it. All we need is to be notified when Tilo enters and leaves the trigger.
There is also the tricky case where Tilo would have left the trigger (for whatever reason) without calling OnTriggerExit. Which is a fairly rare situation but it could happen. To remedy this case I use an Update function on the vegetation bend behavior script which tests from time to time (every couple of seconds) if the distance between the actor and itself (in this case the fern) is greater than a certain threshold. If it is then we know for sure we should switch back to the static model.
Of course that component only becomes active while Tilo is within the trigger. And it ensures we don’t accidentally leave some vegetation items in “high-quality” mode.
That’s it for this update! I will keep converting a lot of the game’s vegetation over the next build updates but some assets will remain “dynamic-but-rigid” (meaning non-skinned/rotation only) as they don’t require as much detail.
I hope this answered any questions you guys might have had regarding this topic, and I genuinely hope it didn’t bore you to tears. See you in the next update! 🙂
evilkinggumbyJanuary 12, 2017 at 3:21 pm
god all this and i remember when you were taking pictures of your lawn to slap in the game.. haha… such progress!!! 🙂
SeithJanuary 13, 2017 at 12:06 pm
Hehe. A long time ago it was… 🙂
Glotz EulorJanuary 12, 2017 at 3:48 pm
Very nice technical blogpost,
always nice to read how other developers handle technical difficulties.
Sometimes it feels like steping from struggle to struggle, but after solving an issue its such a good feeling (and you can write a blogpost with ease) 😀
Keep up the good work, looking up for every new beta and of course the final release!
SeithJanuary 13, 2017 at 12:07 pm
Thanks for your support! I’m glad you liked this tech update.
John PorterJanuary 12, 2017 at 4:56 pm
Would using an actual
LODGroup to control the transition between static/dynamic be better than using triggers?
SeithJanuary 13, 2017 at 12:15 pm
It’s a good idea but it wouldn’t work for a couple of reasons:
– LODs work based on either distance to camera or size on screen. But in this case the distance to Tilo is what counts; the camera could be very close or far away (conversely the vegetation items could be small or big on the screen).
– It wouldn’t be precise enough: potentially ALL of the fern objects around the camera (or of a certain size on-screen) would be switched to dynamic models, which is definitely not what we want.
EvanJanuary 12, 2017 at 5:49 pm
What. The. Heck. You’re somewhat of a perfectionist, and I commend you for that.
Not only did I enjoy many of the underlying elements of the game already, but you’ve continued to improve in the smallest, often over-looked elements. I replay the entire alpha-release every time there’s an update.
SeithJanuary 13, 2017 at 12:17 pm
Thank you Evan. Well in this case I really wasn’t happy about rigid/non-dynamic vegetation so I kept thinking about the issue for a while but the actual implementation took only a couple of hours. 🙂
luckyJanuary 12, 2017 at 8:51 pm
Amazing, thanks for sharing a bit of your science Seith!
SeithJanuary 13, 2017 at 12:18 pm
You’re most welcome! I’m glad I could put it out there for other devs as food for thoughts.
SinglePixelJanuary 13, 2017 at 12:34 am
I love this kind of solutions.
SeithJanuary 13, 2017 at 12:19 pm
Xbob42January 13, 2017 at 5:04 pm
Nice! I actually noticed the capsule effect in the Witcher 3 the other day and wasn’t sure why they did it like that, as I’d seen it before. Your solution produces a vastly superior reaction from the foliage, I love it!
SeithJanuary 14, 2017 at 9:45 pm
Thanks! Technically shader solutions perform faster. But they don’t give as much control on collision and recoil. Glad you like it!
PhilsipJanuary 14, 2017 at 3:03 am
I actually don’t think I’ve ever seen a game with this level of detail to its foliage collision. Most people just slap a capsule in there and call it a day.
Especially when Tilo is crawling and actually treads some of the fronds under his feet. Just great. And not a serious performance issue either because of intelligent coding!
Hats off to you, sir!
SeithJanuary 15, 2017 at 8:54 am
Thank you Philsip! Well Naughty Dog did a nice job with that on Uncharted 4. Then again they have dozens of geniuses forking on their games, so that helps… 🙂
Lee HendersonJanuary 15, 2017 at 8:43 am
I wish i had the slightest of a smidgeon of knowledge on how to make games so i could offer you my services. Even animating some leaves. I could say to people “Hey, you know that fern you just passed through. That was me that was”.
Unfortunately im at the technical equivalent of a neanderthal shouting at the magic of a fire just been lit. I keep watching the videos though and i’m following on Facebook. If i had a PC that could play it i would, but it’s a lowly Xbox One for me.
SeithJanuary 15, 2017 at 1:36 pm
Well, there are days where I probably look like a monkey banging on a keyboard. Thankfully I work at home.
And take heart, the Xbox One version should look (95%) the same as PC!
Michael SmithJanuary 20, 2017 at 2:23 pm
It’s a really cool update. I love how intractable the plant life is even if you’re just walking on them, even when you consider when games I also love, like Skyrim, are set where you just walk through any non-collidable plant life without fazing it in the slightest.
I just have one question. If it only switches when Tilo is near it, does that mean it will remain static or whatever when an NPC or enemy is near it. If so how would that look?
SeithJanuary 21, 2017 at 8:30 am
Very good question! Other actors can interact with the plants but then it’s a matter of being close enough to the camera. In other words the dynamics effect is only active if the NPCs are within a certain distance threshold.
That distance threshold will be an option in the game (similar to the current “Dynamics Distance” slider).
HugoFebruary 24, 2017 at 3:38 pm
Hi, I’m really looking forward to this game. But please add the Brazilian Portuguese language in the audio or at least in the subtitles. Also I would like to know if there is any news about the version of xbox one, or about a preview for this console. Many thanks and sorry for my bad english!
AmauryNovember 30, 2020 at 10:36 pm
Thanks for the great article !
The link to the asset store is dead, could someone update it or just name the asset so that we could find it again ?
Thanks in advance.