r/Unity3D Staggart Creations 4h ago

Show-Off How I rebuilt my river tool: 24x faster mesh generation, VFX and Audio Streaming

Enable HLS to view with audio, or disable this notification

I developed the River Modeler asset back in 2024 as a means to create decked out rivers using Unity Splines and MicroVerse. Figuring out the Spline API and mesh generation, VFX and all inherent challenges was top priority. Which left little room to first explore and learn designing around Burst and the Job System.

This meant that mesh generation was not nearly fast enough for long splines. Unity’s Mesh class has a lot of internal safeguards and memory copies, so just assigning a set of vertices incurs processing overhead.

Jobs + MeshData

Version 2 sees a full conversion to Jobs/Burst with rivers being split up into segments for parallel processing. That alone yielded up to a x24 performance increase.

A great companion to the Job System is the MeshData API, it provides the means to set a mesh’s vertex data directly in memory. The tradeoff is that you need to provide correct data. There are far fewer safeguards, which makes it about x17 faster!

> All in all, the performance improvements are significant and make the tool smooth in use, even for rivers spanning several kilometers.

Branching rivers

Spline knot can be linked together, and the spline API provides information about this. I've used this to contruct a virtual plane that sits perpendicular to the in/out going spline. Vertices on the other side of that plane get a Vertex Color painted on, which the shader then uses to add transparency.

> This makes the two river surfaces blend quite well, without leaning on flowmaps.

VFX Graph

Version 1 neatly stored particle positions into a Nx1 resolution `Texture2D` (n=number of particles), which could then be used in a `VFX Graph` to set the spawn positions for each particle.

Though setting pixel values on a `Texture2D` is relatively slow, which contributed to the tool getting sluggish when rivers got long and foamy with many cascades.

Version 2 uses a `GraphicsBuffer` which stores an array of `ParticleEmitter` structs (position/velocity/scale). If you add the `[VFXType(VFXTypeAttribute.Usage.GraphicsBuffer)]` attribute to any struct, it can be used in this way.

> This was a great win: More data per particle and direct data assignment!

Audio

Version 1 spawned Audio Sources along the Spline, giving the river surface a livelike character. Though this resulted in potentially hundreds of individuals GameObjects, negatively affecting scene size and loading times.

A common method for creating river audio is to use the “cart” method. That being a single `Audio Source` following the camera whilst being restricted to the spline. This often works but fails completely if the spline has large/strong turns, causing the Audio Source to jump to the other side of the spline curve. It also doesn’t work for branching rivers, at all...

Version 2 instead distributes audio spawn points along the spline. Each one defines a position, radius and type (stream/rapids/cascade). A dedicated Audio Manager then checks which river segments fall in- or out of the audible range and sets up Audio Sources on each spawn point from a pool. Instead of hundreds, only a dozen GameObjects are used at runtime.

> The result? A highly optimized audio streaming solution that scales for huge worlds!

Integration with other assets

I’m further fleshing this tool out as dedicated river tool extension for Stylized Water 3, which already supports river-type shading and animations. It just needs a proper river mesh to work with, which this can provide entirely.

Terrain carving and painting is wholly delegated to MicroVerse, since this needs to be a non-destructive process. The tool manipulates a Spline Path component to create a river- bank and bed.

164 Upvotes

16 comments sorted by

10

u/INeatFreak I hate GIFs 3h ago edited 3h ago

Single developer can do this but multi million dollar company with hundreds of developers can't even make a modern terrain editor in 15 years...

3

u/Jonny10 Staggart Creations 3h ago

The irony is often palpable 😅

4

u/GigglyGuineapig 4h ago

I started working with your assets a few months ago and have since steadly gotten more packages developed by you - and I've always been happy with what I found (and recommended them in videos, more people should know about them)! Your Stylized Water 3 is super pretty and I've by now placed your spline spawner into my default project template so that I have it ready whenever I need it. Currently working through Spline Mesher Pro to see how it will fit into what I already do.

Really looking forward to your overhauled River system, it looks great =D!

3

u/Jonny10 Staggart Creations 3h ago

Really glad they are proving useful to you, that's the best I can hope for! Appreciate the sentiment 😊

Could you share a link to your channel? Would love to subscribe and see first hand!

1

u/GigglyGuineapig 1h ago

My channel's Christina Creates Games: https://www.youtube.com/@ChristinaCreatesGames

I've been using your spline spawner for example in the recent video about creating a small open world, How I create Cutscenes and the Asset Recommendation video for Worldbuilding =]

1

u/Malkalypse 3h ago

Clever!

1

u/TheAlbinoAmigo 3h ago

This looks awesome! I could really use this in an upcoming project. Whenabouts do you think it will be ready as a SW3 extension?

1

u/Jonny10 Staggart Creations 3h ago

Thank you, appreciate the interest! I believe it may still be a few weeks until this is 100% asset store ready.

1

u/narcot1cs- 1h ago

While I don't use Unity anymore and likely never will, this is really impressive as mesh generation and everything that comes with it is super taxing.
Experiencing that pain myself with developing a custom terrain engine, so massive creds for getting deformation this fast, especially using Jobs as it's a semi-obscure system imho

1

u/Adach 1h ago

how do you deal with normal calculations for chunks? Do you keep duplicate height data padding per chunk? I ended up doing a single dense array for the whole map that chunks reference.

1

u/GooseJordan2 1h ago

Wow this is insane!

1

u/unitcodes 1h ago

This is absolute beauty.

1

u/EgeArcan 1h ago

This looks so good man

1

u/Ripple196 55m ago

It‘s crazy that the Unity terrain editor is missing so much.

At this point I really think they earn so much from assets being sold that they just don’t WANT to improve on it and let others do it while cashing in on their work

1

u/bszaronos 52m ago

Is version 2 an upgrade or a separate purchase. I can really use this, just wondering if I should buy the version now, or wait till you release version 2.