Download

Randomly choose a mesh upon spawning foliage type?

First of all, I’m no programmer so I don’t know what I’m talking about.

We’re in dire need of a fairly small engine feature that Epic once said they might implement but in the last stream claimed they had no idea what we were talking about so I guess we’ll have to find a way of implementing it ourselves.

What we need is any way of randomly selecting a mesh from a list upon spawning a mesh using Foliage Types (either by hand painting with Foliage Mode or procedurally with Procedural Foliage Tool).
Keep in mind that I am NOT asking to instance different meshes, I know that’s not doable and for some reason that’s what people assume when I ask about this even though I never used the word instance.

The reason we need this is that currently you can make clusters, or groups of meshes that spawn close together using steps under the “Clustering” category in Foliage Types, but it can only consist of one mesh.
This is a great feature but with the limitation of a single mesh it looks rather bland most of the time.

Example: We have 3 different versions of Plant X, (PlantX_01, PlantX_02 and PlantX_03), 3 different meshes that are of different “ages” of this plant. This plant usually grows in groups in nature as it releases it’s seeds within a few meters of the plant and isn’t spread by either wind or animals.

We spawn clusters/groups of lets say ten Plant X, but due to the limitation of only 1 mesh per Foliage Type, we end up with a few clusters from Foliage Type 1 consisting of **ten **PlantX_01. Then Foliage Type 2 spawn a couple of clusters of **ten **PlantX_02 and Foliage Type 3 spawns clusters of **ten **PlantX_03.

So we get a bunch of clusters, but they all only contain one of the three versions of Plant X. This looks very repetitive and dull and not realistic at all.

Epic did talk during the procedural foliage stream about having a feature for having different “ages” of plants in the same foliage type and the further away from the center of a cluster the “younger” meshes would spawn. But in the last stream they claim they have no idea what we we’re talking about and asked “Who would want a feature like that?” so we’re stuck.

Since Epic won’t be doing it we’d settle for the simplest implementation of something like this that we can. Simply randomly spawn one of a list of meshes with a single Foliage Type. We’d be okay with not having different “ages” as that would complicate things I guess. We want to add as many meshes as we want to a Foliage Type and then have that Foliage Type randomly select one every time it spawns a mesh.

So, I am NOT asking to instance different meshes. We simply want a single Foliage Type to be able to randomly spawn meshes from a list.
Then every PlantX_01 will be instanced together, PlantX_02 will be instanced separately together and PlantX_03 will be a third bunch of instanced meshes, they will just spawn from the same Foliage Type, not instance different meshes.

I hope I explained it so it’s understandable.

Could something like this be implemented?

I would gladly pay for someone to do it for us so please let me know if you can do it and how much you want as compensation.

I think but I’m not sure, that the technique used for clustering requires that you only use the one mesh. Someone else will have to verify that though…

I see.
If someone else knows more I would love to hear about it. This is so limiting and painting it by hand would take me years.

I have some experience manipulating the foliage placed with the foliage tool at run-time. I can tell you that if all else fails, you can do a trick at BeginPlay where you read all foliage instance data, remove those instances and reinsert the instance info in another instanced static mesh component.

Foliage placed by the foliage tool is stored as, not surprisingly, instanced static mesh components. All those ISMs are kept in a InstancedFoliageActor. So if you find the InstancedFoliageActor at run-time using an TActorIterator, you can read each foliage instance’s transform. You could reuse those transforms as instances in different ISMs, for example randomly select one of your three types. Then remove them from the original foliage ISM et voila. Hope that helps.

Have you thought about using a shader to produce your different variations? I’m not sure if you could do much based on proximity to specific objects, but there are definitely proximity functions in materials. At the absolute worst you could use their position to vary the way they look and have that function repeat over short distances, appearing pseudo-random.

If you look at how SpeedTree materials work, you’ll see they do some trickery with the vertex shader and some texture maps to animate in the wind. You could come up with a coefficient based on location and modify the overall size and then tint/lerp the textures you want to use. That at least connects the colour and texture of the foliage to the size behaviour, which the current foliage implementation won’t give you.

You shouldn’t need to compensate anyone for this, it’s very straight forward! Have a crack at it and let me know how you go!

Thank you! We have been thinking of doing something similar to this but was so sure it would be too demanding to do it in runtime since we have hundreds upon hundreds of thousands of meshes. But we might be wrong, we never ended up trying. Do you think it would be viable for processing that many meshes? I’ts closer to a million.

Thank you! I did use this for our grass before the new grass tools were released. I had a list of different grass textures that it would randomly choose based on a per-instance random and also different sets for different parts of our map based on a low resolution mask that masked out the different areas. I don’t use that now but still use random color variation for most of my foliage. It definitely helps with breaking things up but I wish i could use my different meshes in an easy way.

If you use a transform map you could paint each mesh into a different shape and then lerp its effect, giving you many variations for the cost of one mesh. Actually, I think I might do this myself. Just use the lightmap UVs, make a Substance material that does the transformation with a map then start painting in something like Substance Painter to get your map. Then re-implement it in UE as a custom material.

If you use the map as an offset instead of an outright position then you can paint with a flat colour to offset whole branches, or use a gradient to rotate them.

Oh never thought about that! I’ll try that if I can’t get this to work. I have over 70 species with multiple versions of each so I’m worried about having to spend even more time on them. : )

It sounds like a lot of work! Maybe you could define the UV regions once then transform those in a bit of a more random fashion, say using a random seed to populate a sin function with reasonable limits set on the translation? I suspect it’ll look a little strange at first, but with some work you’d have fairly unique trees all over the place.

I feel like trying this myself now. I’ll let you know how it goes!

Would absolutely be something to try. Whether or not I manage to get the feature I’m looking for something like this would further remove repetitiveness.

I did have a quick crack at it after I posted but speedtrees are unholy abominations that don’t seem to transform very well. Are you using speedtree or regular meshes?

Oh didn’t think of that. Yep I use SpeedTree as well for all our plants.

Just use the procedural foliage spawner you can add multiple meshes and spawn them either randomly Or at specific locations by adjusting the spawn volumes in the world .

Thanks for trying but I would suggest reading the thread before posting. In the third line of text I mention that I’m already using the Procedural Foliage Tool and it does not contain the feature I need.

Then you need To clarify what it is you’re trying to do, How does it not contain the feature you need? You want to spawn multiple versions of the same mesh with different features so it looks more natural?? You want different heights and ages of foliage ?? Then you adjust the number of steps, seed variation settings and growth settings

this is indeed very possible and easy with the procedural tool.

You can also use multiple foliage types at the same time . And can either keep everything all seperate by using multiple spawning volumes giving you more control or you can completely randomise it and just have one spawning volume spawning everything

So it is all possible you can either control everything yourself or let the tools do it for you and tweak the results as needed .

So maybe it’s you that needs to learn to READ like maybe the documentation for a start

“Since Epic won’t be doing it we’d settle for the simplest implementation of something like this that we can. Simply randomly spawn one of a list of meshes with a single Foliage Type. We’d be okay with not having different “ages” as that would complicate things I guess. We want to add as many meshes as we want to a Foliage Type and then have that Foliage Type randomly select one every time it spawns a mesh.”

Wrong way round , create multiple foliage types with different mehes then add them into the spawning volume array either a single spawning volume or you can have multiple .
The outcome is up to you the possibilities of this tool and how you’re content looks is up to you and how you set it all up.

Another thing I have noticed is you can actually add the procedural tool as a blueprint class though at the moment I’m not sure what you can do with it. But if you can expose the right variables or create you’re own nodes you could even override the parent class and create you’re own spawning/programming logic

Hi, guys. Have same though about procedural foliage, for example i have 5 meshes of dead tree, just randomised variation of the same speedtree.
For first i need to create and adjust every foliage type per mesh, so filling up all that data over and over again when something changed (optimization pass for example) is realy boring:D
For second clusters with same mesh looking bad when you look at it in close or when you have a lot meshes in dense area.
Also its possible to reduse number of instanced meshes type with “random material” feature, like red bush and blue bush, it will be cheaper because of number of different meshes on scene and material complexity if you want to make this randomnes in shader.
And for the last some values can be realy more comfortable if they have range from min-max. So for example steps number per cluster min-2 max-5.Or clusters can get different Max scale 4.8 and 5.2 per cluster or even instanced mesh