Search Unity

Paint In 3D ✍️ Paint In Editor✏️ Paint In 2D

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

  1. Euricius

    Euricius

    Joined:
    Sep 3, 2017
    Posts:
    25
    Hi!

    I'm trying to implement sphere brush which doesn't paint back mesh surfaces (back to the raycasted paint point, see attached pictures).
    My idea is to provide paint direction (equals to hit point normal) to P3D Sphere.shader and calculate dot product of fragment normal and paint direction :

    Code (CSharp):
    1.              
    2. void Frag(v2f i, out f2g o) {
    3.     ...
    4.     float strength;
    5.     if (dot(i.normal, _PaintDirection) >=  0.0f) { //https://stackoverflow.com/a/49535408
    6.         strength = 1.0f - pow(saturate(distance), _Hardness);
    7.     } else {
    8.         strength = 0.0f;
    9.     }
    10.     ...
    11. }
    12.  
    I have a problem with calculations of fragment normal value (i.normal). How I can provide/calculate fragment normal value from real mesh to current RenderTexture shader?

    Thanks in advance


    UPDATE

    I found solution with UnityObjectToWorldNormal function
    Code (CSharp):
    1.  
    2.  
    3. #include "UnityCG.cginc"
    4. ...
    5.  
    6. struct a2v {
    7. ...
    8.     float3 normal    : NORMAL;
    9. ...
    10. };
    11.  
    12. struct v2f {
    13. ...
    14.     float3 normal   : TEXCOORD2;
    15. ...
    16. };
    17.  
    18. void Vert(a2v i, out v2f o){
    19. ...
    20.     o.normal   = UnityObjectToWorldNormal(i.normal);
    21. ...
    22. }
    23.  
    24.  
     

    Attached Files:

    Last edited: Aug 14, 2019
  2. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Glad you found a solution!

    I'm currently working on a large update to Paint In 3D that redesigns how the painting is implemented. This new system makes modifying and adding new paint brush types much easier, and it will also allow me to add more custom ones like you describe. In addition to this, it unifies the in-game and in-editor painting to use the same components and settings, which will make all of this even more consistent.
     
    Euricius likes this.
  3. JanetRGilbert

    JanetRGilbert

    Joined:
    Sep 25, 2017
    Posts:
    8
    Is there any way of masking an area of a paintable texture as if you were using masking tape? I want to be able to paint only on certain areas of a quad, defined by a masking texture.
     
    Last edited: Aug 20, 2019
  4. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Not yet, but this is on the to-do list. I want to get this next update out first, because it already adds many new features. If I add too much right now I will never release this :D
     
  5. JanetRGilbert

    JanetRGilbert

    Joined:
    Sep 25, 2017
    Posts:
    8
    I need this feature by next week :) Could you give me some hints on how best to implement it?
     
  6. RonnieGaikwad

    RonnieGaikwad

    Joined:
    May 14, 2017
    Posts:
    13
    Hi I'm applying paintable script on the cube and when i click on it it paints that face as well as the r other faces..
    Also when i used it on the pro builder asset it many times does not paint on the face that i have clicked on and if i try to click on other faces then in one of that face if i click it paint itself as well as all the faces of the probuilder asset.. What i want is to paint the arch that we get on probuilder.. I want to paint the each face of arch one by one whike playing the game
     
  7. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    It's a little difficult. You have to pass the mask information to the painting shaders, and then before the paint is applied you must see how much that area is masked based on this information, then you can subtract that from the painting strength.


    This will happen if you have multiple triangles that share the same UV data/area. For example, Unity's built-in cube has all 6 sides sharing the same UV data, so painting one side will paint them all. To fix this you must make them unique, which can be done inside Unity as detailed HERE.
     
  8. RonnieGaikwad

    RonnieGaikwad

    Joined:
    May 14, 2017
    Posts:
    13
    Can't see any crood copier in gear icon for imported obj it just says reset
     
  9. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    It's in the context menu of the Mesh inspector, not the object itself. If you expand the object you should see its mesh.
     
  10. JanetRGilbert

    JanetRGilbert

    Joined:
    Sep 25, 2017
    Posts:
    8
    Cheers Darkcoder! This worked great!

    And thanks for writing such a great tool! I've had a lot of fun working with it.
     
    Darkcoder likes this.
  11. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Hey everyone. Version 1.7.0 of paint In 3D has just been submitted.

    This includes an immense amount of changes, as I rewrote about half of the code. The biggest change is that the editor painting has been unified with the in game painting. This means they use the same components, except that for editor use you must put them in a prefab and add the new P3dBrush component. This makes adding new features so much easier for me and anyone wanting to make changes. It also allows users to make brush packages and easily share them.

    Another big addition is the modifier system, which allows you to add components like P3dModifyColorRandom alongside your paint components. You could previously do this from the brush settings, but it made development more difficult as I had to add so many of these different modifiers to each different paint component, but this new system allows this one modifier to work with all painting components automatically.

    Another big addition is an undo/redo system that is based on paint commands, rather than texture snapshots. You can still use the old snapshot system for animated objects, but for solid objects you can use this new P3dPaintableTexture.State = LocalCommandCopy setting to save lots of memory. As the name suggests, paint commands can now be converted to local space and back to world space. Besides being useful for undo/redo, it also allows for much easier network communication where each client will see the same paint result.

    Another big addition is lots more example scenes. This is something I've done with my other assets, where I go through each feature step by step showing every feature in a bare bones scenario.

    If you upgrade to this version then make sure you back up your project first, delete the old Paint in 3D folder, then install, as this will most likely break a lot of stuff and require you to update many components. You can see the change log when it's released to see what components changed to what.

    There are still a few more things I want to add soon like many more example brushes, but I wanted to get this new version submitted before the weekend. I look forward to any feedback when it comes out!
     
    Euricius and JanetRGilbert like this.
  12. RonnieGaikwad

    RonnieGaikwad

    Joined:
    May 14, 2017
    Posts:
    13
    What is the difference between paint decal and paint sphere?
     
  13. RonnieGaikwad

    RonnieGaikwad

    Joined:
    May 14, 2017
    Posts:
    13
    In rigidbody example i see that the cube paint's the surface with a strip of width same as cube also the paint thickness is looks like a real paint, how can i do it and make it look like a nice thick paint?
     
  14. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Decals allow you to set a texture, and that texture is then projected/extruded into the mesh when painted. It also gives you options to adjust the projection depth, prevent backface painting, etc.

    Sphere painting just paints all pixels within the 3D radius you specify. You can adjust the color and falloff/hardness of the sphere.

    I'm not sure I understand, which example are you talking about?
     
  15. RonnieGaikwad

    RonnieGaikwad

    Joined:
    May 14, 2017
    Posts:
    13
    Rigidbody collision painting.

    Im currently using a cylinder as a pipe laid along z axis and having a roller to paint it and i added paint decal(using color and not texture) and i noticed that when the roller collider with the cylinder and falls down rolling over it then the paint appears on the cylinder.. But if i keep the roller stationary and rotate the cylinder then the roller doesn't paint the surface of the cylinder.. I actually want to rotate the cylinder with the roller collided to it and thus wanna paint the cylinder surface instead of rolling the the roller on the cylinder. How can i do it? Also how can the same roller paint different colors on different cylinders?
     
  16. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    There's no demo scene called "Rigidbody collision painting"? Which version are you using?

    The collision painting feature is triggered by collisions, so if your roller is stationary or rolled then there will be no new collisions. For this scenario I recommend using P3dProximity to paint, and using P3dPaintSphere/Triplanar instead of decals. This way the roller will constantly emit paint.

    To change the paint color you would have to adjust the P3dPaintSphere/P3dPaintDecal Color setting from code. In the current version the P3dPaintSphereColor component can be used to do this if you trigger it from a UI button or something.
     
  17. RonnieGaikwad

    RonnieGaikwad

    Joined:
    May 14, 2017
    Posts:
    13
    So should I add p3dproximity and prdPaintSphere/Tiplanar both to the roller?
     
  18. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Sure, you want to add multiple so it more closely resembles a cylinder though.

    Now that you mention it, a component that continuously paints lines rather than just points would be very useful in this scenario. Also, a component that continuously paints decals where you can specify the orientation would be useful too. I'll add these to the to-do list!
     
  19. RonnieGaikwad

    RonnieGaikwad

    Joined:
    May 14, 2017
    Posts:
    13
    I hope p3d Proximity and prdPaintsphere/Triplanar will add continuous lines once the object is collided with the cylinder so that i can paint the cylinder by rotating it.
     
  20. Daniel-Streck

    Daniel-Streck

    Joined:
    Jul 4, 2015
    Posts:
    4
    I'm having an issue where the Pixel Counter gives wrong values while running on Android (works fine in the editor).

    Basically I'm trying to count red pixels in a texture to check how much of it has been painted. The object starts with a texture with zero red pixels painted, but on the first small spray of paint the values go crazy showing that it has much more red pixels than it actually has.

    The weird thing is that it works as expected in the editor, and there's nothing different about the Android build.

    Any ideas of what may be causing this?
     
  21. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    It will paint regardless of the rotation. If you require it to only paint while being rotated then I'll have to make some changes, perhaps the paint pressure could be controlled by the angular velocity. I'll add that to the to-do list too!


    What's the exact device you're trying this on? What's the exact Unity version you're building with? Does this issue occur in the example scenes, or does it require a special mesh? What if you change the DownsampleSteps setting to 0?
     
  22. RonnieGaikwad

    RonnieGaikwad

    Joined:
    May 14, 2017
    Posts:
    13
    CAN WE GIVE THE LIQUID EFFECT TO PAINT OR VISCOSITY?
     
  23. Daniel-Streck

    Daniel-Streck

    Joined:
    Jul 4, 2015
    Posts:
    4
    Tested on a few Motorola devices (Moto Z play, Moto G7), versions 2019.1.14f1 and 2019.2.2f1, it occurs in the Pixel Count example scene if you use the p3dPixelCounter on other objects instead of the grass. Nothing special about meshes and tried DownsampleSteps as 0 to no avail.

    I created a repro project that has two modified versions of the Pixel Counter example scene, one where the issue happens if you try to count pixels on the Cliff object, and another where it works as intended counting pixels on the grass mesh. As its possible to see in the attached screenshot I just painted a small red circle but it shows wrong pixel counts.

    Again, it works in the editor but not on Android build.

    How can I send it to you? (wont send here because contains your plugin)

    Thanks in advance.
     

    Attached Files:

  24. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    You can paint any texture you like if you adjust the paint settings for your shader/material. The PBR painting example shows you how to paint multiple textures, which can be used to paint liquid-like effects. There's no liquid flowing or viscosity demo though, perhaps in the future.


    You can email or private message me the project. If you're only using media and components that come with Paint in 3D then you can attach the scene file though, since it doesn't contain anything but references.
     
  25. Daniel-Streck

    Daniel-Streck

    Joined:
    Jul 4, 2015
    Posts:
    4
    Attached the repro scenes here without the plugin as you suggested.

    Added a readme file with a small description of the issue and repro steps... thanks again.
     

    Attached Files:

    Last edited: Aug 28, 2019
  26. yul10001

    yul10001

    Joined:
    Apr 9, 2019
    Posts:
    1
    Can i use this texture paint tool in not edit mode but play mode?
    and additionally, i want to know is there any plan to add eraser tool.
     
    Last edited: Sep 7, 2019
  27. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Yes, Paint in 3D works both in the editor, and in game.

    There is already an eraser tool. If your paint is on a second transparent layer (there are example scenes for this), then you can use any brush with the Subtractive blending mode, with a color of RGBA(0,0,0,1), and it will erase your paint. If your object starts as a solid color like white then you could also paint white with the Alpha Blending mode.
     
  28. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    I couldn't test your scenes directly because you're using an older version of Paint In 3D.

    If I copy+paste your settings to the new pixel counter demo scene with the cliff mesh then I notice no issues on Android though.

    If you let me know the exact version of Paint in 3D you have then I could test it in that too.

    I've made changes to these components (and will do so in the next version too), so it's possible this is just some bug that I've now fixed.
     
  29. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Hey everyone,

    Version 1.7.1 of Paint in 3D just released!

    This includes the new "26 Reveal Original" demo scene.



    As well as the new "31 Paint Percentage" demo scene.



    This paint counter uses a new strategy that is much more accurate than before, you just need to set your original mesh (non-seam fixed) in the P3dChannelCounter/P3dColorCounter component's Mesh setting.

    You'll notice that the inspectors of the P3dChannelCounter and P3dColor components have also been improved, and tell you how much % ratio of the texture you currently have painted. These values are accessible from C# code using the same names too.

    This version also fixes a bug with the P3dTransformMirror component (used to mirror painting).

    This version also fixes a bug where preview painting would incorrectly cause the P3dPaintableTexture.OnModified event to get fired with a false parameter, indicating you had actually painted it.

    Enjoy!
     
  30. noobynobody

    noobynobody

    Joined:
    May 9, 2019
    Posts:
    75
    Is it possible to paint individual faces of a mesh? I'm looking to recolor low-poly models.
     
  31. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Yes, but this requires your mesh to be UV mapped in a specific way where each triangle/surface occupies a unique area, and the colors must be stored using a texture that matches this UV mapping.

    Most low poly models I've seen either store the colors in the vertex color data (requires special shader/material to see), or they have some kind of color palette texture and overlap every triangle for each color. So they wouldn't work as-is.

    Making a tool to generate this UV data isn't too difficult, and you could then paint it from scratch (e.g. a solid base color) and I will add this to my to-do list. However, making it also port over vertex colors or color palette data would be more tedious and likely not make the initial release.
     
    noobynobody likes this.
  32. Daniel-Streck

    Daniel-Streck

    Joined:
    Jul 4, 2015
    Posts:
    4
    Thanks for the response.

    Unfortunately I just tested using version 1.7.1 and the issue still happens (see screenshot). Painted with only red color, and green and blue show up.

    For now I've managed to implement a simple naive pixel counter as a temporary solution, but I'd really appreciate if you could take a further look into it becauce your pixel counter is far more performant.


    On a different topic, could you give me a hint as to how to use the plugin in a programatic way?

    I need to generate textures for multiple objects that have their full UV completely painted in a single color (see screenshot example using the spaceship uv). The reason I'd do it this way, and not just paint one by one using the plugin, is because I need to perform a single operation on about a hundred object textures, so I'd batch the whole process in Unity.

    So how could I programatically just paint an object with a huge solid color brush (preferably while the game is not in play mode)?
     

    Attached Files:

  33. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    I can experiment with some different settings. Which Android device are you testing this on? Perhaps it's an issue with the GPU, hopefully not the dreaded Mali ones :D

    This can be done by pretty much copy+pasting the new P3dPaintableTextureMonitorMask.cs lines 75-102 (inside the Bake() method). You would want to pass your own RenderTexture with your desired size, replace the PaintableTexture.Channel + PaintableTexture.Slot.Index + mesh values with your own, and you can then save the output Texture2D as you wish.
     
  34. qwqweeo123

    qwqweeo123

    Joined:
    Sep 30, 2019
    Posts:
    4
    I want to know how to close symmetry in Editor Mode
     
  35. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    I'm not sure I understand your question.

    You can close the 'Mirror Brushes' list in the Paint in 3D window Painting tab by clicking the Mirror Brushes button.

    If you want to deselect a mirror brush then you can click its name so it's no longer green (you may have to click Unlock first).

    If your mesh is UV mapped so painting one side always paints the other, then you must UV map it so both sides have unique UV area. If you don't know how to use 3D modelling software then you can let Unity automatically generate lightmap coordinates in UV2 for you, then use the CoordCopier tool to copy them back into UV0.
     
  36. alargastudio

    alargastudio

    Joined:
    Apr 18, 2017
    Posts:
    11
    hello mr darkcoder, already try your plugin everything works well awesome!
    may i ask something? is there anyway to paint decal with apply button, i mean if i touch the car body it just only show a preview decal, and if i press that button it'll paint decal.
    thx be4, sorry for my bad english
     
  37. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    If I understand correctly, you just want to customize P3dHitScreen to use a keyboard button instead of the mouse/touch? If so, that's fairly easy to do, and I can send you an updated version.
     
  38. alargastudio

    alargastudio

    Joined:
    Apr 18, 2017
    Posts:
    11
    yes sir just like that, and paint to texture only when i press apply button
     
  39. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Just sent you a new build with this feature :)
     
  40. alargastudio

    alargastudio

    Joined:
    Apr 18, 2017
    Posts:
    11
    sorry for late reply, i'll try now, ty so much :)

    #edit, works perfectly awesome sir!
     
    Last edited: Oct 2, 2019
  41. alargastudio

    alargastudio

    Joined:
    Apr 18, 2017
    Posts:
    11
    sorry to ask again,
    if i use "clear all button", why undo & redo button can still working?
    is it possible to clear undo & redo too?
    thank you
     
  42. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Good idea, I added this to the next version. I sent you a copy via private message!
     
  43. alargastudio

    alargastudio

    Joined:
    Apr 18, 2017
    Posts:
    11
    wohoo awesome! all is perfect now for my project, thank you
     
    Darkcoder likes this.
  44. spsmith224

    spsmith224

    Joined:
    Oct 25, 2016
    Posts:
    5
    I have a paintable object using the 'Paint in 3D/Opaque' shader working just fine, but when I switch it to using the Standard shader it doesn't get painted anymore. Is there something special I have to do? This is using the built in render pipeline. Thanks.
     
  45. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    If you only want to paint the Albedo (_MainTex) then it should work by just changing the shader. For example, the "Bullet Dents" demo scene uses the Standard shader. Some texture slots like Normal Map require you to specify the "_NORMALMAP" keyword though.
     
  46. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Hey everyone,

    Version 1.7.3 was just released!

    This includes the new AlphaBlendInverse blending mode, which works like AlphaBlendAdvanced, but paints behind the currently painted areas instead of on top. This allows you to easily fill in the remaining un-painted areas of a transparent texture. This feature is shown off in the new "Paint Remaining" demo scene.

    This version also includes some fixes to the blending mode selection code. In 1.7.2 I changed the way blending modes work to more easily allow for new blending modes, and there was a little bug in this code that made it so some blending modes wouldn't activate properly.

    Finally, this version changes the way P3dInputManager works. It's no longer a shared component that gets added to your scene, and is now a normal class that works behind the scenes with both keyboard and mouse and touch integration. This means its code is simpler, it works better, and your scene is slightly less cluttered.

    Let me know if you encounter any issues, enjoy!
     
  47. sacb0y

    sacb0y

    Joined:
    May 9, 2016
    Posts:
    874
    Does this allow painting materials? Like can a decal have a PBR shader on it Albedo, SpecSmooth and Normal? Is it compatible with custom shaders like amplify shader?

    EDIT: My bad i missed the image in the store page, though still i'm wondering about custom shader support!

    EDIT2: ALSO! I was wondering does this work with a sprite sheet type layout? Or is it individual images?
     
    Last edited: Oct 23, 2019
  48. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Yes, Paint in 3D works with any shader, including custom ones from Amplify. You can also paint multiple textures at the same time, and the "PBR Painting" demo scene (among others) shows you how to do this. The only thing you must keep in mind is that the painting itself is applied using the mesh data, so if your custom shader modifies the mesh vertex positions, then the paint may not look like it appears in the right place, because Paint in 3D doesn't know where your modified vertex positions are. If you only have minor modifications like subtle displacement then this shouldn't be an issue though.

    The decal painting feature works using a Texture, not a sprite, so it will ignore any sprite sheet layout you have. As long as your decals are originally separated and you rely on Unity to pack them into an atlas, there should be no problem.
     
  49. ARideout

    ARideout

    Joined:
    Sep 7, 2017
    Posts:
    7
    I have a question regarding implementation of an almost reverse gradually fade effect. I'm looking at creating an effect where as you paint, your paint appears slowly over time. Ultimately I am using the painted texture as a mask in a custom shader. My implementation has the red channel function as a mask for blending textures, and I would like to use the green channel to slowly fade in so I can use it to drive strength of normals/displacement for a kind of growing effect. Effectively the green channel fades in to match the red channel over time, though preferably doesn't overshoot? Is it better to try to achieve this effect using two separate textures and feed the first (actively drawn in runtime) into a modified fadegradually script as the texture argument for PaintFill.Blit? Or could I do something similar with individual channels of a single texture as I currently have set up? Would performance be particularly different either way?
     
  50. ARideout

    ARideout

    Joined:
    Sep 7, 2017
    Posts:
    7
    Actually scratch that, it seems as though just using the gradually fade component in additive mode with the color set to green appears to work for my current setup.
     
    Darkcoder likes this.