Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

New Path Paint Tool

Discussion in 'World Building' started by Rowlan, Feb 14, 2019.

  1. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    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:

    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:

    inspector.png

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

    pathpainttool.gif


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

    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 :)
     
    Last edited: Feb 14, 2019
  2. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    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 :D

    vs.gif
     
  3. gabrielw_unity

    gabrielw_unity

    Unity Technologies

    Joined:
    Feb 19, 2018
    Posts:
    957
    Hey, this is awesome! Great work, and thanks for sharing!
     
    DavidLieder and Rowlan like this.
  4. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,236
    Very cool -- would love to get it and play around with it!
     
    Rowlan likes this.
  5. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Sure, I'll do some polishing and post it I guess by the weekend.
     
    mons00n and antoripa like this.
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I like!
     
    Rowlan likes this.
  7. ChrisTchou

    ChrisTchou

    Unity Technologies

    Joined:
    Apr 26, 2017
    Posts:
    74
    Awesome!

    Color control for the default preview brush is on our backlog; what is the saturation/stroke width control?
     
    Rowlan likes this.
  8. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Basically the parameters being used in BrushPreview.shader here:

    Code (CSharp):
    1.  
    2. float4 frag(v2f i) : SV_Target
    3. {
    4.    float brushSample = UnpackHeightmap(tex2D(_BrushTex, i.brushUV));
    5.  
    6.    // out of bounds multiplier
    7.    float oob = all(saturate(i.brushUV) == i.brushUV) ? 1.0f : 0.0f;
    8.  
    9.    // brush outline stripe
    10.    float stripeWidth = 2.0f;       // pixels
    11.    float stripeLocation = 0.2f;    // at 20% alpha
    12.    float brushStripe = Stripe(brushSample, stripeLocation, stripeWidth);
    13.  
    14.    float4 color = float4(0.5f, 0.5f, 1.0f, 1.0f) * saturate(brushStripe + 0.5f * brushSample);
    15.    color.a = 0.6f * saturate(brushSample * 5.0f);
    16.    return color * oob;
    17. }
    18.  
    19.  
    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.
     
    Bodyclock likes this.
  9. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    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.
     
    wyattt_, VertexRage and ceebeee like this.
  10. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    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.
     
    VertexRage and mons00n like this.
  11. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    246
    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.
     
    Rowlan likes this.
  12. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Please keep in mind that Undo doesn't work. That's my only worry right now ;) 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 :(
     
  13. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Last edited: Feb 18, 2019
    wyattt_ likes this.
  14. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    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:

    height-settings.png

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

    height.gif
     
    VertexRage likes this.
  15. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    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:

    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:

    dual.gif
     
    DavidLieder likes this.
  16. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    246
    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.
     
    awesomedata, DavidLieder and Rowlan like this.
  17. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    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.
     
    DavidLieder likes this.
  18. Baalhug

    Baalhug

    Joined:
    Aug 12, 2013
    Posts:
    32
    very cool indeed
     
    Rowlan likes this.
  19. voc007

    voc007

    Joined:
    Nov 18, 2012
    Posts:
    8
    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
     
    Last edited: Jun 23, 2019
  20. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    909
    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.
     
    Rowlan likes this.
  21. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Please move the Utilities folder into the Editor folder, i. e.

    current:
    Assets\TerrainTools\PathPaintTool\Utilities

    new:
    Assets\TerrainTools\PathPaintTool\Editor\Utilities

    I'll upload a new package later this week, I'd like to test against 2019.1 and the new terrain tools first while I'm at it.
     
  22. Adragen

    Adragen

    Joined:
    May 4, 2013
    Posts:
    25
    Any tutorials floating around? Got the tool, seems easy enough but I'm not seeing results like stuff above.
     
  23. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    It basically is only a mixer for Unity's own awseome terrain tools. Nothing special. But here's a dedicated thread:

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

    If you have questions or problems, just ask in the thread, others might be interested as well.
     
    Adragen likes this.
  24. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Unity added a lot of new terrain tools, it's getting hard to keep up and manage them all in order to have a combined painting mechanism with a single stroke. So I gave it a thought about how to clean up the UI and facilitate the mixing better.

    The "cleanest" solution I could think of was to use a reorderable list. Basically you add whatever terrain tool you prefer, put it in the order you like and set the relative position and relative brush size via a range slider. The tool brush size is the absolute size.

    Looks like this:

    mixer.png

    Single click on a terrain tool gives you its settings. Or does anyone have a better idea?
     
    wyattt_ likes this.
  25. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    909
    I like it, i would even use this mixer stack just for regular editing not specifically trying to paint paths. Maybe give each tool in the list a dropdown for its options; it's personal preference but i find it sometimes hard to 'select' a list item where instead i click some control it contains.
     
    Last edited: Mar 9, 2020
    Rowlan likes this.
  26. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    246
    I'm really glad to see you're still working on this.
    I've been out of the running for almost a year due to health stuff. When i came back here, this tool was one of the first i checked for progress..
    Any luck on implementing Undo yet?
     
  27. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Sad to hear, I hope you're fine now.

    Yeah, I added some stuff like e. g.dual path painting, i. e. like a wagon driving over a road. I have the code, but didn't release it because I sense that the upcoming stuff by Unity, i. e. Environment System with Layers and additionally Unity's Splines will kill everything there is and the work would be futile. Which also means the Undo mechanism is futile. I intended to add backup & restore of the entire terrain. But I figured it would be a feature of Unity's own Terrain Toolbox on the one hand and on the other hand with the upcoming layer system it might not be necessary at all.

    My hopes were to see something happening next week when GDC 2020 would have been. But that was understandably cancelled by Unity with reason. So fingers crossed that Unity still shows progress and from that on everyone can make plans.
     
    Last edited: Mar 10, 2020
  28. sylon

    sylon

    Joined:
    Mar 5, 2017
    Posts:
    246
    Yes, i'm fine. Thanks :)

    I have to dig in to all the new developments that i have missed. Especially the terrain stuff.
    So hopefully it all comes together nicely and in a timely manner :)
    Thank you Rowlan.
     
  29. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Really awesome work man! -- I don't think you should give up on this though!

    Do not fear the "new" Environment System!

    I have confirmed with Unity that the new "Environment System" is still using their heightmap-based terrains (which really makes me cry), so your tools should still work. As far as I understand it, the workflow remains largely unchanged. That is, you will still author your terrains as normal, but with "Layers" essentially defining the shaders/textures/details for a given (standard) Terrain. These are details (such as rocks/grass) your specified terrains use. The terrain tools themselves will remain relatively unchanged -- it's just how those authored Terrains are leveraged in the visualization pipeline at runtime that will change.

    And just to cover my bases:


    @ChrisTchou -- How far off am I?


    Anyway, @Rowlan, I think you're doing an awesome job on these tools. I really don't think you should give up. After all, the Environment System sounds like it is a long way off until it is ready for production use. In my case, I'm still in tears that Unity hasn't yet properly supported mesh-based terrains (i.e. for streaming worlds). I'd really like to be looking forward to the new "Environment System", but its current design does not plan to support mesh-based terrains as far as I can tell -- though I may be wrong. Maybe the shader/detail-placement systems can be updated to support mesh-based (non-heightmap) terrains? -- Either way, I think a full-featured solution to heightmap-based terrains is in your hands, @Rowlan. I seriously think you should keep working on it! -- You've got some badassery going on there! It'd be a shame to toss it for a far-away feature like the Environment System. Momentum like yours is hard to get back!

    Keep at it man! -- We're all looking forward to seeing what comes of your tool! :)
     
    Rowlan likes this.
  30. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Thanks, but not giving up here :D Just waiting for the synergies. I took a look at the latest Unity Terrain Tools. They even have paint history now. Only for Unity Tests though, but who's to say we can't "abuse" that.

    There's lots of nice new stuff there. But the thing I'm looking forward to the most is actually splines. You can do a lot with them, it will be killer. I use them in my YAPP tool, a free spline solution from the community though. However going with standards is the way to go. Not only can you model paths, roads and rivers with them, but also automatically have dual paths, easily distribute gameobjects, move objects along them, etc

    Let's wait for next week, I hope Unity still shows their roadmap and state of things.
     
    awesomedata likes this.
  31. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Just in case anyone searches for the Path Paint Tool thread: Unity deleted it:

    path paint tool thread deleted notification.png
     
  32. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Wow. You bad, bad person. What did you do?? lol
     
  33. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    My current state of knowledge is that a publisher has a trademark on something, whatever that may be, he doesn't disclose it, neither does he show proof of the trademark. And apparently when you purchase an asset and it turns out to be bad, you're not allowed to make one that's useful for you. Neither do you get a refund.
     
  34. Waterlane

    Waterlane

    Joined:
    Mar 13, 2015
    Posts:
    188
    Is your path tool available anywhere now @Rowlan ? :)
     
  35. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Yes, of course. Unless Unity tells me what I'm actually violating or the publisher tells me what exactly he has a trademark on, it'll always be available for free:

    https://github.com/Roland09/PathPaintTool

    After all it's only a Mixer of Unity's own Terrain Tools, nothing else.
     
  36. Waterlane

    Waterlane

    Joined:
    Mar 13, 2015
    Posts:
    188
    That's Great! - Thanks very much :)
     
  37. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Waterlane likes this.
  38. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    You'll be waiting a while. lol


    Sadly, I've seen users get banned for simply asking why -- and then insisting they get an answer. :/

    They've been sniping free, useful, "addon" assets like yours. I think MCS Caves and Overhangs was one of them that the author tried to release for free, but Unity gave the author grief for it. I've seen others though.
     
    NotaNaN likes this.
  39. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Also, I just wanted to say, I think plenty of people (including me) would appreciate if you developed this tool further. Just seems like a no-brainer tool to have in the toolbox. :)
     
    Rowlan likes this.
  40. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Thank you, but to be honest working on it while Unity is working on the Environment System is a waste of time. You know, any minute they could announce it and then it would all be futile. The last update on the Terrain Tools was quite some time ago. The new Environment System is the way to go. I rather spend my spare time on something that's future proof and cross platform. But in order to provide that for free, the issue at hand needs to be clarified first.
     
  41. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    You're absolutely right. As not much has been mentioned about the new Environment System, I had completely forgotten about it. I simply saw your roadmap on your github and thought "Yeah, anyone doing heightmaps in Unity definitely needs this!"

    I personally do environments with Houdini, so I don't mind one way or another, but I thought it might be nice to do some manual work at some point.

    Do you think it might have something to do with the Vegetation Studio support? -- Maybe that's a good question to ask. I know a lot of the time, Unity half-asses their approval process for assets. They don't have the manpower to dig through the code apparently.
     
  42. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    No, that's not VS related.
     
  43. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    1,419
    Didn't think so -- However, I asked because I've known Unity to half-glance at descriptions/images when uploading to the Asset Store and deem them "unworthy" simply through 'at-a-glance' misunderstandings. Your github says "Vegetation Studio" in it, so I was thinking maybe they saw that and just instantly "noped" it.
     
  44. siemthanh5

    siemthanh5

    Joined:
    Jul 9, 2020
    Posts:
    2
    wow, tks so much
     
    Rowlan likes this.
  45. Aykutkaraca

    Aykutkaraca

    Joined:
    Jan 4, 2018
    Posts:
    33
    I suppose you removed your tool from github? I only see gitignore and readme files...:(
     
  46. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    909
    Rowlan likes this.
  47. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    I started updating the code, so that it's easier to migrate to Terrain Tools 4. It was little effort because Unity now supports reorderable lists, which is awesome. I tried compacting the UI and give the stacked brush size and brush strength a better comparable overview. Currently looks like this:



    It would be so much nicer if Unity would support stacking their tools out of the box. Or at least provide an interface so that the tools can be re-used in a stack :)
     
  48. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Made it compatible with the experimental and the release version of the Unity Terrain Tools. I thought I'd pick up the very first post and add a bike an hit play and modify the terrain while I drive :D

     
    andreyefimov2010 and TerraUnity like this.
  49. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,159
    @Rowlan Great as always. Kinda off-topic but do you have any advices on applying the heightmap on the whole tile using the new GPU based API without any lags in runtime?
     
  50. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    3,590
    Thank you.

    Haven't tried runtime yet. I was thinking about adding a brush to the bike and just drive :D Don't have the time for that yet, however the hints I got from @wyattt_ are in this thread, or in short: Get the Unity Terrain Tools and check out the MeshStampTool.cs class, I think that might be better suited for your case.
     
    TerraUnity likes this.