Search Unity

How to make a pixel painting program using Unity

Discussion in 'General Discussion' started by ladlamuzamil, Oct 18, 2021.

  1. ladlamuzamil

    ladlamuzamil

    Joined:
    Oct 18, 2021
    Posts:
    1
    So I'm making an Android app/game using Unity where the user is able to "draw" by touching the screen. The drawings will be pixel art -- basically, a pixel art drawing function -- so everything should be pixel perfect.
    Some functions I will add are: OlansiChina.com
    1. Changing brush size
    2. Changing brush color
    3. Filling areas
    4. Erasing
    A game called Worldbox has a pretty similar function, where users are able to draw "land."

    I thought about using the tilemap function of Unity, and even made a program that does all #1~#4 well. However, if the tilemap(drawing size) exceeds 100*100 tiles, the app took forever to load, and I concluded that tilemaps weren't suited for drawing programs.

    A friend of mine said that I would have to make some kind of "editor" for this application, and Unity just isn't fit for that.

    However, I only know how to make applications using Unity, so are there any Unity functions I can use to make this app?

    The answer could be very simple(ex. Just use the tilemap function). It doesn't have to explain how I could make this app, but what I could use.
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,448
    can create texture, then draw on it with
    https://docs.unity3d.com/ScriptReference/Texture2D.SetPixel.html

    this can be already good enough, for low resolution texture,
    but if its big high resolution texture, then it starts to get slower, need to look into,
    https://docs.unity3d.com/ScriptReference/Texture2D.LoadRawTextureData.html

    or go another way, and use render textures, something like
    https://80.lv/articles/using-rendertexture-painting-shader/

    asset store has ready drawing and painting solutions also.

    i have one old drawing asset here, but its quite a mess (can take some drawing parts from it if needed though)
    https://github.com/unitycoder/UnityMobilePaint
     
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    You absolutely can make a graphi editor in unity. There are several ways you could go about it:

    Store pixel data in memory, and use Texture2D.LoadRawTextureData ( https://docs.unity3d.com/ScriptReference/Texture2D.LoadRawTextureData.html )

    Use render targets. Basically when you paint with a brush, what you're doing is taking one texture, blitting it onto another and then painting a brush on top. Or just painting a brush onto it.

    Use shaders or compute shaders. Some shader/computer shader versions allow random memory access, meaning you could implement brush operations as shaders and use them ( http://blog.deferredreality.com/write-to-custom-data-buffers-from-shaders/ ), This is likely not suitable for mobile and works better for desktop.

    So, your friend is mistaken. You can make a graphic editor in unity. Now, if you were trying to make a word processor, then unity likely wouldn't be the best choice.