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.

Paint In 3D ️️✏️ In Game & In Editor & Skinned Mesh Painting

Discussion in 'Assets and Asset Store' started by Darkcoder, Jul 10, 2018.

  1. AndrewRoto

    AndrewRoto

    Joined:
    Jul 7, 2021
    Posts:
    4
    Did some more digging. It appears that to get the Points On UV mode to work properly in build the mesh asset needs to have Read/Write Enabled in it's import settings. I now have this up and running. I might have missed a section on asset preparation for this.
     
    Darkcoder likes this.
  2. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Aha, yes someone pointed this out before. This is on the to-do list, and I will add some sort of inspector warning in an upcoming version.
     
  3. manscomgamedesign

    manscomgamedesign

    Joined:
    Feb 17, 2021
    Posts:
    21
    Thanks for your reply, I have used a shader editor to test out a few shaders and I think I am now understand how it works.
     
  4. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Great, let me know if you encounter any issues with the painting!
     
    manscomgamedesign likes this.
  5. pastersteli

    pastersteli

    Joined:
    Dec 9, 2020
    Posts:
    5
    Hello, There is a problem with changecounter. Can u help? @Darkcoder
     
  6. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Sure, if you provide some details.
     
  7. AndrewRoto

    AndrewRoto

    Joined:
    Jul 7, 2021
    Posts:
    4
    We're using this on a mesh that has a secondary UV and getting this bizarre effect where it applies a screen instead of a regularly applied color to the Mesh, and only on the meshed that are using the secondary UV. This can be seen in the linked GIF below:

    https://imgur.com/a/dLMmVa8

    Our other meshes aren't having this issue where the screen is applied and have a pre-multiplied application as intended.

    Are we setting values up incorrectly? Is there a way to get the UV to use the same effect as the base? Or is this made this way by design? I have attached below the material settings. It and the mesh being used are the only differences between the meshes when it comes to painting settings.

    upload_2021-10-14_15-14-18.png
     
  8. piegaro

    piegaro

    Joined:
    May 17, 2017
    Posts:
    10
    Hello, thanks for this cool asset.

    For some reason, the rear of my horse mesh cannot be painted in-game (using the usual P3D Hit screen & P3D Paint Sphere), where it is working absolutely perfectly in the editor (Via the Paint in 3D window). Any idea why?
     

    Attached Files:

  9. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    It's hard to say what's happening without seeing your full setup or a test scene. The painting modes should behave the same regardless of the UV channel and mesh you specify.


    In in-editor painting uses the visual mesh for painting via Unity's super secret internal editor-only API. However, in-game painting uses physics raycasts, which use colliders. You only have a BoxCollider on your horse, which probably isn't precise enough to paint the mesh relative to the size of your paint brush. To fix this you should use a MeshCollider, or some kind of compound collider from individual colliders on each bone. You could also use the technique shown in the "Zombie Blood" demo scene, which uses a stretched decal that still works with just a BoxCollider, but it has some drawbacks like painting through everything under your mouse/finger.
     
  10. pastersteli

    pastersteli

    Joined:
    Dec 9, 2020
    Posts:
    5
    When I start the game, count start higher but texture has nothing changes. but When downsample step is 0 there is no problem. It causes performace problems I want to make higher but there is a problem.
    upload_2021-10-16_13-29-20.png
    upload_2021-10-16_13-31-1.png
     

    Attached Files:

  11. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    If I modify the "55 Change Counter" demo scene to match your settings, it works as expected. I see no real difference between DownsampleSteps = 0 and = 3. Let me know what I'm missing so I can replicate the issue.
     
  12. pastersteli

    pastersteli

    Joined:
    Dec 9, 2020
    Posts:
    5
    try to use this texture with cutstom replace painter and on 512 *512. try with downsample 0 and 6 . threshold 0. Counter will start with high values on downsample 6
     

    Attached Files:

  13. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    512x512 downsampled 6 times is an 8x8 texture. I don't think this is enough pixels to give any accuracy for counting pixels. Does it work for lower values?
     
  14. pastersteli

    pastersteli

    Joined:
    Dec 9, 2020
    Posts:
    5
    no, not working. Also there is no change for 8x8 but look like changed. counter not starting from zero even for 1 downsample
     
  15. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    I've attached a package that shows the change counter with the setup you describe, and it works fine for me. Let me know what needs to be changed to replicate the issue.
     

    Attached Files:

  16. pastersteli

    pastersteli

    Joined:
    Dec 9, 2020
    Posts:
    5
    I tried your example. Only difference is texture settings. I figure out now the problem. when I reset the texture settings, problem solved.
     
    Darkcoder likes this.
  17. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Sorry for the delay. I found time to debug and fix the issue, it should now be live in Version 1.11.11 :)
     
  18. lawsonh

    lawsonh

    Joined:
    Jul 25, 2018
    Posts:
    76
    Wow! great news. Thanks so much
     
    Darkcoder likes this.
  19. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    65
    Hello, I'm creating a game where people build vehicles by putting together blocks, and I am thinking of using your asset for it.

    I would like to apply a texture to cover the entire vehicle that the player has built from the blocks, so it fits the entire vehicle as a whole. For example, the way a tank's armour looks like it was moulded from one large piece of metal.

    Here is a bit more about the game. The player will be able to select blocks of different shapes and sizes (e.g. corner blocks, flat blocks) from a menu, and combine them together to make the shell of a vehicle, such as a tank. I'm not sure if I've gone about this the right way, but each individual block has a material to make it look like a painted metal.

    The way the tank is built is by adding each block as a child of the main vehicle game object (which is the first tank component to be placed - in this case the tank tracks). So the tank ends up with about 20-30 blocks as children game objects that make up the hull. At the moment, each of these blocks has its own material, and as a result the blocks produce a tiling effect, as the pattern on each block's material does not match up with its neighbours.

    What I would like is for the whole tank to not have this tiling, so that it would seem to be made out of one piece of painted metal. I am looking for a way of either making each block's materials match up so the tiling disappears, or have one material that just covers all of the tanks blocks, so it looks like the tank is made out of one piece when it is finished.

    Would your Paint in 3D asset be able to help me do this?

    Thank you for your help.
     
  20. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    What you want is a triplanar mapping shader. This will make all blocks appear as though they're part of one continuous material, and it wouldn't even require you to UV map them, and it wouldn't require any additional texture memory.

    Paint in 3D has a triplanar painting mode, but to use it in your scenario you would have to merge all the blocks into one mesh, generate or at least move around each block's UV so there is no UV overlap, and then create a paintable texture for each tank and then paint it all. This would be fairly difficult and would only be advised if your game also needs decals, paint, and other features of the asset.
     
  21. Uncochonvolant

    Uncochonvolant

    Joined:
    Oct 13, 2021
    Posts:
    1
    Hello Darkcoder, thank you for the great asset!
    I encountered some problems when using it to make an archaeological interactive game. I hope that the user can use the mouse to color the stone. (The colored texture will gradually appear wherever the mouse goes, and the colored texture will gradually disappear when the mouse has moved away.)

    I want to use the functions in Sample49: Reveal Original and Sample 88: Delayed appearance at the same time, but judging from the brush blending mode, it seems to be impossible.:(
    Do you have any suggestions for me? Thanks!

    (The attachment is the effect I have achieved with Sample49: Reveal Original, but now the color on the stone can't gradually appear, it appears directly, which makes me very distressed.)
     

    Attached Files:

  22. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    65
    Hello, thank you for the information.

    I will look into triplanar mapping shaders. They sound exactly what I need.

    I actually bought your asset some time ago, as I liked the idea of giving players the opportunity to customise their tanks by painting them and adding decals. From what you said, this could be difficult with how my game is set up. If I get a triplanar mapping shader working for the tank's overall general texture, would it be possible to use Paint in 3D just for decals and maybe a bit of paint work to be added by the player on top of it?

    I have made the tanks blocks in Blender, and each has its own UV (in fact I followed how the UV is set out in your first example, so they are hopefully well placed out). I am also thinking about merging all the block meshes when the player has finished assembling the tank (I have the Mesh Baker asset which can do this). If I did try and use Paint in 3D for the tank's overall texture, would it be possible to then create a paintable texture for each tank and then paint it from code? This would need to be done before the player takes control of the tank and starts using it. If these procedures were done by code, could then player then be able to paint and apply decals?
     
  23. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    The "88 Delayed Appearance" configuration can be used with any blending mode or paint tool. You probably haven't configured your object properly. Look at the child GameObjects of the Spaceship in this scene and you will see a it's a little complex.


    Yes this would work. Keeping the blocks separate would also be easier as you wouldn't have to adjust the UVs after. One thing to keep in mind is that main use-case for a triplanar mapping shader is if your mesh is too complex to UV map, then you can use this technique to apply textures without any UV data. However, Paint in 3D requires UV data, so your shader would have to apply triplanar without UV, and then apply your painted texture on top using UV. This would most likely require a custom shader.

    Another approach is to just keep your blocks separate, and paint them all with Paint in 3D's triplanar mapping tool. This allows you to use almost any shader, and will allow for painting and such as long as each block is UV mapped. Of course this means you must actually paint each block, so your game's texture memory will increase depending on the resolution of the texture on each block.
     
  24. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    65
    Thank you for the information. I think I will go with your first approach, and use a triplanar mapping shader for the finished tank (with the blocks kept separate), and let the player apply Paint in 3D on top.

    As this will require a custom shader, I will try and learn Unity's shader graph and make one using that. Do you think it will be possible to make this type of shader in shader graph, and will it still be compatible with Paint in 3D?

    I will also have to switch from using the built-in shader to using either URP or HDRP, so that I can use shader graph. From the perspective of performance, which of the options - URP or HDRP - give better performance when using Paint in 3D? There is quite a lot going on in my game, so I would like to have things as optimised as possible. My game will be targeting PCs only.

    Thanks for the advice.
     
  25. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Yes, this should be easy to implement with Shader Graph since I believe it has a triplanar mapping node built in. The only tricky part would be combining the painted texture on top of the triplanar texture. This would be done by 'lerp'ing the triplanar texture into the painted texture using the painted texture's alpha channel as the lerp weight. This is how the Paint in 3D / Solid shader works with the override Albedo/Normal/etc textures.

    The performance of Paint in 3D is identical in all render pipelines. Also, I believe Shader Graph is being ported to the built in render pipeline, not sure which version of Unity it's in or will be in though.
     
  26. GreaterHawkeye

    GreaterHawkeye

    Joined:
    Apr 13, 2017
    Posts:
    31
    Hello @Darkcoder !

    I've got a question :)

    I'm using your plugin which works really great. I'm painting on 3D animals models. Each parts (eyes, legs, head...) has the components that allow painting.
    However, I've noticed that when I draw on some location it is much more aliased than other locations. For example the arms are smooth but the head is aliased. Here is an image:



    Do you know the cause of that? Better unwrapping? The 3D modeler says the unwrapping is correct.
    We also tried to increase the texture size on the components but it seems that it does not apply on the models...
    I will send you a link in DM to test the tool we implemented as well as the a model we are using.

    Thank you very much :)
     
  27. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    The unwrapping is pretty good. The issue is that each part is a separate object and you're probably using the same resolution P3dPaintableTexture despite each part being a different size. Here's what it looks like with the same resolution checkerboard texture applied:

    upload_2021-10-25_22-42-9.png

    As you can see, the eyes would have 10x more detail than the head. To fix this you must manually adjust the resolution of each so they have the same texel size based on your desired resolution. Also, I notice the back/tail has around 3x the resolution of the front, so you might want to remap that to be more consistent, or to increase the detail at the front assuming that part is more important.
     
  28. GreaterHawkeye

    GreaterHawkeye

    Joined:
    Apr 13, 2017
    Posts:
    31
    Thanks Darkcoder!
    I'm unsure where to change the resolution size.

    I tried to change that setting :


    But it looks like it does not affect the resolution.
     
  29. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    65
    That's great that it all sounds possible to use the triplanar mapping shader and Paint in 3D. Looking forward to trying it out.

    Appreciate your help!
     
    Darkcoder likes this.
  30. Lemovision

    Lemovision

    Joined:
    Apr 6, 2020
    Posts:
    32
    Hi, impressive asset

    I'm interested in making a 3d painting app
    And I think pen pressure is very important for proper painting to control brush size variation
    But it doesn't seem to be supported here? which I find strange for an asset specialized in painting
    I mean how far is it humanly possible to paint with a mouse, beside child-style drawing?
    The pen for now can be used to draw, but without pressure sensitivity for details it's not great
    Even this forum title has pen ✏️ in it, yet it's still not fully supported?

    If you still don't have a pen tablet, I'd recommend investing in one, since you're making a Paint asset
    You can get good quality Wacom small size tablet like this for just one sale of this asset
    This way you could easily test it out, and make this asset far more precise with pen support

    https://stackoverflow.com/questions...essure-values-in-unity-using-s-pen-on-android
    https://docs.unity3d.com/Packages/com.unity.inputsystem@1.1/manual/Pen.html

    I did try to read the pen pressure myself in Unity, to eventually link it to the p3d pressure modifier
    But I'm just getting 0 pressure with that method still (although it works in Unity input debugger)
    So integrated support for pen pressure out of the box would be good for this asset indeed
     
  31. wonderscope_rob

    wonderscope_rob

    Joined:
    Feb 20, 2016
    Posts:
    11
    Hey! I'm having issues with Undo and I was hoping you could give me some tips of where to look to figure out what's going on.

    Essentially If I use UndoAll, then store a new state, and undo again, the prior state will also be removed.


    In this image i'm painting three lines, using UndoAll, painting another line, and then Undoing again (which removes the latest step and the one before)

    Simply put the code runs as follows:
    On Update:
    if Mouse button Down this frame:
    - call P3dPaintableTexture.StoreState();
    - call P3dPaintDecal.HandlePoint();
    - return;
    If Mouse Button is currently down
    - call P3dPaintDecal.HandleLine(from previous point to current);

    I call P3dStateManager.UndoAll(); to perform an undo action

    I've checked and neither StoreState nor UndoAll are being called outside of these timings, so I can't quite figure out what's going on.

    I realise this isn't much information to go on, but do you have any tips for where I should start digging to find out what's happening? Or any idea what this could be?

    Happy to provide more info if needed! Thanks!
     
  32. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Yes, that is the setting. If I open the "80 Flow" demo scene and change this setting on the Plane GameObject, then it works as expected.


    The in-editor painting and touchscreen finger painting features use the pressure values provided by Unity. Whether Unity provides correct values for these when using a pen I don't know because I don't have a tablet. The in-game non-finger data uses the mouse values Unity provides, which doesn't include pressure (though as you point out you can probably access it via the Pen data with the new InputSystem package). Maybe in your use case it seems ridiculous for this asset to not have direct code to support a pen, but I don't think many people are making games with this in mind. From what I recall every inquiry to date about tablet support was in the context of in-editor painting which should work unless Unity's event system doesn't provide this data for some reason. When I have more time I will look into this, but if almost nobody seems to want a specific feature then I'm not going to rush to spend money in order to implement it.


    I can't replicate the issue. See the attached demo scene: you can draw 3 lines, press F1 to UndoAll, and then paint again as expected.

    However, I do notice if UndoRedo = LocalCommandCopy then the draw order can change, so maybe that has something to do with it?
     

    Attached Files:

  33. Lemovision

    Lemovision

    Joined:
    Apr 6, 2020
    Posts:
    32
    Hmm how about the very first reply for this asset for example?
    I suppose he's talking about pen pressure support in game (iPad) rather than in editor
    Anyway he seems to have found a way apparently so I'll also ask him
     
  34. dariuspowell

    dariuspowell

    Joined:
    Jun 11, 2015
    Posts:
    21
    Hello.
    I'm looking into using Paint as part of a large scale installation. Do you think the following could be possible:

    multiple brushes in a scene controlled by float data instead of mouse? I have data from colour tracked objects that I want to assign a coloured brush each. Is it possible to have multiple brushes in one scene and any ideas around how I could control brush position via float? I can figure it out if the brush can follow a dummy object for example.

    Any advice would be appreciated.

    many thanks
    Darius
     
  35. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    Not sure what you mean by float data, like a Vector3 position? The P3dHitNearby component can be used to apply sphere/decal painting at the current GameObject/Transform position, so you could position this using your custom data easily enough. This would work with any number of objects.
     
  36. dariuspowell

    dariuspowell

    Joined:
    Jun 11, 2015
    Posts:
    21
    Hi thanks.

    I'm getting tracking data data in via OSC that will represent XYZ positions as float values. I have those values moving a gameobject and so I will look into using P3Dhitnearby on it.

    Many thanks
     
  37. Faizalski

    Faizalski

    Joined:
    Oct 4, 2018
    Posts:
    17
    @Darkcoder Hi. Awesome tool by the way. I've got a question about the procedural approach of your awesome tool. Is there any way that I can add a replace texture done via code to the undo list?
     
  38. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    No problem, this is shown in the "37 Nearby Painting" and "60 Live Painting" demo scenes.



    If you call the PaintIn3D.P3dStateManager.StoreAllStates() method, then you will be able to undo all paint you apply after that.
     
  39. Faizalski

    Faizalski

    Joined:
    Oct 4, 2018
    Posts:
    17
    [QUOTE="If you call the PaintIn3D.P3dStateManager.StoreAllStates() method, then you will be able to undo all paint you apply after that.[/QUOTE]

    Brilliant. Thank you very much for that pointer. Will give it a shot.
     
    Darkcoder likes this.
  40. Faizalski

    Faizalski

    Joined:
    Oct 4, 2018
    Posts:
    17
    Hi @Darkcoder. Is there a way to have an unlit material for the paint texture? I can't see any variant in the materials folder that would have such an attribute. Thank you in advance.
     
  41. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    You can use any material/shader, for example the Unit shaders that come with Unity should work. Unless you need the albedo override texture feature from the Paint in 3D versions?
     
  42. Faizalski

    Faizalski

    Joined:
    Oct 4, 2018
    Posts:
    17
    Wow. Paint3D rocks. It's just that easy. Thanks, Darkcoder for your prompt response.
     
    Darkcoder likes this.
  43. Lemovision

    Lemovision

    Joined:
    Apr 6, 2020
    Posts:
    32
    Hi, so now I can read the pen pressure from my tablet with Pen.current.pressure.ReadValue()
    And then I apply this to the scale factor of the P3D paint sphere, making these dynamic lines
    It works when painting slowly, but since I just apply it on Update every frame,
    on fast strokes (bottom one in pic) the size doesn't update at every single hit point during the stroke
    Where could I apply this in your scripts to apply pressure levels constantly?
     

    Attached Files:

  44. GreaterHawkeye

    GreaterHawkeye

    Joined:
    Apr 13, 2017
    Posts:
    31
    I have exactly the same problem.

    Also, if an object has "Save/Load" applied, it removes the loaded texture when doing the first undo as well as the stroke I just made.
    This behaviour occurs only when using "Local Command Copy". I prefer not to use the FullTextureCopy for performance issue.
     
  45. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    You'll have to disable the Advanced/ConnectHits setting. Connected hits extrude the current hit to reach the last hit point, they don't have the ability to blend to the previous size, color, hardness, etc.



    I'll send you a test build that may have this fixed.
     
  46. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    65
    Hello. I wrote to you last week about a game I am making where players create tanks from blocks.

    I have made a shader in Shader Graph that uses triplanar mapping to make a continuous texture for all the blocks (so seams don't show between them), and then blended this with a texture using Paint in 3D. This all works well, as I can now paint across blocks.

    However, the paint placed by P3dPaintSphere is tinted by the triplanar texture underneath. Is it possible to have the paint not be affected by the base triplanar texture? I have had a look at example 10 in your asset, which deals with tinting by changing the colour or texture in the P3dPaintableTexture component. However, this does not seem to work in my case, as changing these either has no effect on the tinting, or overwrites the triplanar texture.

    I have also tried altering the blend mode, but this also has no effect. Would you have any suggestions for stopping the tinting?

    Thank you for your help.
     
  47. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    It sounds like you're multiplying the colors together, which will cause this issue. You must replace the base color with the painted color, which can be done using lerp, with the painted opacity/alpha as the lerp factor.
     
  48. DromoDesigner

    DromoDesigner

    Joined:
    Mar 27, 2016
    Posts:
    65
    I was having a bit of trouble doing that with the 'Lerp' node in shader graph - they might have changed how it works recently (or more likely I still don't know which button to press :)).

    However, after tweaking the 'Blend' node's settings, I found that using the Overwrite option did the trick. There are 22 different settings on the blend node, so it took a bit of time to find the right one.
     
    Darkcoder likes this.
  49. villaman

    villaman

    Joined:
    Apr 21, 2021
    Posts:
    58
    Hello, a couple of questions.

    I know there has been some discussion around a polygon tool and some of the challenges around it in the general case. However, I have a flat surface (think whiteboard with an image on it) and I could definitely put it into a head-on orthographic view if that helped. With these constraints is there a straightforward way to draw a polygon around (say) a part of the whiteboard at runtime?

    My goal is essentially to allow the user to remove the background in a photo by setting the pixels outside the polygon as transparent.

    If there is no easy way to draw a polygon, if I were to implement that on my own, would there be an easy way to "fill" the outside of the polygon (provided in say a List<Vector2>) with transparent pixels?

    The second question I had was around whether decals could be resized at runtime by the user?
     
  50. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,063
    The 'quad' painting technique can be used to paint triangles, you just need to make two of the points overlap. This is how the triangle painting demo scene works.

    In your scenario you would need to allow the user to draw a polygon, and then you would need to implement something like constrained delaunay triangulation to generate triangles for the area outside the polygon. You would then 'paint' the triangles outside the polygon so that they remove alpha from your whiteboard.

    If you look at the Live Painting demo scenes, you can see the P3dPaintDecal settings can be adjusted in realtime before you actually 'apply' the paint. Modifying paint that's been applied is also possible, but it's much more difficult as you would have to modify the raw paint commands and rebuild the texture.
     
unityunity