Search Unity

[Released] Mobile Paint (with multi-touch)

Discussion in 'Assets and Asset Store' started by mgear, Aug 16, 2014.

  1. Jael-Acaxa

    Jael-Acaxa

    Joined:
    Aug 19, 2019
    Posts:
    9
    Thanks for the answer, i will implement a function to resize my texture while i paint on runtime then. :)
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    nice!

    some ideas,
    - can do resizing in another thread (since you just need to resize that pixel array)
    - can cache resized textures, so no need to resize every timer
     
  3. Jael-Acaxa

    Jael-Acaxa

    Joined:
    Aug 19, 2019
    Posts:
    9
    Thanks for the ideas it helped me alot, i'm changing it to resize in another thread and it's almost working.
    But i have another idea to implement, i want to make a painting tool that detects the color of the image and automatically adds the right color. Can you direct me with any ideas

    Thank's again :D
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    do you mean color picker?

    i'm thinking could do:
    inside MousePaint(), create code for rightmouse button (to work as an color picker, or any other key..),
    similar code as the drawing one: checks button, does raycast, then it gets pixelUV as pixel coordinate.

    then you can get that pixel color with something like:
    Code (CSharp):
    1. int pixel = (texWidth * y + x) * 4; // get 1d pixel array index
    2. var mypickedcolor = pixels[pixel];
    and then could assign that color into one of the color pencils in ui canvas (to be able to use them),
    or manually set it as current color with:
    Code (CSharp):
    1. SetPaintColor(mypickedcolor);
     
  5. Jael-Acaxa

    Jael-Acaxa

    Joined:
    Aug 19, 2019
    Posts:
    9
    I'm painting with alpha at 255, so the image below is colored ... it worked, but for some reason it gets so slow on my phone and tablet. Is it normal to lose so much fps when I start painting?

    Many thanks again, you're helping me with your application that is free. Thank's :D
     
  6. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    check profiler for whats slowing it down.
    (but most likely it just gets slow because of high resolution displays, then need to use lower resolution texture, instead of full)
     
  7. Jael-Acaxa

    Jael-Acaxa

    Joined:
    Aug 19, 2019
    Posts:
    9
    Okay, i will use lower resolutions and make some optimizations on the application too.

    Thanks, and btw I'm learning a lot from your codes, there are a lot of vector and pixel calculations here that make me go back to studying math to understand everything and that's amazing.

    :D
     
  8. Jael-Acaxa

    Jael-Acaxa

    Joined:
    Aug 19, 2019
    Posts:
    9
    Hi again, now i'm trying to expand the pixels when i use the paint bucket tool, instead of just adding the color immediately.

    But i can't multiply the pixels while it's paintings and i don't understand why, can you give me some advice on this ?

    Thanks :)
     
  9. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  10. Jael-Acaxa

    Jael-Acaxa

    Joined:
    Aug 19, 2019
    Posts:
    9
    I didn't see that Issue, i will do that...i was using coroutines on the wrong place haha Thanks mgear :)
     
  11. Jael-Acaxa

    Jael-Acaxa

    Joined:
    Aug 19, 2019
    Posts:
    9
    Hey mgear, it worked more or less this solution.

    It creates a rhombus shape and it updates in every other point that i press, so a lot of them are becaming bigger while i keep pressed.
    I think that this update on every other form has to do with the Buffer but i don't know what is happening.
    Can you help me ?
     
  12. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    (somehow missed alerts on this)

    not sure whats happening, can you record gif or screenshots?
     
  13. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  14. indra151096

    indra151096

    Joined:
    Nov 22, 2019
    Posts:
    2
    Hi, thanks for the great asset. Is this support for 3d scene material?

    Thanks
     
  15. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  16. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    121
    Hi! Thanks for asset!
    I just found a freeze (even in editor) when you try start paint a large area with mask locking
    Big GC.Alloc goes from LockAreaFillWithThresholdMaskOnly()
    I use full screen canvas texture. And targeting for mobile devices. Any suggestions?
     
  17. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    yeah, that would need to be fixed, but personally havent had time to look into it:
    some info https://github.com/unitycoder/UnityMobilePaint/issues/41
     
  18. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    121
    I think currently will solve it just reducing the resolution.
    However paint dot now looks like
    2020-02-15_113028.png

    Is there any way to make it look smoother? Something like reducing alpha on edges?
     
  19. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    i think that would need to using custom brush,
    or modifying the drawcircle method to paint lower alpha on edges.

    or can try trilinear filter mode, using image effects to soften whole image (but not really ideal since its slow on mobile),
    or modify the canvas shader to do small blur inside that shader.
     
  20. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    Hi there

    After upgrading my project to 2019.3 a whole bunch of errors popped up.

    Has this happened to you also?

    Thanks
     
  21. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    I get only those 4 warnings, but still seems to work. (tried on 2019.3.0f6)
     
  22. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    121
    Can you reffer where did you find func that draws a circle? Or maybe point me where can I detect pixles that are on edges?
     
  23. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    brush circle drawing is here,
    https://github.com/unitycoder/Unity...ssets/MobilePaint/Scripts/MobilePaint.cs#L957

    for a quick test,
    could make it so that it draws always 4 pixels (regular full pixel in middle,
    and then 50% alpha pixels on the each neighbor pixel, to see if it helps or not)
     
  24. Sparkline

    Sparkline

    Joined:
    Feb 8, 2013
    Posts:
    121
    No. I mean where did you get that func? Or it is your own?
    Could you share an example of that solution please?
     
  25. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    there is source link above (but seems broken), midpoint circle based
    https://stackoverflow.com/questions/1201200/fast-algorithm-for-drawing-filled-circles

    not at the moment.. but try painting neighbor pixels there,
    pixel index in 1D array is take at line:
    https://github.com/unitycoder/Unity...ssets/MobilePaint/Scripts/MobilePaint.cs#L970
    so make new variables for left, right, top, bottom pixels,
    then assign those pixel colors there https://github.com/unitycoder/Unity...ssets/MobilePaint/Scripts/MobilePaint.cs#L985
     
  26. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    Hi there
    I am getting this one error:
    Assets/MobilePaint/Scripts/UserInterface/AdjustBrushSize.cs(13,10): error CS0619: 'GUITexture' is obsolete: 'GUITexture has been removed. Use UI.Image instead.'

    I haven't update it in a long while I guess so I was wondering what would be the safest way to do so?
     
  27. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    i think that script was not used, at least not in the latest github version. so can just remove it.

    update,
    take backup and/or use git, so can revert back if it breaks. (or clone project, test updating there first)
     
    gegagome likes this.
  28. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    asset got removed from asset store due to complains that is has error messages in new unity versions.. which is ok, but bit silly since the released version clearly says unity 4.5..
    anyways, use the github version:
    https://github.com/unitycoder/UnityMobilePaint
     
  29. yjb5047

    yjb5047

    Joined:
    Nov 20, 2019
    Posts:
    1
    Hello, Thanks for your asset. This is very helpful for me... My English will be awkward because I'm Foreign student. Please understand..
    Can I size the background(500*500) and store it transparently??
     
  30. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    can force resolution:
    upload_2020-8-7_23-21-15.png

    saving image, there is screenshot method, which uses regular https://docs.unity3d.com/ScriptReference/Texture2D.ReadPixels.html
    public Texture2D GetScreenshot()
    so could try that, see example script SaveImageToFile.cs, where that part is commented out.
     
    yjb5047 likes this.
  31. rabishan-maharjan

    rabishan-maharjan

    Joined:
    Jul 3, 2016
    Posts:
    18
    has anyone tried this on Universal Render Pipeline?
     
  32. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    ok was it you on this issue, i havent tested.. but i'd suggest trying different shaders for those that show pink. (any builtin urp ones, sprite shader etc)
    https://github.com/unitycoder/UnityMobilePaint/issues/51
     
  33. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    84
    Hi mgear ,

    Thanks for your great asset.

    I want to ask 2 question.

    How can i prevent to flood fill not paint on black?

    How can i prevent not to paint on ui layer?

    Because when i select a color , image are also painting ?

    Thanks in advance

    King regards
     
  34. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    1) scene_MobilePaint_NewUI_PaintAreaLockMask.scene should work like that, and is has this option disabled in inspector: [ ] can draw on black

    2) there is code to check that mouse is not over UI, not sure if it has changed in newer unity versions?
    Code (CSharp):
    1.             if (eventSystem.IsPointerOverGameObject()) return;
    2.             if (eventSystem.currentSelectedGameObject != null) return;
    can check
    https://answers.unity.com/questions/1095047/detect-mouse-events-for-ui-canvas.html
    https://forum.unity.com/threads/can...-raycasts-even-when-option-is-enabled.557584/
     
  35. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    84
    Sorry but i am using 2020 but both not working.

    Not draw on black is working n default but flood fill.

    And Not Draw on UI is not working completely.

    did you try these features in 2018 , 2019 or 2020 ?

    thanks in advance.

    King regards.
     
    Last edited: Dec 19, 2020
  36. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    84
    Hi mgear again,


    i want to ask a simple question. how can i make a glitter or glow painting with your asset?


    Thanks in advance.

    King regards
     
  37. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  38. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    84
  39. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    glow,
    i'd try post processing glow effect.. or modified canvas shader to do "blur glow" directly in the painted image..

    glitter,
    if its for "appearing glow texture", it should be ready made static glitter image (or with custom shader in the background),
    and its just revealed from drawing with transparent brush.. (asset store has some glitter shader plugins).

    but no ready solutions..
     
  40. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    84
    Can you give me an example use?
     
  41. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    84
    I figured out how i will prevent . thank you so much.
     
  42. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    84
    Hi mgear again,

    Thanks for your great asset.

    i want to ask i wonder if how can i add a sticker or stamp or decal to my texture? is there a way for this?

    thanks in advance.

    Sincerely King Regards
     
  43. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    custom brushes can be splatted into image, but no resize or rotate..
    upload_2020-12-25_20-10-7.png
     
  44. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    84
    Thanks mgear.

    i added stickers thanks.

    But i have a problem z value of stickers(custom brushes) are smaller and because of that stickers are staying under lines before drew.

    upload_2020-12-26_16-50-39.png

    i want my sticker on the top.

    how can i achieve this?

    thanks in advance.

    Sincerely King regards.
     
  45. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    if theres mask overlay, everything will be drawn below it (see the shader, it blends mask on top).

    not sure if theres easy workarounds,
    - could have those stickers drawn on completely separate, overlay image (with transparent bg).. but then they wouldnt interact with rest of your painting/floodfill etc. and need to manage which painter is active for that mode..
    - modify the script so that stickers are splatted on separate texture, which is then drawn on top in the shader..
     
  46. egem2015

    egem2015

    Joined:
    Oct 27, 2015
    Posts:
    84
    No they are just custom brushes.

    And can i ask an another question?

    how can i put i custom brush after my touch up not down?

    i mean custom brush will draw after my finger up. is this possible?


    thanks in advance.

    Sincerely King Regards
     
  47. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
  48. payalzariya07

    payalzariya07

    Joined:
    Oct 5, 2018
    Posts:
    85
    hello,
    if the image draws completed with filling the color. how did we know the image is completed?
    Please help me to solve this problem.
    Thanks in advance.
     
  49. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    see example scene "scene_MobilePaint_LockingMaskWithAreaCalculation.scene",
    would need to use that kind of system, and the script PaintAreaEventListener.cs defines those fixed areas that it watches.
     
  50. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    392
    I am working in "scene_MobilePaint_LockingMaskWithAreaCalculation.scene" but I am having a hard time setting up an image that works like the example.

    For instance it is a firetruck that has black and transparent pixels but when painting it paints over black and not like the example.

    Any ideas?
    Thanks