Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

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

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

  1. simplelogiccompany

    simplelogiccompany

    Joined:
    Jul 22, 2019
    Posts:
    21
  2. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    You can create size/opacity/etc sliders as seen in that video using Unity's built-in UI Slider component. This component gives you the OnValueChanged event, which can send a float value to a component in the scene, for example the P3dPaintSphere/Decal component's Opacity setting:

    upload_2021-4-18_23-28-46.png

    You can then add a second event handler that changes the UI CanvasGroup opacity to make it show up in your UI too.

    You can do the same thing for the Radius setting too. However, there's no built-in way to change the radius/scale of a UI image from a single float value that this event gives you. For this you will have to write a simple script that converts a float into a Vector3 for the transform.localScale. Another option is to write a script and point it to the P3dPaintSphere/Decal component, and have it read and apply the opacity/radius/etc settings to your UI element, that way you only have to set up those events once and they will always be in sync.
     

    Attached Files:

  3. simplelogiccompany

    simplelogiccompany

    Joined:
    Jul 22, 2019
    Posts:
    21
    Ok I understand how to implement changing size and opacity. But i dont understand how to implement Hardness in image. In 2D/3D Paint Asset this implement with RenderTexture and RawImage.

    In your asset it is not reachable, beacouse is hiden in code. I Find where you draw on Quad preview of brush in RenederTexture and Apply to the PaintableTexture. But i dont understand how i can get this RenderTexture of brush preview?
     
  4. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    I'm not sure I understand. The P3dPaintableTexture component has the .Current and .Preview properties, which tell you the current paint state. The paint drawing itself is pretty low level and is handled in the ExecuteCommands method.
     
  5. XB23

    XB23

    Joined:
    Sep 12, 2018
    Posts:
    12
    Hello, I already posted several times and I'm still using your wonderful asset in my app. I would like to ask if you know the answer for my problem.

    In my app, I want to draw with the mouse, my finger (on a surface studio pro) and with a pen (the pen from the surface studio pro). It works well with the mouse and pen, but when I draw multiple straight lines (it is an example) with my finger, it draws a line between the last cursor position and my new one. So I would like to stop this link between my last point and the first point of my newly drawn line (or don't draw this first "false" point in order to stop the link).

    Best regards!
     
  6. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    This is already implemented in the P3dHitScreen component. When a finger/mouse goes up (line 153) it calls the connector.BreakHits method (line 157), which disconnects the current line from the next one.

    Based on your description it sounds like the Surface Duo Pen isn't sending the 'up' event, so it never disconnects the lines. Are you using the legacy input system in your project? If so, you may want to try the new InputSystem package. If it still doesn't work then perhaps the 'up' event would have to be implemented separately for this, like using the pen pressure or similar.
     
  7. XB23

    XB23

    Joined:
    Sep 12, 2018
    Posts:
    12
    It's not the pen the problem, I have this link problem with my finger on the touchscreen. I just checked, I go through the finger/mouse up check but it still have those lines. It draws a line between my last finger position (so it's the cursor position) and my new finger position, if I draw two vertical lines starting by the bottom, it draws me a "N". Also if I draw a line with my finger, I move the mouse cursor by moving the mouse without clicking, and then I re-draw with my finger, it links the last position of the mouse's cursor with my new drawing.

    Thanks you for your answer !
     
  8. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    Hmm, maybe I made a mistake with the code. I seem to have forgotten to bring all of my test devices with me, so I'll test this next week.
     
  9. anton88pro

    anton88pro

    Joined:
    Jul 20, 2017
    Posts:
    55
    Hello!
    I've recently purchased the asset and so far I find it quite confusing.
    I want to use it to make my scenes more interesting by paining a dirt/mold or adding graffiti decals which would effect albedo, normal and smoothness maps. After spending several hours and going through every inGame and inEditor tutorial scenes and reading manual I'm still left confused on how to achieve my task. There are many confusing parts, like how to export a drawn normal map(seems like we can export only albedo png), why i can choose only "basic - AA" preset or my preset (with normal group) does nothing , is it even possible to draw a normal map using "Paint in 3D" window or I need to follow inGame method and there are many other confusing parts.
    It would be the best if the author could make a video tutorial or at least step by step tutorial on achieving the task.
     
  10. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    Looks like I didn't correctly set up all the textures for the presets. Basically, each preset defines a set of textures that can be painted, and these textures each use a specific paint group. Each paint group has a list of shaders and texture slot names that use that group, and if any of these are missing then the preset doesn't appear. For now I've made two new presets called Normal, and Albedo + Normal. I'll send you an early copy of it in a second.
     
  11. 13E12K

    13E12K

    Joined:
    May 4, 2014
    Posts:
    15
    Hi there,

    Just got Paint in 3D to draw some holes on a double sided cloth, which I use with its own specific shaders. I am not so much familiar with shaders, but to be able to use your drawing hole effect in "Fireball Holes" scene with my double sided cloth, what should I add to the attached shader code additionally?
     
    Last edited: Apr 25, 2021
  12. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    You can add this to your surf function: Clip(c.a - 0.5f);
     
  13. 13E12K

    13E12K

    Joined:
    May 4, 2014
    Posts:
    15
    Thank you @Darkcoder , it works now.

    By the way, is this very forum thread the only place for support or there is other platforms for support like Discord or a website?

    My question is I have used the reference fireball hole effects to create teared and ripped sail cloth effect. It worked OK as in the first picture. However, although having high hardness all the holes are more or less spherical cut holes in the end. What I am targeting is to have more random and irregular cutlines like in the second picture, where I used a custom texture with stencil to have untidy cutlines.

    Is there any chance to achieve this kind of effect? (I tried tile texture with no success)
     
  14. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    You can also do email or private message, but the forums are probably best.

    If you're using P3dPaintSphere then the tiled texture is your only option. You can instead use P3dPaintDecal though, which allows you to choose any shape. You can also use a modifier to rotate and/or offset the hit. Just keep in mind the decal is basically an extruded sprite, so it must be rotated correctly (e.g. facing down its movement direction).
     
  15. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    248
    Hello Darkcoder

    I have a question about the resolution of the paintable texture
    upload_2021-4-25_20-43-29.png

    Previously when I first started to use the asset I was using a resolution of 512 for the paintable texture, this was working fine and my textures were looking on full resolution as if they were 4k. So I was understanding the actual texture is actual 4k and only the paintable texture was 512.

    On a later update things broke, now all my textures were low resolution and they were looking exactly as I set the Paintable Texture to be, this is 512x512. Hence I needed to change them to be 4096x4096 and then they looked fine again.

    So my question is, Why on a previous version I could manage to have a 512x512 paintable texture and still have my textures to look like 4k?

    Since now I have to set them to 4096 I am concerned about performance, on the past when I set them to 512 there was not performance issue, I haven't tested now but I am worried having the paintable texture at 4096 will have issues.

    Thanks for your clarification and advice.
     
  16. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    Which version is 'previously' ? I don't think I've changed this code in at least a year. To my knowledge the size you specify there has always been the resolution that the texture is created with. There's no way to paint a lower resolution and have it somehow appear on a higher resolution texture unless you use some kind of material or shader technique to combine two separate textures together. For example, the "08 Overlay" and "09 Override" example setups are both capable of painting a lower resolution texture and applying it on top of a higher one.
     
  17. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    248
    It was June 2020 when I first started using it and it was working like that. Maybe it was a bug and it always used the 4k resolution so now it is working fine and is using the specified resolution. Could you confirm this?

    Do you think there is any performance issue by using them at 4k?

    Regards
     
  18. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    248
    Another question related to the previous one, how do I work with Quality Settings so that Paint3D textures not always generate 4k textures but instead it generates the size according to the quality settings?
     
  19. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    I just tested version 1.8.7 which was released at the end of May 2020, and the texture size behaves the same as it does in the current version.

    A 4096^2 texture will be up to 64x slower to paint than a 512^2, since there are 64x as many pixels to process. The GPU may be able to discard most of these pixels though, and depending on your UV many of these pixels may not be drawn at all, so the performance impact may not be linear. To optimize this you can split the mesh up as detailed HERE.


    You would have to adjust the Width&Height of each P3dPaintableTexture via script. Currently none of the components read the quality settings. I could add some kind of setting like this though, perhaps to the P3dPaintable component.
     
  20. Hazneliel

    Hazneliel

    Joined:
    Nov 14, 2013
    Posts:
    248
    Thanks, I already have my mesh splitted into 8 4k textures, this is why I am concerned about performance.

    Thanks for the suggestion, I will add a Script to read from quality settings at the time the GameObject gets initialized. It would make sense P3dPaintable would do that and read from settings so it can use half or 1/4 resolution according to the quality settings.

    Thanks again for the help
     
    Darkcoder likes this.
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    Hey everyone,

    Version 1.10.5 of Paint in 3D is now out!
    • Added P3dSerialization class for easier low-level de/serialization of paint commands.
    • Modified P3dCommand data to allow for de/serialization.
    • Added more Paint in 3D window material presets.
    • Added PaintIn3D window material export button to speed up exporting.

    Some nice low level changes here that make de/serializing commands much easier now.

    The Paint in 3D window has also been simplified, so you can set up your objects and save their textures to assets with far less clicks (see the docs HERE).

    Enjoy :)
     
    Hazneliel and 13E12K like this.
  22. 13E12K

    13E12K

    Joined:
    May 4, 2014
    Posts:
    15
    Thank you Darkcoder, I am quite enjoying Paint in 3D so far.

    Right now, for a multiplayer project I need to have several clone instances of a ship with atlas mapped sail textures. What is the best approach to use Paint in 3D at such constraits?

    I think I have hit to a limitation that no more than one instance can be used with atlas painting?!
     
  23. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    I'm still not sure I understand your issue with the ships.

    If your atlased ship works fine with one ship, then it should work fine with any number of ships. The only requirement is you must use the P3dMaterialCloner (it looks like you do).

    This is what should happen:

    Before P3dPaintable and P3dMaterialCloner activates.
    Ship 1 = Material A
    Ship 2 = Material A
    Ship 3 = Material A

    After P3dPaintable and P3dMaterialCloner activates.
    Ship 1 = Material A (Clone 1)
    Ship 2 = Material A (Clone 2)
    Ship 3 = Material A (Clone 3)

    As you can see, each ship will have its own material, so there should be no conflicting paint or materials, because each ship will have its own unique textures and materials.
     
  24. 13E12K

    13E12K

    Joined:
    May 4, 2014
    Posts:
    15
    I am not sure, but maybe because I am using networked objects, in my case the setup is like that:

    Before P3dPaintable and P3dMaterialCloner activates.
    Ship 1 = Material A
    Ship 2 = Material A
    Ship 3 = Material A

    After P3dPaintable and P3dMaterialCloner activates.
    Ship 1 = Material A
    Ship 2 = Material A (Clone 1)
    Ship 3 = Material A (Clone 2)

    So, as a result, since local player is Ship 1 in each instance, local players own sails cannot be painted.
     
  25. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    Why would Ship 1's material not get cloned? (though it shouldn't matter if it doesn't) Also, unless your multiplayer solution is somehow syncing the materials it shouldn't matter that your game is multiplayer. With Photon for example, unless I'm mistaken each networked object will be spawned as a prefab clone, and therefore each client will have its own unique materials and paintable textures, and only the transform position and other explicitly defined values will be synced.
     
  26. 13E12K

    13E12K

    Joined:
    May 4, 2014
    Posts:
    15
    Solved the issue. Nothing to do with Paint in 3D :) The material is being updated by other scripts in game. Thank you for your support!
     
    Darkcoder likes this.
  27. knas01

    knas01

    Joined:
    Feb 24, 2018
    Posts:
    175
    Hi, I'm wondering about meshes created by tiling on splines. Since those are generated by scripts they don't behave as I want so I probably have to use Unitys fbx exporter to make them one single mesh. I'm afraid that will create UVs that may mess up painting. Is there anything you could suggest me so I don't end up with a bunch unpaintable meshes?
     
  28. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    In this scenario you must generate lightmap UVs (second UV channel) for your meshes, and then use a custom material to apply the paint on top of your base texture using this second UV channel. This is mentioned in more detail in the documentation HERE, and also the "07 Auto UV" + 08 + 09 demo scenes.
     
  29. knas01

    knas01

    Joined:
    Feb 24, 2018
    Posts:
    175
    @Darkcoder Thanks. I just glanced at it for now but I got one more question from it. If I want to paint all my objects, to simulate damage during play with a custom shader, but only want it temporary then removed and then repeat; what would be easier for me if I constantly make changes to my meshes and textures? To use the normal way or always use the 2nd channel for everything?
     
  30. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    It depends what you mean by temporary and then removed and repeat. An example video would be helpful. The "Live Painting" for example is temporary.

    The secondary UV channel technique is ideal for objects that have UV data unsuitable for painting. For example, a character model is typically UV mapped so each triangle has a unique UV area and no overlap, which makes it perfect for painting. Whereas a building or wall will typically have weird UV data that includes tiling, and/or only use small sections of the texture space. In this scenario it's best to use secondary or lightmap UVs, which are more suitable for painting.
     
  31. knas01

    knas01

    Joined:
    Feb 24, 2018
    Posts:
    175
    @Darkcoder Well, I meant that I only want the paint material to be temporary. I spawn and desapwn prefabs and each time I do this I'm going to remove all paint. But to make it simpler, can you recommend a workflow that creates as little extra work for me as possible if I decide to make (large) changes to my meshes, textures and prefabs? The most flexible way more or less.
     
  32. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    I see, you can just call the Deactivate() method on the P3dPaintableTextures and P3dMaterialCloners, or just the P3dPaintable to undo their activation. Should work well with prefab clones and stuff, unless I misunderstand your scenario?
     
  33. knas01

    knas01

    Joined:
    Feb 24, 2018
    Posts:
    175
    @Darkcoder Thanks, I think you got it. I'm just worried not fall into an unseen trap there I have to redo tons of stuff. That's something I've found is very likely when you try to work with shaders mixed from different devs. That's why I'm worried about UVs and whatnot.
     
    Darkcoder likes this.
  34. thecali

    thecali

    Joined:
    Jan 21, 2014
    Posts:
    6
    Hi @Darkcoder!
    First, i want to thank you for your excellent add-on. Works flawlessly and is so much fun to play around with!
    My question is: Is it possible to access the painted texture in another material/shader that isn't used by the painted mesh? Let's say i have an object on which i paint a mask in real-time. This mask should also be used by another object with another material. Is this possible with p3d?
     
  35. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    Yes, but you would have to use a little custom script to apply it. The P3dPaintableTexture component's .Current property tells you the current texture state applied to the object, so you would just yourMaterial.SetTexture("texture name", yourPaintableTexture.Current) to apply it. Keep in mind you may want to clone (e.g. in Awake) the material you're applying to if it's used multiple times, and if you're applying it using the material reference stored in a MeshRenderer or similar then you would want to access the .sharedMaterial property so the material isn't constantly cloned every frame.
     
  36. Zucc0

    Zucc0

    Joined:
    Mar 25, 2015
    Posts:
    2
    Hi there @Darkcoder

    I'm trying to make example scene VR HLVP work with XR in an Oculus Quest 2 device. I'm probably doing something wrong, I can tell you that If I configure my project from Project Settings -> Player -> Virtual Reality Supported enabled it works perfectly, but this setting is deprecated and I need my project working with newer XR Plug-in Management (I'm using Unity 2019.4.16f1).

    Any ideas? Thanks in advance.
     
  37. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    The current VR examples are only designed for the old XR system. I plan to separate the VR code and demo scenes so I can more easily modify them to work in both or just the new system, but it's quite a bit of work so I haven't started doing that yet.

    It's my understanding that this new XR system comes with components to position a GameObject for the controller and/or tools, so you should be able to already integrate Paint in 3D without any custom code. For example, the P3dHitThrough component ("32 Through Points" demo scene) can be attached to some kind of VR object and it will paint anything. The only tricky part is connecting a trigger to turn paint on/off, which may require some code.
     
  38. melksnis

    melksnis

    Joined:
    Sep 30, 2020
    Posts:
    8
    Hello, I just wanted to know where are the automatically saved textures stored - I am going to store a lot of them and need to know how much space they take and I will have to make a system to clean up unused ones
     
  39. crdmrn

    crdmrn

    Joined:
    Dec 24, 2013
    Posts:
    128
    Hi @Darkcoder, and thank you for this great asset :)
    I got it 'cause I was looking for something to help me paint splatmaps for some non-terrain terrain meshes, but looking into this thread I realized that "In-Editor" as mentioned in the documentation, means that the Plugin works within the Unity Editor, but it still requires it to be in play mode; which makes it very inconvenient for what I'm trying to do.
    Did I miss something or is that actually the case?
    I've seen that Paint3D can be also controlled via c# so I was wondering, how heavy would you say it would be if I had to write an extension that allows me to do what I'm looking for in scene view, without play mode activated?
     
  40. MFKJ

    MFKJ

    Joined:
    May 13, 2015
    Posts:
    264
    The car is not paintable if I don't use a convex check mesh collider? What to do?
     
  41. Zucc0

    Zucc0

    Joined:
    Mar 25, 2015
    Posts:
    2
    Got it working, thanks for pointing me in the right direction. For others in my situation: The object Paint that includes P3dHitThrough can be attached to the right (or left) controller inside the XR Rig component and changing the start/end points it will follow your movements. Then, creating an Input Manager with an InputDevice to detect if the trigger is pressed/released to activate/deactive the Paint gameObject does the trick.

    The other thing to keep in mind (it's in the documentation well explained) is to change your material to URP and paint over the _BaseMap (Albedo) or else it won't paint when you'll compile your project.
     
    Darkcoder likes this.
  42. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    They use Unity's built in PlayerPrefs system, which stores them HERE.

    If you want to change to a different save/load system, then open P3dHelper.cs and change the code in the SaveBytes, LoadBytes, SaveExists, and ClearSave methods.


    I'm working on an update that brings the in-editor painting back to the scene view, as well as not requiring you to add colliders. This should make things much easier, and it's almost ready. The problem with making paint work in edit mode is that it has the potential to break your scene, because it has to modify the materials and textures of your objects. The modifications to make this work aren't that difficult, as you basically just have to 'trick' the paint components into thinking they're running in-game by manually calling OnEnable, OnDisable, Update, etc that would normally be called when in game.


    It is, but making the collider convex means where the paint tries to apply and where the mesh actually is are sometimes too far apart, so you see nothing. In other words, the gap between the collider and the visual mesh must be less than the radius of your paint brush. If you make it convex and try to paint the roof for example, you should see it work as expected because those surfaces will match or be very close.
     
  43. ahmedNabeel_UnityDev

    ahmedNabeel_UnityDev

    Joined:
    Sep 15, 2020
    Posts:
    3
    Hello there!
    I have question that there is a floor game object in my scene (just like a plane with mesh) containing numbers of different materials since it is a large plane having roads, pavements and grass textures. But when I make it paintable and presets the textures in PaintIn3d Editor it shows "Failed to find any presets for this material or shader" instead of Albedo Alpha can you please tell why? because I'm unable to paint my floor.
     
  44. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    What shader is your object's material using? If it's a non standard one you must add it to the PaintIn3D/Shared/Examples/Groups list, or manually add the P3dMaterialCloner and P3dPaintableTexture component the same as the in game setup.
     
  45. ahmedNabeel_UnityDev

    ahmedNabeel_UnityDev

    Joined:
    Sep 15, 2020
    Posts:
    3
    These are custom ones.

    Well I also added MaterialCloner and PaintableTexture manually but still it didn't paint. And can you please elaborate/guide about the "Groups list" you've mentioned previously..
     
    Last edited: May 8, 2021
  46. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    I've updated the documentation for the next version HERE, which has more information about this.

    If you add your shader to the group data like this then it should appear in the presets list.

    Keep in mind the current version requires you to add colliders to your object too. In the next version coming out soon this will no longer be required.

    Also, you can click the "Analyze Mesh" button to make sure the mesh is suitable for painting (see HERE).
     
  47. crdmrn

    crdmrn

    Joined:
    Dec 24, 2013
    Posts:
    128
    That's great to hear! Any prediction on when that might be ready?
    And also, is there/will there be a way to pain splat-map like?
     
  48. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    It's currently pending review by Unity, so within a few days I'd imagine.

    Splat maps can be painted just like any other texture already, you just need to:
    1) Make a splat map shader.
    2) Change your P3dPaintableTexture to use this splat map texture slot (e.g. it's probably not _MainTex).
    3) Maybe change this texture and paint component's Group to something different.
    4) Maybe change your paint component's settings based on your splat map (e.g. change the blending mode to Additive).

    Now that I've moved the example shaders to use Better Shaders, it's much easier for me to make a splat map example shader again. I've added this to the todo list HERE :)
     
  49. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    2,668
    Hey everyone,

    Version 1.11.1 of Paint in 3D is now out!
    • Moved in-editor painting tools back to scene window.
    • Made in-editor painting tools not require colliders.
    • Added P3dGraduallyFade.BlendPaintableTexture setting.
    • Added Scale / Random paint modifier to P3dPaintSphere and P3dPaintDecal.
    • Fixed P3D / Solid shader's Opacity Override not working.
    • Fixed P3dPaintableTexture.Resize not updating mips.
    • Fixed P3dReadColor giving incorrect values in OpenGL.
    • Fixed connected hits incorrectly joining together on mobile devices.
    • Renamed P3dGraduallyFade.Texture setting to BlendTexture.
    • Renamed P3dGraduallyFade.Color setting to BlendColor.
    Lots of small changes here, and one big change: in-editor painting is back in the scene view. It should be much easier to use now, but please read the updated documentation on how to get started!

    Enjoy :)
     
    Opeth001 likes this.
  50. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    805
    Hello :)
    im thinking about bying this Asset to help me integrate runtime Painting ... but im not sure if it's gonna work with my custom hybrid render which is based on DrawMeshInstancedIndirect.
    does this asset support gpu Instancing or is there a way to use it with gpu instancing ?
     
unityunity