Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    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


    Apr 10, 2013
    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.         {
    4.             tex.SetPixels32((int)pixelUV.x, (int)pixelUV.y, brushWidth, brushHeight, colorToPaint);
    5.         }
    6. }
    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?

  2. Kurt-Dekker


    Mar 16, 2013
    You have to manually draw the pixels between each sample you get from the mouse.