Dynamic Vegetation System

Jan 122017
 
twittergoogle_plusredditlinkedintumblrmail

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! :)

  20 Responses to “Dynamic Vegetation System”

  1. god all this and i remember when you were taking pictures of your lawn to slap in the game.. haha… such progress!!! :)

  2. 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!

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

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

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

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

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

  6. I love this kind of solutions.

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

  8. 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!

    • 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… :)

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

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

  10. 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?

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

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>