Aug
9
2011

Painting holes with shader v1.0

mHolePainter v1.0

Using a shader from http://www.unifycommunity.com/wiki/index.php?title=Dissolve_With_Texture we can paint “holes” to the cutout texture.

Webplayer:
http://unitycoder.com/upload/demos/mholepainter1/

Download:
mHolePainter1.UnityPackage


12 Comments + Add Comment

  • What about doing the opposite?
    I mean, painting texture on a completely transparent object?

    • Make the mask initially black, and paint with white color.

  • I have assigned shader to multiple objects . when i edit one object all other objects also get erased..
    may be thats sound silly I am a new to unity. please help

    • I think it happens because if you place the same script on multiple objects and you paint one object, other objects will also register the raycast hit as true and will erase from that same position where it hits on the other object..

      so should modify the script and move it to camera..(and then paint on the raycast hit target only)

      or for a quick test, in the current script should check when the raycast is hitting, that is the hit target same as this object..

      • what modification s are neede so as to attach it to the camera… just want to say that your script is superb…

      • I did necessary changes and attached to the camera but still it doesnt work… it fails to do following part

        Vector2 pixelUV = hit.textureCoord;
        pixelUV.x *=tex.width;
        pixelUV.y *=tex.height;
        tex.SetPixel((int)pixelUV.x,(int)pixelUV.y, Color.black);
        tex.Apply();

  • HI, How do we know if object is completely Erased or not.?

    • Every time you paint, could check that if pixel is not painted color, then increase pixel counter.. (until pixel counter equals total all pixels)

      Or after each click, go through all pixels and see which ones are painted and which ones not.

      Would be faster to use SetPixels32() array (and check from the array), instead of the invidual SetPixel()/GetPixel()

      • Thanks for reply, Can you provide me the C# version of the Script with some Solving example related my Query. Hope you Don’t mind

        • Unfortunately no time at the moment..
          Try first yourself, post results/question in Unity forum, so others can help also 🙂

          • ok thanks i will try 🙂

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Youtube Join Discord Twitch

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.