Foliage collision + foliage bend on collision- In engine feature?

I’ve been going through the forums and documentation on my effort to make a decision on switching from Unity to UE4. My amateur project is young enough that switching wouldn’t be a huge hassle. So I decided that character models and animation transferring won’t be a problem (which was my first question).

Now my 2nd very important issue is foliage collision physics. In Unity, via a user generated tool from the asset store, I easily applied collision-bending to all my vegetation. It is very key to my game. On any plant, or mesh basically, I can adjust the degree of bend (resistance, bounciness) that occurs when an object hits it. Like painting a texture, just paint the least/most affected areas. Easy stuff.

It gives the world so much more life. To run through a field and see the grass bending around the character is such a significant enhancement to the experience.

Is foliage collision bending physics a built-in feature of UE4? I can’t find any tutorials. Just collision only. The meshes remain static. Nothing about bending grass, bushes, any mesh. If not a feature, are there plans for more lively vegetation in the near future?

(Vegetation bending physics is my 2nd of 3 key reasons for me to switch to UE4. First reason turned out great. 3rd is wind. But that comes after grass :slight_smile:

EDIT: I guess more accurately, I’m asking about a grass bending shader - like wind shaders. Not an expensive renderer for each blade or branch. A shader that bends foliage (like a quick small punch of wind) when a character collides with it. Like the character’s mesh has a breeze and makes foliage react on direct contact. It is cheap on GPU because Unity does it with the shader I linked below in followup post.

I too, would very much like to hear something about his.

Nothing like this exists right now. If you have the source code to the Unity plug-in that allows it, you could probably port it, or find someone who could?

Surely such a thing is hideously expensive though? Unless it’s using some shader magic and not actually calculating ‘real’ collisions.

Wind does indeed exist, but once again it’s done in the shader :slight_smile: I’m almost certain this would be possible but it wouldn’t be ‘accurate’ so to speak, do you have any videos of the Unity plugin working?

Of course I don’t mean it’s as accurate as a server farm at Pixar calculating each a million blades of grass :slight_smile: But it is certainly a very good enough touch bending effect. The grass simply bends as an object collides, like a wind shader is hitting it. Surely touch bending can be applied to grass easily.

It is a simple affect that weak hardware like last gen consoles can do. As if a mini pocket of wind is punching the foliage. That is how the effect looks. It is not like a Cinema 4D rendering. Still cheap shader trickery. The grass bends like wind shader is hitting it, but it still works. Only the hit portion of the plant is affected too. It really works well in dense fields. The problem is it’s limited by Unity’s horsepower. UE4 imagery with this simple shader would be glorious.

But I’m sad if it doesn’t exist in UE4. Of course I know I shouldn’t beg for it, being an amateur relying on GUI-based game making. Seeing a field of grass waving in the wind is beautiful in UE4, but then seeing my character run through it, the grass passing through his body and not bending at all, it affects the experience. It is something from gaming generations past.

Here is the foliage bending shader forum discussion. I want something like this for UE4 because UE4 simply would do it better with more horsepower and eye candy.
There might be videos somewhere.
There is an online demo if you have free Unity.

http://forum.unity3d.com/threads/133398-Advanced-foliage-shader-released

You should have a look at Parameter Collections.

Thanks for that link. I wouldn’t have found that documentation with all the search terms I was trying. Truly appreciate it. I feel good knowing I’ve taken a step in the right direction.

Sadly, that page doesn’t explain how **MaterialParameterCollection **uses the collected parameters to make the grass move away from the player.

I understand that the global position of the player is being fed to a shader on the foliage, and then the foliage reacts accordingly. At the same time, I do not understand it. Specifically, I don’t understand how or why the problem is solved using global data. Why (and how) is this a global parameters problem?

My confusion arises from my mental image of the problem: I see it as an issue between the character model and the foliage. And I see the solution as being between the model and the foliage. For example, simply have a wind-like shader on the foliage that reacts to contact with the player/any rigid mesh model collision. The wind effect area would only be a very small area surrounding the player model.

I can’t grasp the concept of a global parameter taking care of what seems to be a very “local” problem. I don’t understand how I would set up the **MaterialParameterCollection **to make a certain shader on the all the game world’s foliage bend away from the player. Is it the wind shader briefly blowing the grass away from the player?

Is it: The **MaterialParameterCollection **tells the grass a single, small gust of wind is occuring, because the player’s global location is XYZ? What parameterized shader is this “global parameters god” telling a blade of grass to use at that moment the player is touching it? How is this “god” aware that only those few blades of grass in location XYZ should move at the moment?

I picture the player model telling the grass " You move because I am at location XYZ". I don’t know how the **MaterialParameterCollection **god solves it by looking at the entire game world, then applying a bend shader to certain foliage at that very specific moment of player/foliage contact at location XYZ. And what shader is it?

A “global view/solution” seems more complex to me, but obviously it works and apparently simply because that documentation mentions it.

(Sorry I’m rambling. This probably started to make less and less sense as I kept writing. I am not articulate, that’s for sure) :frowning:

Unfortunately i can’t really help you any further with this, since i haven’t done much with parameter collections yet. You can dig through the Material Examples and maybe you will find something, otherwise you may have to wait for an example about it from Epic.

The MaterialParameterCollection is just a way of setting a global parameter such as the player location to all materials that want to make use of it. The foliage material would have a WorldPositionOffset input that checks if the foliage mesh is inside some sphere of influence centered on the player, and if so bends the foliage out of the way. It’s a global parameter problem because an individual piece of foliage being rendered by the GPU doesn’t know anything about the player. Note that this method of bending foliage doesn’t really have anything to do with “collision”, it’s just some math calculated for every vertex of every piece of foliage, based on the player position parameter being sent to the shader.

I’m not sure where the example material mentioned in that document is, or if it’s available to UE4 subscribers yet, but I’ll find out and post back here.

Wow, you articulated that so concisely. And the part I bolded, that is exactly how my mental image of the problem is. Except you summed it up so much better and to the point. Thanks for explaining why it is a global parameter reasoning. I was half right at least. I just used too many words and didn’t step back enough to examine the issue better.

I see your point about it not really being about collision. Under the hood, the UE4 engine is not calculating two hard objects coming into contact. The result is a simulation of a collision, but behind the scenes, the engine doesn’t see it as a collision.

My brain just always pictured it as “invisible sphere of influence attached to player touches grass = grass moves.”
And that could somehow be a “system” not relying on global parameters. Thus, my focus on collision.The sphere and grass just need to know they are touching each other and grass reacts according to its material programming.

A global approach does seem faster and easier to apply to a game world though. I am very interested in how the UE4 documentation version is done.

You used the term “material.” Is it a material that bends the grass, and not shader? I was using shader for my questioning. I thought that’s how I could get foliage to bend because coming from Unity, it is a shader that bends foliage. Like the wind shader.

Is the UE4 method using a material? Can UE4 bend grass simply by adding a material to the grass mesh? If so, that is incredibly simple and . Especially for a visual learner, GUI reliant amateur like me - dragging a “bend” material onto the grass in Blueprint - UE4 would be my superhero.

Thank you for looking into the UE4 documentation. It would be wonderful to have the the foliage bend example material mentioned in the document. Having a foliage bend material would be insanely popular and, speaking for myself, convert me from Unity.

Thanks again for your very concise clarity. I am eager for your update.

You could approach it from this direction, ie enable CPU-calculated collision on the foliage, and when a cluster of foliage instances get a collision notification, find which instance it is and move it etc. This all gets a bit messy because the individual instances of foliage are grouped together in a single component for rendering efficiency. You’d probably want to hide the instances being hit by the player and replace them with individual components that you then simulate etc. A GPU-only solution is more efficient and scalable, but doing things on the GPU sometimes requires you think backwards from the point of view of each independent piece of foliage as it’s being rendered :-).

In Unreal-speak, the Material is higher-level the network you graph you build, where as Shaders are the lower level HLSL or GLSL code generated from the material graph. Note that one material might generate a number of shaders used for different purposes but that’s mostly hidden from the user. We do use the terms independently to some degree. In this case using the World Position Offset input causes the material to generate code inside the vertex shader to move the foliage.

I spoke to the artist who made the content in the doc screenshot. That content is from Fortnite, one of our internal games under development, but he’s going to port that material to plain UE4 and build a small example which we will make available to you guys.

Is the actual collision on foliage working?

can;t wait to see that, could also be great to do permanent deformations like dents in cars?
potentially tesselate the surface where hit, etc. very muc looking forward to seeing what I can do with that example :slight_smile:

Question:
When i drag said tree or rock into the map manually my collisions work but with the painter they do not? Is this normal?

Answer:

Hello,

It is expected that Foliage instance actors do not currently hold collision. We do plan on adding this in a future update, but it is not yet in the engine.

Cheers!
more ▼
answered 1 day ago
Alexander Paschall gravatar image
Alexander Paschall :diamonds::diamonds:
1.7k ● 65 ● 5 ● 6
Shoiko gravatar image Shoiko 1 day ago
So this should just be for bushes and grass for now trees and bolder should be manual understood.

Thanks Shoiko!
I’ve been asking that question for ~week now :stuck_out_tongue:

Hey JackP,

Thanks a lot for the information. I haven’t found any examples posted to UE4 yet related to this thread. Do you know if this UE4 example of foliage collision is still being worked on?

I would like to know this as well, so here’s a bump.

I have set up a grass material and given it the players position using parameter collections and the level blueprint but I don’t know how to use this to bend the grass away from the player, does anyone know how to do this or know where to find any tutorials/documentation about it?

Thanks

Thanks I hope it is relatively high priority. Would be amazing to have plant collision physics as part of a toolset within UE4. Would be precedent setting for a game engine. For example, using red to blue as hi to low bend reaction (“hot to cool”), a colored material image could be “painted” onto the plant mesh using UE4 or made separately in Photoshop, for example, as an image file of some format, and attached to the collection of textures for that specific plant mesh. The “hotter” red zones bend more than the “cooler” zones. Such as thick branches bending less than thin.

I can’t articulate it well. Hope that made sense. There is probably a much simpler, quicker way that you pros would achieve it though. I envision painting the thickness, which is the bend level, of plants being very easy though. Simply color a tree trunk red to not bend, but gradually cool down to blue as the mesh spreads out to thinner plant parts and ultimately leaves. And it could be told to react to wind using the color scale.

Just wondering and hoping for in-depth foliage tools. Game worlds these days are very redundant in regards to open world natural scenery. They’ve reached a roadblock in physics, appearance, and density of plant life. Stale. I hope there’s a new era of nature’s glory in games soon:)

Would be if it works like Cryengines bending weights which are based on vertex colors.
That way we can just paint vertex colors to control vegetation bending

Just gave it a quick try and came up with this simple material. It’s using the UVs green channel to prevent the grass base from being moved away. There are 2 parameters to adjust radius and strength of the bending effect.


GIF: http://abload.de/img/grassbent01a7bs0q.gif

2 Likes