/Unity_MaskDraw

Draw RGB Mask for any mesh inside Unity Editor

Primary LanguageC#MIT LicenseMIT

Unity3D Mask Draw

This component allows to draw RGB mask directly inside scene view

Preview

image

Abilities

  • Draw RGB mask in editor.

  • Draw in play mode (require to have "MainCamera" tag on scene camera).

  • Don't care about stitches. Brush projected directly on mesh.

    Proof

    image

  • Support skinned mesh renderer.
  • "Read/Write enabled" in import settings doesn't required
  • Custom brush mask.
  • Orthographic and perspective projection types.
  • Easy export result as .PNG.
  • Up to 4 images for draw (for black, red, green, blue; alpha channel didn't use)

How to use

This component works as usual MonoBehaviour script.

  1. Assign Draw.cs to any object on scene.
  2. Assign shaders to component. This to "UV Projection Shader", this to "RenderTexture Shader"
  3. Assign target mesh from hierarchy.
  4. Create a mask. In project folder create Custom Render Texture.
  • Configure size as you wish (power-of-two size of side is preferred).
  • Initialization Source => Texture and Color; Color => Set black color.
  • Be sure to check Double buffered switch turned on.
  1. Assign mask into Draw component on scene.
  2. Create material. You need to create a shader that support masks. I prepared this one. It's simple world-coord shader. You can choose this from path "Drawable/World Coord Simple".
  3. Assign created material on target mesh.
  4. Assign draw mask in property field. You can use prepared image. If you want to create you own, don't forget to set Wrap Mode to Clamp in import settings of your asset.
  5. Profit! For start draw just turn on toggle "Draw in edit mode"

Requirements

  • CustomRenderTexture feature is released in 2017.1. Check. You need younger version.
  • Image Conversion package (in Build-in packages) to export mask as .PNG file.

Known issues

  • Doesn't work with (new) Input System.
  • Catch left mouse button press and deactivate selection frame works weird. When you draw, don't use combination of Alt+LMB to orbit. Alternatively use RMB to orbit, MMB to move editor camera.