Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  5. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Artifacts while using SetPixel32

Discussion in 'Scripting' started by Igris, Jun 14, 2018.

  1. Igris

    Igris

    Joined:
    Apr 10, 2013
    Posts:
    4
    Hello world!

    I wrote some code to draw on screen, but I get blank spaces between my drawings like the ones shown in the bottom line on the picture when moving the mouse too quickly.



    Because this is part of a larger application, I have the following constraints:
    I have to draw on a procedurally generated fully transparent texture, applied to an Unlit/Transparent material, applied to a GameObject.

    To do this, I am using the following code:
    Code (CSharp):
    1. void Update()
    2. {
    3. if (Input.GetMouseButton(0))
    4.         {
    5.             tex.SetPixels32((int)pixelUV.x, (int)pixelUV.y, brushWidth, brushHeight, colorToPaint);
    6.         }
    7. }
    The texture is a power of 2 and it's 512 x 512. It's declared and assigned here:
    Code (CSharp):
    1.  tex = new Texture2D(width, height, TextureFormat.RGBA32, true);
    2.         drawingCanvas.GetComponent<Renderer>().material.mainTexture = tex;
    And the brush (colorToPaint) is just a small array of 3 x 3 pixels.

    I am only drawing on a single object, using Color32, and using SetPixels32 instead of SetPixel. I am aware of line renderers, and I have an app for drawing with them but I cannot use those for this particular scenario.

    The FPS when running varies, but it's 74fps at its lowest. Any ideas, am I missing something obvious?

    Thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    2,875
    You have to manually draw the pixels between each sample you get from the mouse.