Search Unity

[Released] [FREE] Vertex Painter 2.0, paint on mesh instances, splat map shaders, Flow maps, AO, etc

Discussion in 'Assets and Asset Store' started by jbooth, Feb 8, 2016.

  1. moure

    moure

    Joined:
    Aug 18, 2013
    Posts:
    184
    @jbooth nice update, thanks for all the hard work that you share!
    I was wondering if it possible to create a tessellation shader variant or does the tessellation mess around with the vertex colors? Never had to use something like that before and have no idea if the new vertices that are created during tessellation keep the original vertex colors.
     
  2. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    @moure
    You can interpolate the colors as part of the tessellation. But personally, I don't think tessellation makes much sense for surfaces in most cases. The tessellation pipeline's on most cards are extremely slow, and you're usually better off just subdividing your mesh in the areas you need more detail, or doing something like Parallax Occlusion Mapping. On top of that, dynamic tessellation tends to swim as the tessellation level changes, so it's one of those great in theory but not so much in practice technologies. Useful for non-surface stuff, like hair, though..
     
    moure likes this.
  3. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    @Tom163

    Hey Tom, are you expecting that it keeps showing you vertex colors when you don't have the vertex painter active? For that, you'd need to apply a shader to your mesh that uses the vertex colors; when the vertex painter is active, it's using a preview shader so you can see the data, but it reverts back to whatever material you have on your object when you uncheck 'Show Vertex Data' or deactivate the painter. Your data is still there, but the Unity's default shader just isn't using it..
     
  4. Tom163

    Tom163

    Joined:
    Nov 30, 2007
    Posts:
    1,290
    Yes! With a custom mesh, it works just fine. Maybe you should include a custom plane? I can make a github pull request and add mine if you want.
     
  5. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Seems odd, I used the unity plane in all of those videos I produced..
     
  6. wdw8903

    wdw8903

    Joined:
    Apr 2, 2015
    Posts:
    48
    Hello, thank you for this useful plugin. And I think I found a bug.
    I can't paint "Value G" as target channel. Other target channels work fine, and paint ing green color in "Color" target channel also work.
    I use the latest plugin in github.
     
  7. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Fixed- typo in a recent refactor, thanks!
     
  8. wdw8903

    wdw8903

    Joined:
    Apr 2, 2015
    Posts:
    48
    Great, I also have a suggestion.
    When the vertex painter window is opened, if I select an object in scene, the object will be added "vertex instance stream" script automatically. But I don't want to add the script, static object has conflict with vertex instance stream, and the vertex painter is not active. I think the script should be added after I active the vertex painter.
     
    ElectroMantis likes this.
  9. wdw8903

    wdw8903

    Joined:
    Apr 2, 2015
    Posts:
    48
    And shortcut for brush size and flow will be great.
     
  10. ElectroMantis

    ElectroMantis

    Joined:
    Sep 15, 2013
    Posts:
    78
    This becomes problematic when I select or paint a terrain object that has many children that are combined at runtime (grass objects). The tool adds a vertex instance stream to Every object the the hierarchy, and then I have to manually remove them.
    It would be preferable to have an option to only add a vertex instance stream to Only the single object you're painting.
     
  11. Flurgle

    Flurgle

    Joined:
    May 16, 2016
    Posts:
    389
    The video looks amazing.

    Could this be used on skinned meshes?
     
  12. SukhvinderSingh

    SukhvinderSingh

    Joined:
    Jul 18, 2016
    Posts:
    55
    Shaders are unable to compile in unity 5.4. Import is stuck on importing shaders
     
  13. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    They compile- they just take a really long time. I would suggest deleting the workflow you aren't using from the files if you want them to compile faster (like if you don't need specular, or 5 layers, etc)..
     
  14. 8bitRick

    8bitRick

    Joined:
    Nov 18, 2013
    Posts:
    11
    Confirmed, I removed all shaders and just compiling the 4 layer took about 3 to 4 minutes on my GTX970, I can see it's from all of the compile time branch baking, nice, old school! @jbooth thanks for this awesome asset. I just wanted to get a splat map shader with PBR, I'm converting a terrain I created in Gaia into a mesh object and trying to apply the terrain textures to the new object. Your splatmap 4 is close to what I need. In Gaia I can export a splatmap mask with the 4 layer weights as a single RGBA texture. I'm just going to hack your shader to use this instead of the alpha from albedo. Just sharing this to let you know a use case that others might run into. And to let others know that, yeah it is compiling the shader, just takes a few minutes, delete the ones you don't want.
     
  15. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461

    Yeah, for MegaSplat, I got around this by making my own shader generation system that basically writes out the shader you want based on the options. shader_feature blows up once you have more than a dozen options or so, and MegaSplat has hundreds. It actually takes over a month to compile every option on my laptop (though I've never actually let it do that).
     
  16. Karbec

    Karbec

    Joined:
    May 23, 2013
    Posts:
    3
    Great work! Any chance this will work with skinned meshes?
     
  17. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Nope, additional vertex streams are not supported on skinned meshes..
     
  18. colin299

    colin299

    Joined:
    Sep 2, 2013
    Posts:
    181
    I use this tool for terrain "texture splatting with heightmap" & "flowmap", works really well(feel like using UE4 vertex painter),


    the only problem I have now is I must write "disable batching" is my shader inorder to work, else the following error will appear when I hit play
    Code (CSharp):
    1. Not allowed to access vertices on mesh 'Combined Mesh (root: scene)'
    2. UnityEngine.Mesh:get_vertices()
    3. JBooth.VertexPainterPro.VertexInstanceStream:Apply(Boolean) (at Assets/VertexPaint-master/VertexInstanceStream.cs:456)
    4. JBooth.VertexPainterPro.VertexInstanceStream:Start() (at Assets/VertexPaint-master/VertexInstanceStream.cs:191)
    5.  
    wonder if static batching is possible when the additional vertex data is present?
     
  19. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461

    You need to bake the mesh down to a unique mesh using the Save Mesh utility. Static batching requires that the mesh data not be read/write, and additionalVertexStreams cannot be saved into the scene, so you have to bake everything down into a unique mesh.

    In MegaSplat, I have a system to do this automatically across whole scenes, which can be integrated into your lighting/build pipeline so you don't have to think about it much..
     
    colin299 likes this.
  20. punchface

    punchface

    Joined:
    Oct 21, 2016
    Posts:
    3
    Files obtained from github....but when unzipped, not packaged.

    How do I install?

    Sorry for the noobish question...but well...I'm a noob.
     
  21. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    copy them into your assets directory and wait while unity compiles the shaders (for like 5 minutes)
     
  22. punchface

    punchface

    Joined:
    Oct 21, 2016
    Posts:
    3
    Everything is in a set of folders and sub folders....copy everything? I don't mind if it takes five minutes...I'll just go get a cup of coffee or something....check my email, whatever.
     
  23. punchface

    punchface

    Joined:
    Oct 21, 2016
    Posts:
    3
    BTW sir, I expected to have to wait hours to hear something back. Thanks VERY much for being so responsive!
     
  24. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    yep.
     
  25. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    something i am working on.

    a lot of vertexpainting has to be done ;D
    still cant get parallax effect
     
  26. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Do you have a directional light? If you don't, then it wouldn't have a light direction to parallax off of. Also of note, parallax is parallax offset, not Parallax Occlusion Mapping, in case your confusing the two.
     
  27. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    obviously i got a direct light. i figured out that nothing is wrong with you shader at least. other shaders (uber shader has same problem). i got latest unity freshly installed .... something is wrong - strange.
     
  28. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    still no parallax effect but i found no better solution - maybe i purchase megaspalt - it should work with meshes as well!?
     
  29. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    So, there's a bug in the Unity Shader compiler that hit MegaSplat a while back and broke parallax mapping in some cases. Basically, it looks like the compiler doesn't realize your using the viewDir and writes it out in world space instead of tangent space. You might try putting a useless statement that the compiler can't optimize out at the end of the shader and see if that helps:

    Code (CSharp):
    1. #if _PARALLAX
    2. o.Albedo *= saturate(i.viewDir + 10);
    3. #endif
    This is basically what MegaSplat does and it forces Unity to pass viewDir in the correct space.

    MegaSplat works on meshes or Unity terrains..
     
  30. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    You have to bake out the mesh using the save mesh tool, as static meshes cannot be read from and cannot have additional vertex streams applied.
     
    JamesArndt likes this.
  31. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Is Unity aware of it / is fixing it? seems pretty horrifying really.
     
  32. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    I have a repro project in with them, and spent a fair bit of time trying (unsuccessfully) to widdle down a simple case for them. I think they look at the 13,000 line shader it's in and figure "Must be something else in there". But if you actually look at the logic, it goes something like this:

    1. Sample height from diffuse map
    2. Use height to compute parallax UV w/ viewDir
    3. Sample many other textures with parallax UV
    4.(hacky fix) use viewDir to (not) modify albedo to fix this issue..

    What I suspect is happening is this:

    viewDir is a magic keyword in Unity. When you assign something to o.Normal, it sends you viewDir in tangent space. When you don't, it's in world space. The reason is to save a matrix multiply in cases where you don't need it in tangent space.

    Complex shaders, like MegaSplat, and these, use lots of functions and structures to make the overall flow of the code easier to work with. Often, the assignment and use of these variables happens deep inside a function. Note that most of these don't exist in the final code as they are mostly syntax sugar, and things like passing a structure to a function in HLSL will actually flatten the structure into a list of floats/etc.

    So what I suspect is happening is something about these cases causes it to think I'm not assigning o.Normal, or that viewDir isn't actually used by my code, and it assigns it the wrong value. The author of Lux has reported having to do similar things with the worldPos keyword (another magic variable), which seems to back up this theory.
     
  33. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    even on a new empty project the example scenes do not work. no parallax height.
    after adding those lines of code nothing changes. i do use 5.6.1f1. am i the only one having this issue? :(
     
  34. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Does it have no effect, or the wrong effect? The bug I encountered in MegaSpat caused the effect to smear the texture in the wrong direction, not the effect to do nothing. Also, keep in mind, it's parallax offset mapping, not parallax occlusion mapping, so the effect is subtle comparatively (though should be very noticeable).
     
  35. nbac

    nbac

    Joined:
    Jul 7, 2015
    Posts:
    267
    i am aware of the fact it is just parallax offset mapping and it is not doing anything. so it is not wrong but non excistent.
    i am using uber shader now with tesselation but this is pretty heavy performance wise (uber has no pom for two layerd shader). i really like the simplicity of using your shader and i really dont get why it is not working. i have tried a lot i use ngss asset and tought this could be the cause, so i went back to old shadow lib. i am back to standard unity and like i said an empty project.
     
  36. ilesonen

    ilesonen

    Joined:
    Sep 11, 2012
    Posts:
    49
    Hi jbooth,
    I just tested out the Vertex painter and it's really amazing asset. Thank you! I'm currently working on off road driving game and the mesh deformation feature could work for creating soft ground effect for tires. Since I'm no coder would you have any examples how to make it work runtime, or is it possible?
    (I accidentally posted this first to really old wip thread of Vertex paint..sorry about that;)
     
    JamesArndt likes this.
  37. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    you are awesome for sharing this
     
  38. Alcolepone

    Alcolepone

    Joined:
    Jan 28, 2013
    Posts:
    30
    seem to get a shader compile error with the latest unity. Related to the viewDir

    "shader error in 'VertexPainter/SplatBlend_2Layer' : invaild subscript 'viewDir' at line 305 (on d3d11)....

    any ideas how to fix?
     
  39. gurbrindersingh

    gurbrindersingh

    Joined:
    Feb 28, 2017
    Posts:
    32
    Can it be used for realtime painting on mobile devices?
     
  40. Jakub_Machowski

    Jakub_Machowski

    Joined:
    Mar 19, 2013
    Posts:
    647
    have exactly the same problem Anyone fixed that? :) Will be greatful cause tool is great but that adding that component to every object is very unpredictable when working on huge scenes with many objects
     
  41. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    Is there a trick to exporting/importing painted meshes? I've got a terrain mesh that I spent a lot of time painting, and I want to move it to another project. I saved it as a prefab, selected the prefab's dependencies, and exported it. When I imported it into a new project, all of the colors/textures were scrambled. If the vertex stream data isn't getting included in the exported dependencies, where do I find it, and how do I transfer it?
     
    Last edited: Feb 10, 2020
  42. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    It's stored in the VertexInstanceStream component, though you could always save out the mesh with the utilities tab so it becomes part of the mesh itself.
     
  43. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    OK. Here's what I tried:

    1. Selected the mesh terrain in Scene view, and used "Save Meshes" on the Utility tab to create a new mesh asset
    2. Replaced the mesh component of the terrain with the newly saved asset
    3. Saved the updated terrain as a prefab
    4. Selected dependencies for the new prefab and exported it
    5. Imported the terrain prefab into a new project, and placed it in a new scene

    This is what I started with:
    Island1_original.jpg
    ...and this is what I got:
    Island1_imported.jpg
    This is the same as I got before saving the mesh out first. Any idea what I might be doing wrong here?
     
  44. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    No idea- Unity's package format is a mess, you might try just moving the files yourself. Once it's in .asset format it can't be an importer thing anymore..
     
  45. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    Hmmm... just tried that - copying the original FBX file, materials, textures, and prefab, along with their meta files, and got this:
    Island 1 copied.jpg
    It's not as horrible as the first attempts, but if you compare it to the original, the textures are still messed up, like they were placed randomly instead of using a splat map.

    I may have found a clue though - the original project was running in Unity 2018.2.5. The new project is using Unity 2019.3.0. When I created another test project using Unity 2018.2.5, the textures looked fine after either importing or copying the files. After saving the 2018.2.5 test project, I tried opening it with 2019.3.0, and the textures were again scrambled, as shown in the last picture, so it looks like something is being lost in translation from 2018 to 2019. So my question now is how can I get the files to transfer between Unity versions? Since I think you use the same or similar vertex painter in MegaSplat, has anyone else had issues upgrading assets to 2019.3.0?
     
    Last edited: Feb 10, 2020
  46. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    unity may have changed something about the fbx importer causing the vertex order or count to change. If so, saving the mesh out should allow it to transfer between versions.
     
    FargleBargle likes this.
  47. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    And yet it clearly doesn't. Whatever has changed, saving out the mesh doesn't seem to lock in the painted vertex streams. After trying various combinations of saving out the mesh, exporting, importing, and copying the resulting prefabs and other files, they all work fine in Unity 2018.2.5, and they all get scrambled as soon as I try them in 2019.3.0. If Unity changed the FBX importer, it looks like a breaking change for anyone with a previously painted mesh - unless I'm the only one this is happening to. It seems pretty consistent in all of my tests though.
     
  48. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Well if you baked it out you're not using the FBX importer. It may be that they changed the internal mesh format in some way, and revision existing meshes stored in assets to this new format.
     
    FargleBargle likes this.
  49. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    Ahhh, but I was. By simply replacing the original imported mesh component on my prefab with the saved out mesh asset, I was still apparently dependent on the original FBX file it was made from. After creating an empty game object, and manually adding the saved mesh filter, renderer, and material, the new prefab no longer had any FBX dependency, and could import cleanly into 2019.3.0. Thanks for the help.
     
  50. ZackTwisted

    ZackTwisted

    Joined:
    Sep 29, 2017
    Posts:
    6
    Hello!
    I'm having an issue with vertex painting and GPU Instancing. I have 3 planes painted in simply different ways:

    upload_2020-2-13_10-35-28.png

    The problem is when enabling GPU Instancing, they all have the same vertex paint information and they look like this:

    upload_2020-2-13_10-36-24.png

    I'd like to enable GPU instancing and be able to have different vertex data in each mesh, so I would be able to draw grass and dirty in different scenarios with the very same material.

    How could I work a way around?

    Thanks!
     

    Attached Files: