New Path Paint Tool

Yesterday afternoon I studied the Terrain Tool Samples from Unity. They are really impressive. While I was toying around with them I saw a huge benefit of combining them and thought why not make something new out of it.

Basically what I created within 3 hours of combining and adapting code is a Path Paint Tool. The idea is this:

Have 3 brushes overlapping:

  • inner brush: texture tool
  • middle brush: bridge tool
  • outer brush: smooth tool

To better visualize it, looks like this:

4215118--374227--action.jpg

So the yellow circle is the texture brush, the blue one is the bridge tool, the grey one is the smooth tool. All of them are applied in sequence. To the left is the brush itself, the right disc is the anchor point from where a stroke is painted to the brush location.

The inspector looks like this:

4215118--374230--inspector.png

The result is a Path Paint Tool which you can see here animated:

4215118--374224--pathpainttool.gif

So creating e. g. a motocross track was a matter of a minute :smile:

4215118--374233--moto.jpg

Of course it works with multi tile terrain, that comes out of the box with the awesome Terrain Tool Samples.

A few questions I have in that matter:

  • Am I allowed to post this on github for others to use and extend? What I created is a modification of Unity's own toolset. License would of course remain the same.

  • Where can one add feature requests? e. g. it would be great if the preview brush would support setting color, saturation and stroke width. Currently it doesn't and I had to modify the shader.

  • What is a preferred way to make continuous paint strokes? Sample by distance, sample by time or anything else?

Thank you very much for your feedback :)

15 Likes

I just had to add Vegetation Studio support, ie grass and tree removal along the painting of the path. Adding support was super easy with the API :smile:

4216192--374323--vs.gif

5 Likes

Hey, this is awesome! Great work, and thanks for sharing!

2 Likes

Very cool -- would love to get it and play around with it!

1 Like

[quote=“gecko”, post:4, topic: 732201]
Very cool – would love to get it and play around with it!
[/quote]

Sure, I’ll do some polishing and post it I guess by the weekend.

2 Likes

I like!

1 Like

Awesome!

Color control for the default preview brush is on our backlog; what is the saturation/stroke width control?

1 Like

[quote=“ChrisTchou”, post:7, topic: 732201]
Awesome!

Color control for the default preview brush is on our backlog; what is the saturation/stroke width control?
[/quote]

Basically the parameters being used in BrushPreview.shader here:

float4 frag(v2f i) : SV_Target
{
   float brushSample = UnpackHeightmap(tex2D(_BrushTex, i.brushUV));

   // out of bounds multiplier
   float oob = all(saturate(i.brushUV) == i.brushUV) ? 1.0f : 0.0f;

   // brush outline stripe
   float stripeWidth = 2.0f;       // pixels
   float stripeLocation = 0.2f;    // at 20% alpha
   float brushStripe = Stripe(brushSample, stripeLocation, stripeWidth);

   float4 color = float4(0.5f, 0.5f, 1.0f, 1.0f) * saturate(brushStripe + 0.5f * brushSample);
   color.a = 0.6f * saturate(brushSample * 5.0f);
   return color * oob;
}

4222318--375130--rings.jpg

From left to right: normal → stripe width adjusted → saturation value adjusted. An option for the stripeLocation would also be nice. Of course one could always copy the Shader and modify it, but it would be nice for the Terrain Tools API to have an option out of the box.

1 Like

Will upload it probably tomorrow. Had to create a quick terrain for testing with Vegetation Studio Pro and find some CC0 textures. I'll upload the terrain itself and the CC0 textures as well for toying around. Teaser:


It's kinda tricky though to find the proper settings that work every time, eg the smoothing isn't always welcome. Or I have added a stroke feature like the bridge tool has and a paint feature where you can paint continuously. The latter has the problem that you can't always know whether the brush should go up or down. So I think I'll keep the manual fine tuning.

3 Likes

Thank you very much for the positive feedback, it's really appreciated :)

I uploaded a first version here:

https://github.com/Roland09/PathPaintTool

The Quick Setup section should get you going in no time. I included a terrain to get you started. I also added the Ridged Erosion module as optional combination.

Please be aware that Undo doesn't work currently properly. I have to figure out why that is, but I guess it's because paint texture and terrain modification are handled differently in the Undo operation. Also I couldn't create my own namespace because the terrain tools code heavily depends on some code that's Unity Reference license only and I'm not allowed to copy/modify it.

ps: Full credit to you guys at Unity. All I did was combining your hard work. You guys did a most awesome job, thank you very much for that! :) In case I missed credits somewhere, please do let me know.

2 Likes

Thank you for uploading!
Timing is perfect as well, as i am about to start making a new terrain.
Will definitely be trying PathPaintTool and hope to get involved a bit.

1 Like

[quote=“sylon”, post:11, topic: 732201]
Thank you for uploading!
Timing is perfect as well, as i am about to start making a new terrain.
Will definitely be trying PathPaintTool and hope to get involved a bit.
[/quote]

Please keep in mind that Undo doesn’t work. That’s my only worry right now :wink: I don’t like it myself when that happens, need to find a fix urgently. Unfortunately the Unity license prevents me from using and modifying their code :frowning:

fyi, I created a dedicated thread for the Unity community in case someone wants to use this as an asset:

https://forum.unity.com/threads/free-path-paint-tool-open-source-github.630832/

1 Like

I wanted to add embankment and thought I'd add the "Raise or Lower Terrain" tool. But the more I use it, the more I think that it might be beneficial for Unity to consider some kind of filter pipeline for the Terrain Tools API. Or the possibility of a graph in the future. Using 1 tool alone isn't as nice as combining them, eg it's helpful to have smoothness applied as well to the raising of the terrain. Same would be the case for sharpness. And of course the texture painting. All in 1 paint stroke.

To demonstrate, with all of these tools active:

4227439--375928--height-settings.png

I get the following, first raising, then lowering terrain, click thumbnail for animation:

4227439--375931--height.gif

1 Like

I was thinking about adding dual texture painting, one outer and one inner. Was as easy as just duplicating the paint module. Question though regarding the painting: the outer texture of course overwrites the inner one while dragging which looks like this then:

4231021--376297--tex.jpg
Is there some kind of preferred way to prevent this? Like modification of the brush during dragging or something else?

Currently I'm recording stroke positions and apply the painting of the inner brush as kind of postprocessing. I'd have wanted postprocessing anyway, was easy to add. These delayed updates however make the usability look a tad ugly though. If someone has pointers about how to make this better UI-wise, I'd appreciate the feedback :)

I've also seen there's already ApplyDelayedActions() in the PaintContext class. It would be nice if one could hook into that.

Here's to visualize the effect on the delayed painting with additionally having the height module active. Doesn't hurt, but doesn't look nice either:

4231021--376300--dual.gif

1 Like

Very nice.
Would be cool if we could 'design' a brush. Perhaps with curves indicating where one texture begins and how it fades into the next. Or define the shape of the height brush.

Perhaps one solution to the overwriting problem, is to detect the direction in which you're moving the mouse and then use a 'flat' brush instead of a circle. If that makes sense..
I suppose you would do the same when automatically painting along a spline.
But to me, your post processing solution doesn't look bad at all.

3 Likes

I was thinking about previewing the brush in the inspector. It can become visually quite overwhelming if you have 6 modules active simultaneously. Currently you can choose whatever brush the Unity terrain tools provide. But with the dragging mostly the circle with fading settings makes sense.

Thanks, that's a good idea. Although I'm not sure if that rotating would work currently. I'll have yet to find an option for e. g. the stamping brush to be rotated.

1 Like

very cool indeed

1 Like

4676519--440354--Capture.JPG works great, but when doing a build in windows, it spits out alot of errors:

Assets\TerrainTools\PathPaintTool\Utilities\LayerUtilities.cs(24,95): error CS0103: The name 'EditorGUIUtility' does not exist in the current context

Assets\TerrainTools\PathPaintTool\Utilities\BrushUtilities.cs(47,17): error CS0103: The name 'Undo' does not exist in the current context

these are just some

I am using Unity 2018.3

Stick an 'Editor' folder in between. It's because they reference editor only classes and namespaces. Or you can put an assembly definition in the tools folder and tick only editor as target platform.

1 Like