fbpx
Loader image
Loader image
Back to Top
 

Blog

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 SYSTEM:

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).

screen-shot-01-07-17-at-10-58-am-001

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.

screen-shot-01-07-17-at-11-02-am

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.

screen-shot-01-07-17-at-11-04-am

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.

screen-shot-01-07-17-at-11-06-am

Again, there is absolutely no visible pop during the change because the “rested” dynamic model and the static one have perfectly matching vertices positions.

NOTES:

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! 🙂

Seith
Seith

22 Comments

  • blank
    evilkinggumby
    January 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!!! 🙂

  • blank
    Glotz Eulor
    January 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!

  • blank
    John Porter
    January 12, 2017 at 4:56 pm

    Would using an actual
    LODGroup to control the transition between static/dynamic be better than using triggers?

  • blank
    Evan
    January 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.

  • blank
    lucky
    January 12, 2017 at 8:51 pm

    Amazing, thanks for sharing a bit of your science Seith!

  • blank
    SinglePixel
    January 13, 2017 at 12:34 am

    I love this kind of solutions.

  • blank
    Xbob42
    January 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!

  • blank
    Philsip
    January 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!

  • blank
    Lee Henderson
    January 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.

  • blank
    Michael Smith
    January 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?

  • blank
    Hugo
    February 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!

  • blank
    Amaury
    November 30, 2020 at 10:36 pm

    Hello,
    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.

Add Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

GDC 2017