Road Splines Procedural Tool

Road Splines Procedural Tool - WIP

This is a new road building tool based on the built-in Unity splines & terrain tools.

I am building this because existing road tools aren’t exactly what I want, and this may help other people.

There are a number of Pros and Cons versus other road tools. It’s primarily for country road building instead of city building. There are no fixed pieces of road to attach and no texture management. A road shader creates all the details including line markings, intersections.

Pros:

  • One-click Intersections: Select three spline knots, click ‘give way’ or ‘stop’ to make an intersection. Knots and roads are auto-aligned. Road markings are automatic (customisable colours in shader). One line of code can also create an intersection.

  • Road shader: Automatic non-repeating details. Line markings, wear, rain, dirt overlay, and more.

  • Terrain painting: Gravel is painted under the road with the provided texture. Non-destructive in preview mode.

  • Terrain height: Road-matching height is set with two smoothness settings. Non-destructive in preview mode.

  • Bridges/Tunnels/Landslides. Terrain remains unmodified over/under the road to allow bridges, tunnels, landslides, or other environmental effects. One section per road group.

  • Tree & grass clearing. Non-destructive in preview mode.

  • Guide posts. Auto placement.

Cons:

  • No pre-built sections of road. Does not suit city building or highways.

  • Road can be any width, but the tarmac shader only draws two lanes at this time.

  • Any number of intersections can be made, however start & end of intersection must be connected to two splines in consecutive order so the UV matches. Side roads can be any spline knot. Knots are colour-marked if gizmos are turned on.

This is a WIP. Most of the hard parts are done but it still has missing features. I’ll be working on these over the next few months.

Please post any feedback you have… if you think this would be suitable for your project but is missing one thing, or have any other feedback.

Thanks

Road shaders have a low-angle sheen effect, which Unitys renderer (most renderers AFAIK) don’t actually do.

The road looks good but terrain doesn’t quite match, so still thinking about which way to go with this.

With a more detailed terrain, the difference would be less noticable.

The road shader (sharp edged lines, & sand/rock noise overlay) don’t do mip-maps. Shimmering is occasionally noticeable with the sand/rock overlay. TAA anti-aliasing removes 90% but also the detail.

Added Lines Age user variable for road shader. 0.0 - 1.0

Line markings are changeable to any colour, width.

Added Road Mesh Bumpiness.

Noise for the edges of the road, adjustable by Height, Direction, & Frequency.

Improved the Road Sink look.

Road Sink is controlled by four sliders in the shader. Large, Medium, Small, Tracks.

The dirt effect on top is controlled by the Sand and Stone Alpha overlay. This can be replaced by flower petals, leaves, etc, and has a colour tint.

Hello. I would like to try it and give feedback. I am really interesting in this.

Added a better road edge to the shader. Ie. The noisey dark edge.

Controlled by Road Edge Noise, Noise 2, Thickness.

1 Like

Hi, I’ll get back to you in a few days to a week. There’s a few things to fix.

1 Like

I’m aiming to finish this in a few weeks.

Primarily needs auto terrain height, auto sign posts, and some tidy up.

I’ll take improvements/bugs/features after everything is done… unless anyone has an idea that their project needs.

1 Like

Sorry for the delayed response. I have a project where I want to create small roads on a standard terrain. I would also like to have the ability to paint the terrain using road splines, just for small dirt roads.

It would also be great to have a tunnel system (for example, a mesh that tiles like a road mesh using a spline).

Good luck with the development! I hope everything works out for you.

Can you DM me? I’d like to help you in any way I can.

Thanks. It’ll be useful for what you see from the photos right now… Road splines with a non-repeating texture, auto painted gravel… I’ll keep in mind the tunnel system.

Going through a hole in the terrain is highly complex.

I understand Jason Booth’s Microverse Roads has a tunnel system, but it seems to me the best way is to make a high quality tunnel mesh in another 3D program then import it and run the road through it.

I have a dirt road shader that’s a work in progress.

If you want to DM me images of something you have in mind. - Real life images of roads. I’ll take a look at that and try to replicate it.

Sand and Stones overlay - Sand texture

Non repeating and works with the intersections.

One 1024x1024 sand alpha texture is multiplied with noise, and a user selectable colour.

Sand and Stones overlay - Gravel texture

A 1024x1024 RGBA texture multiplied with noise and user-selectable colour tint.

User options: Colour Tint, Amount 1, Amount 2

Water settings in shader. One per spline (material instance).

User options: Water Location, Water Length, Water Amount.

Looks better than a flat water puddle decal as it takes in road sink (tyre tracks) and sand/gravel information. Although you should also use puddle decals on the terrain.

Suitable for flooded road, waterfall, rain, etc.

Lines Stop/GiveWay Offset in shader.

There are seperate colour options for road Outside lines, Center line, Stop/GiveWay line.

Double centre lines in shader. One per spline (material instance).

User options: Location, Length.

Working on bug fixes with terrain painting and height offset.

Height offset (terrain auto-levelling to match the road) is 99% coded, just working through final bugs.

On another topic, the road shader used to be a rendered as a decal, but reflections weren’t showing properly so it’s changed back to a standard lit shader.

Basic road Height Offset test.

It’s now possible to click & drag a knot on the spline to update both the gravel & height non-destructively.

Frame rate was ~30 FPS, but the last terrain tessellate function is a unity CPU function which slows everything down to 5 FPS. Don’t know how to get around that while still being compatible with Unity Terrain.

The picture below uses a 1025x1025 sized heightmap (showing 1/4 of the map). Road edges smooth-transition to the terrain, controlled by the gravel edge slider.

The ‘mesh passing through road’ errors are due to the small 128x128 distance field texture. There’s performance room to move to a larger texture, so will be testing that next.

Changed the height map from a 128x128 basic distance-field to a 256x256 dot splatmap type distance-field. Not 100% perfect yet, but close.

User can adjust the Edge Smoothness 0.0 to 1.0. Very sudden height difference to very smooth blend.

Trees automatically adjust their vertical position depending on edge smoothness, and the user can drag the road anywhere and it all updates. Nothing is baked in.

Need a few more weeks on the heightmap, bug fixes, and auto sign posts after this.