I’m trying to set up a blueprint that automatically populates foliage instances randomly on a static mesh surface and uses the mesh normals at those locations to orient all instances correctly upwards.
With this I want to quickly iterate by switching out the instance mesh or static mesh to create new assets and if possible animate the scale parameters to fake the growth of said foliage with a noise.
That would hopefully be a similar setup to how scatter in Cinema 4D a bit more simplified.
I haven’t found anything on how to get started on something like this but since this forum has helped me out many times I thought this would be the perfect time to dive in with a post
I’ve did this once for a character mesh in C++ by using some code I’ve found online, but I can’t recall any of it because it was (and is) above my paygrade. It didn’t work anyway as it is expensive and not feasible to access vertex normals on a character mesh with blendshapes applied as you need to push it out from the GPU to the CPU to see where the points are. And that is a big no-no
but because you want this for static meshes (should work for characters without blendshapes also) I believe the best bet is to look into niagara.
niagara should give you those points and add stuff on top of the rock probably
if not search the forum for vertex normals I’ve seen some posts about them
Thanks for your input! I will read a bit more into line traces.
I’m still fairly new when it comes to blueprints, from my current understanding/everything I found on it a line trace till now is they work by sending out lines from player input or other meshes like during foliage painting or the player running through the tracer line but mostly into one direction.
Is there a way to use line traces to have them spawn all around the mesh in blueprint like a bigger sphere casting them inwards and spawning on the hit locations?
If I manage to set that up then I could maybe control the individual scale and placing of the spawned meshes with a noise shader affecting scale of the individuals that can be potentially animated.
I’m still a bit lost on how to best go about the creating something like this with my limited understanding so any info helps a lot!
For example why switching out the affected static mesh would be more of an issue then switching out the instances?
I will also try around a bit with the procedural foliage spawner maybe that is something potentially useful if its able to spawn from below as well and orient the meshes correctly.
thanks for your input!
I’ve tried using niagara at the beginning since its fairly easy to populate meshes along a surface of a static mesh.
I’ve ran into multiple issues so far sadly as for one there seems to be no way to to adjust their direction according to the normals so they stand up correctly.
(at least nothing I tried or could find worked here and someone mentioned it not working haha).
Since they’re particles the meshes also seem interact differently with lighting and can look a bit off/fake for foliage.
I’m not sure how perfomance hungry spawning in particles as permanent would be but I imagine it would be fairly low depending on the amount but if possible it would be better to have real instances spawn so they’re always sitting at the same position once I use a seed and don’t look different every run to avoid awkward looking meshes.
The trace goes from point A to B. So you can use them any way you want
You can do it ‘foliage tool style’ and paint stuff on the mesh, or you can do casting inward from a sphere onto the mesh. Definitely.
Changing the instances is easy, because you can just change the mesh used by the ISM. But changing the main mesh is more difficult, because nothing is going to auto-adjust. You have to do that. So it would mean doing the trace from scratch.
I managed to set up a working system using Niagara and sampling a mesh in a blueprint that I switch using MeshIDs!
Now I’m trying to use the impact location of a collision with my hand to scale up a sphere mask in a timeline that spawns the foliage delayed so it spreads from the impact location.
I have set up a working material that spreads moss for this using a sphere mask in blueprint as following:
This works perfectly but sadly I can’t seem to find a way to use my spheremask to affect the niagara spawn…
Another way might be using the same input values of the timeline and impact location to set user exposed parameters on a region sphere mask inside the niagara material like this:
but at this point I’m stuck at figuring out how to use the animated region mask scaling up to drive the foliage meshes to spawn on the static mesh location. I sadly can’t use opacity to hide some of them since I have a growth animation. I’m also not sure what spawnmode would make sense here. With spawn rate I had the issue of the foliage continuing to spawn with my infinite set lifetime for the particles but spawn burst instantaneous isn’t really an option anymore once I animate the spawning.
I hope this makes sense! thank you
(EDIT: I just had the Idea I might be able to spawn them all like usual but at scale 0 once the collision triggers the system to run but scale them up from 0 to 1 using the region mask panning over the static mesh. But that will have to wait for tomorrow since it’s already 1am haha )
Where it gets complicated is that inputting the global location variable into the region mask dosen’t work on a local space system as the location is assuming the mesh as 0,0,0 there.
Global works fine but stops the system from following my meshes which ends with the particlefoliage floating in the air while the simulated parent meshes change their location after collisions.
I thought I might be able to switch out the global location variable through a generate collision event inside the system to stay local but those don’t work on gpu emitters and I’m not sure having so many meshes with static mesh foliage on them is a good idea on a cpu emitter performancewise.
I think I either need to find a way to get the local niagara system to read a world location input/transform that input to local input or find a way for the system to stay on my mesh without having local space on but I’m at a loss at achieving either of those atm.
This made me realise I can simply put the mesh location module into update instead of spawn which fixed that issue completely!
I will work on implementing some hand interaction physics with the foliage now and try to set up an alternative spawn method using a render texture to paint the foliage by hand interaction instead of using a region mask that scales up.
Your input has been extremely helpful on getting this far as this is my first project diving deeper into interactions. thanks a lot
Is it ok to leave this thread open for a few more days till the feature is done?
Heyho!
I’ve been making some good progress on my setup as shown here:
My blueprint will spawn the niagara system attached to a hit mesh and draw several line traces into a render target texture as brushstrokes.
The spawned Niagara system is then using this render target as a texture sample to scale particles on that spawned at the beginning.
Here I’m still looking for a better solution to have them spawn in a fix amount per distance on the white alpha of the render target as soon as new areas get painted.
If they all spawn at the same time the scale mesh timer will kick off at the beginning and not work on all the painted areas later on.
Because of this the plants only grow slowly on startup and grow taller instantly with the alpha on everything painted afterwards. Besides that it’s probably better performancewise to only have them spawn where they are needed.
The biggest issue I’ve encountered so far as seen is that in the working example above every mesh is using the same render target texture which is set using a user parameter
which in turn gets set by the Set Texture Object Node in the BP
I have already set up a system that dynmically creates a render target texture in a dynamic material instance for each mesh that is touched if it’s not already existing. This works perfectly for the moss material as seen here:
But somehow the niagara system is unable to read that dynamic render target texture in the Set Texture Object node and remains blank.
Not sure how to proceed on this one or if it’s even possible at all to have a niagara system read dynamically created input like this. It seems way more practial performancewise vs giving each mesh a fix render target texture that loads on spawn.
It would be amazing if you have any ideas on solving those issues
thanks in advance!
thank you!
I’m not sure I get what you mean by growing the plant mesh particles using the emitter scale vs the RT. Right now this is the RT being fed into scale mesh size:
The RT is being read in the particle update and should generally work as I can use it with a normal render target that can get switched out via BP and reinitialzing the system
this is the node structure in more detail:
A potential solution I see for the second issue is duplicating a mesh attached to the orignal one that uses the RT as an alpha and spawn the plants in all visible areas like this: UE4 Niagara Generate Particle at Dissolve Edge - Tutorial - YouTube
I’m not sure if that is possible using a opacity falloff in this technique and I would need to have a doubled mesh for each in the scene but it could be a potential fallback solution.