Instant Mask : smooth Mask image with semi-transparent gradation
InstasntMaskLogo

detailed explanation

About

Instant Mask is smooth Mask!

An image is cut or made hole shape of other one image, on MeshRenderer, Sprite, UnityGUI, Particle and so on.

It is smoothly semi-transparent mask such as anti-alias and gradation.

Mask with Alpha or Grayscale texture.

Can each adjustable such as Position, Rotation, Size, degree of Masking and so on.

Up to three mask images apply to one base image in same time.

Dynamically create a masking image or can also export masked image file.

Not increase the excess load, Batches and SetPass(DrawCalls) always in 1 at one object.

Use

It is used by add the scripts to GameObject in accordance with the usage applications.

- InstantTextureMask

- InstantShaderMask

- InstantParticleMask

These are in 'Script' folder of this asset.

This page is the description of how to use common to three scripts, so when you want to detailed use of each script, select from the menu on this page left side and view each page.

The setting name in Inspector window is same as Variable Name.
(intact the capital letter and fill the space)

For example, you want to change 'Mask Angle' by C# script,

GetGomponent<InstantShaderMask>().MaskAngle += 2.0f;

It is written to Update(), the mask part rotate 2 degree in each update.

Please refer to the IMaskDemoManager.cs that are used in the asset of the Demo.

Or it is possible that variable is changed by the timeline of Animation window.

The drop-down list of change such as WrapMode and SelectMaterial, these are int type internally, so when you want to change it, you set an integer from 0 to order from the top of the list.

GetGomponent<InstantShaderMask>().BaseImageWrapMode = 1;

It is set to Clamp the WrapMode of the base image.

When using Shader and Particle, you can select the culling of shader.
It is necessary to set it to 'None' when drawing the backside or using Flip of Sprite and so on. If you do not need to draw the backside, set culling to 'Back' and reduce the work load of your game without wasteful processing.
You can set it from the Inspector window of InstantMaskShader.

When using Shader or Particle and masking texture of 3D GameObject, if you want to make the inner surface of the model itself visible through the mask hole, 2passShader is also included for that.

To use it, simply replace the regular InstantMaskShader with 2passShader.

Texture

InstantTextureMask

This is used to make an image that do not frequently changes of states.

As Unity of specification, it is necessary to turn ON the 'Read/Write Enabled' state of texture to be used for processing.
(It is set in the Inspector window with select the image. It is in 'Advanced' collapse menu. On less than Unity5.5, it is necessary to set Texture Type to 'Advanced'.)

InstantTextureMask use pixel unit to change size and position, the pivot of change that size and position and angle is center of the mask image, coordinate origin of the mask position(x:0,y:0) is the lower left of the base image.

The following is each item of the settings.

Result

It is made the masked image dynamically and generated here.

Texture2D MaskedTex = GetComponent<InstantTextureMask>().Result;

In this way you can use the masked image.

ResultSize

To change the size of Result image.

ResultOpacity

To adjust the opacity of the masked result image.

ResultWrapMode

To change the WrapMode of Result image. On Unity2017 or higher, you can set with U axis(horizontal direction) and V axis(vertical direction) separately.

BaseImage

The base image to the mask.

MaskImage

The image to be used to mask shape.
This image is used the alpha channel or grayscale, and cut or made hole to BaseImage.

Masking

Whether to work the mask processing.
If turn off this, it is displayed just as the base image instantly.

MaskRect

To change the position and size of MaskImage.
The pivot is the center of the mask image, and the position origin(x:0,y:0) is the lower left of BaseImage.

MaskDegree

To adjust the masking applicability.
When this is set at 0, it is displayed the same view as not masking.

UseMaskRotate

The angle to rotate the mask part.
This is a little heavy processing, it is a good idea to turn Off this if you do not need to rotate mask.

MaskAngle

The angle to rotate the mask part.
The pivot is the center of the mask image.

UseUnityGUI

When using Image or RawImage component of UnityGUI to display the image, it is applied automatically to Image or RawImage component by checking this.
In this case, it adds two items below.

MaskVisibility

When this is On, the image that be attached MaskImage is displayed on the scene.

VisibileColor

When MaskVisibility above is On, you can change the color that MaskImage is displayed on the scene for easy to see.
When this setting is White(255,255,255,255), it is displayed the color of the original image. On the other hand, if the image that be assigned MaskImage is drawn with white, you can display it on the scene with free color.

ReverceMaskArea

Either cut or made hole the shape of the mask image.

GrayscaleMask

When this is turn Off, the alpha channel of MaskImage is used for mask processing.
When this is turn On, the brightness of the MaskImage is used.

Pixelization

To prosess the simplified pixelization.
This is such a bonus so accuracy is not so good.

BaseImageSetNatriveSize

It is set ResultSize values in the same size of the original image of BaseImage.
You can also do the same process in the program by execute the method.

GetComponent<InstantTextureMask>().BaseImageSetNatriveSize();

MaskImageSetNatriveSize

The w and the h values of MaseRect in the same size of the original image of MaskImage.
You can also do the same process in the program by execute the method.

GetComponent<InstantTextureMask>().MaskImageSetNatriveSize();

ExportResultImage

The masked result image is exported the image file.
It is created at InstantMask/ExportImages in Project window, the file is named to the enumeration of year, month, day, hour, minute, second of at that time and 4-digit number.

Shader

InstantShaderMask

This is mask the texture of each Renderer and GUI using a shader.
It is used when often change the states of mask, size, rotate and so on.

InstantShaderMask is compliant with the specifications of Unity shader to change the Mask size, it is changed by Tiling. The Pivot of Tiling is normally the bottom left corner of the image.
And the pivot of rotation is center of the mask image.

It need a material that have 'InstantMaskShader.shader', the material is assigned each renderer, Image and RawImage component of UnityGUI in same GameObject. It drow a result mask image through that material.

* Notes from Unity specification *
InstantMaskShader.shader is added properties to a Unity builtin shader for UI.
(UI-Default.shader)
If you want to mask using other shader, you must add write property of InstantMask to the other shader script yourself.
It is not possible rewrites appropriately shader script from asset, so it have no choice but to be done manually on the user side.
If you have created such a shader, it is assigned the material, and the material is applied to the Renderer and so on.

* Notes from Unity specification 2 *
It is material behavior in Unity specifications, in build game and when scene Play in Unity, the instance material is made automatically if the same material is shared in some renderer and to be done individual rendering in each of the GameObject.
In that case is not problem, but when Edit mode (Not scene Play in Unity) Unity specifications that do not make instance material, so all GameObject using the same material receive a change of state all at once.
So when you want to see the individual masking some GameObjects that share the same material, need to confirm by scene Play.
In addition, in Imaeg and RawImage component of UnityGUI, Unity does not make the Instance material, so you should note that same material is same drawing results even in build game and when scene Play in Unity.
For these behaviors, if this asset would solve such as replicate material or something, it is concern an error by discrepancy when referring to the material from such an other asset, so it leave the Unity standard behavior.
There is nothing to worry this when you use the individual materials in each GameObject.

The following is each item of the settings.

SelectMaterial

When some materials can be set to the Renderer, to choose the material for the masking operation.
It is displayed the list of materials that are assigned to the Renderer, so to select the mateerial that have InstantMaskShader.shader.

ResultOpacity

To adjust the opacity of the masked result image.

AlphaCutoff

To hide the this value and under opacity part of the masked result image.
When this is set at 1, it is completely hidden the opaque part of image.

BaseImage/BaseSprite

The base image to the mask.
In the case of the display destination handle a Sprite image only such as SpriteRenderer or Image component of UnityGUI, it becomes the item name that BaseSprite, and be able to attached a Sprite image only.

BaseImageTiling

To change the size(Number of repetitions) of BaseImage/BaseSprite.
It is the same concept as Tiling of the shader settings of Unity.

BaseImageOffset

To change the position of BaseImage/BaseSprite.
It is the same concept as Offset of the shader settings of Unity.

BaseImageWrapMode

To change the WrapMode of BaseImage.

* Notes from Unity specification *
WrapMode is state of the root image, so can not be changed it from this asset during Edit mode(when Not scene Play in Unity).
When Edit mode, WrapMode should be changed from the setting of root image in the usual way.  In build game and when scene Play in Unity, You can change the WrapMode from this asset.
However, mentioned above WrapMode is the setting of root image, so you should note that all GameObject using the same image receive a change of WrapMode all at once.
On Unity2017 or higher, you can set with U axis(horizontal direction) and V axis(vertical direction) separately.

MaskVisibility

When this is On, the image that be attached MaskImage is displayed on the scene. However, unlike InstantTextureMask, it is not displayed partly out of drawing range because it is through the shader.

VisibileMaskImage

When MaskVisibility above is On, you can select which mask image to preview the scene.

VisibileColor

When MaskVisibility above is On, you can change the color that MaskImage is displayed on the scene for easy to see.
When this setting is White(255,255,255,255), it is displayed the color of the original image. On the other hand, if the image that be assigned MaskImage is drawn with white, you can display it on the scene with free color.

* You can apply the masks up to three in InstantMaskShader.
Below it is described use the item names(variable names) in the case of Mask1 for convenience.

Mask1Image

The image to be used to mask shape.
This image is used the alpha channel or grayscale, and cut or made hole to BaseImage.

UseMask1

Whether to work the mask processing.
If turn off this, it is not masked the image instantly.

Mask1ImageTiling

To change the size(Number of repetitions) of MaskImage.
It is the same concept as Tiling of the shader settings of Unity.
If you want to mask the sprite animation, sprite image is sliced into a tidy grid, and the WrapMode of the mask image settings to Repeat and set to be this values number in the same division as the grid of the sprite image. So you can mask in the same form throughout the animation.

Mask1TilingPivotToCenter

Pivot of Tiling is normally the bottom left corner of the image, this is so as to Tiling from the center of the image. This is useful such as when the Mask size is changed without moving the Mask position.

Mask1ImageOffset

To change the position of MaskImage.
It is the same concept as Offset of the shader settings of Unity.

Mask1Degree

To adjust the masking applicability.
When this is set at 0, it is displayed the same view as not masking.

Mask1Position

To change the position of MaskImage with Pivot of Tiling and Angle. It might be a little difficult to understand the difference between Offset. For example, a Mask is moved while rotation, Offset is like the revolution of the planet. In contrast, this make easier to move like the rotation of the planet.

Mask1Angle

The angle to rotate the mask part.
The pivot in the default is the center of the mask image.

Mask2Prescribe

It change the way of the processing of the mask. The mask is applied from Mask1. Therefore, there is no need mode that except behavior to hide the mask portion (Hide mode) in Mask1, so there is not this item (and variable) that Mask1Prescribe in Mask1. In addition, if there is not earlier number mask, you can not use this item in Masek2 and Mask3 too. If there is not already hidden part by other mask, it is no need mode that except behavior to hide the mask portion (Hide mode).

 - Hide
This mode is the behavior of a typical mask that hiding the mask range.

 - Add Visible Part
This mode is a behavior such as make the image applying only this mask for the base image and overlaying that display part on the result of until this mask. For example, it make a hole shape the big star and cut out the small star in that, and separate movement them in the Shader example in the demo scene. In a conventional, this is not possible in using the masks to one base image. The small star is hidden by the mask part of the larger star and the frame of the big star is hidden by the mask part of the small star.(You will see it if you change to Hide the mode of this item in the demo scene.) The demo scene enable that because this item of Mask2 is set 'AddVisiblePart', so it is made hole shape the big star and overlaying the small star of Mask2.

 - Invert
This mode reverse the alpha value of the mask portion.
It is hidden that display part of the image, it is displayed the part that had been hidden by until this masks.

ReverceMask1Area

Either cut or made hole the shape of the mask image.

GrayscaleMask1

When this is turn Off, the alpha channel of MaskImage is used for mask processing.
When this is turn On, the brightness of the MaskImage is used.

Particle

InstantParticleMask

This is mask the Particle texture and the texture sheet animation, this basic structure is same as the InstantShaderMask that is writed before paragraph.

InstantParticleMask is compliant with the specifications of Unity shader to change the Mask size, it is changed by Tiling. The Pivot of Tiling is normally the bottom left corner of the image.
And the pivot of rotation is center of the mask image.

It need a material that have 'InstantMaskShader.shader', the material is assigned renderer of Particle(Syuriken) in same GameObject. It drow a result mask image through that material.

* Notes from Unity specification *
InstantMaskShader.shader is added properties to a Unity builtin shader for UI.
(UI-Default.shader)
If you want to mask using other shader, you must add write property of InstantMask to the other shader script yourself.
It is not possible rewrites appropriately shader script from asset, so it have no choice but to be done manually on the user side.
If you have created such a shader, it is assigned the material, and the material is applied to the Renderer.

* Notes from Unity specification 2 *
It is material behavior in Unity specifications, in build game and when scene Play in Unity, the instance material is made automatically if the same material is shared in some renderer and to be done individual rendering in each of the GameObject.
In that case is not problem, but when Edit mode (Not scene Play in Unity) Unity specifications that do not make instance material, so all GameObject using the same material receive a change of state all at once.
So when you want to see the individual masking some GameObjects that share the same material, need to confirm by scene Play.
For this behaviors, if this asset would solve such as replicate material or something, it is concern an error by discrepancy when referring to the material from such an other asset, so it leave the Unity standard behavior.
There is nothing to worry this when you use the individual materials in each GameObject.

The following is each item of the settings.

It is appears material names in the top of InstantParticleMask component that have been assigned to the renderer of Particle. As mentioned above, this must be a material that applied InstantMaskShader.shader.

ResultOpacity

To adjust the opacity of the masked result image.

AlphaCutoff

To hide the this value and under opacity part of the masked result image.
When this is set at 1, it is completely hidden the opaque part of image.

BaseImage

The base image to the mask.

BaseImageTiling

To change the size(Number of repetitions) of BaseImage.
It is the same concept as Tiling of the shader settings of Unity.

BaseImageOffset

To change the position of BaseImage/BaseSprite.
It is the same concept as Offset of the shader settings of Unity.

BaseImageWrapMode

To change the WrapMode of BaseImage.

* Notes from Unity specification *
WrapMode is state of the root image, so can not be changed it from this asset during Edit mode(when Not scene Play in Unity).
When Edit mode, WrapMode should be changed from the setting of root image in the usual way.  In build game and when scene Play in Unity, You can change the WrapMode from this asset.
However, mentioned above WrapMode is the setting of root image, so you should note that all GameObject using the same image receive a change of WrapMode all at once.
On Unity2017 or higher, you can set with U axis(horizontal direction) and V axis(vertical direction) separately.

MaskVisibility

When this is On, the image that be attached MaskImage is displayed on the scene. However, unlike InstantTextureMask, it is not displayed partly out of drawing range because it is through the shader.

VisibileMaskImage

When MaskVisibility above is On, you can select which mask image to preview the scene.

VisibileColor

When MaskVisibility above is On, you can change the color that MaskImage is displayed on the scene for easy to see.
When this setting is White(255,255,255,255), it is displayed the color of the original image. On the other hand, if the image that be assigned MaskImage is drawn with white, you can display it on the scene with free color.

* You can apply the masks up to three in InstantMaskShader.
Below it is described use the item names(variable names) in the case of Mask1 for convenience.

Mask1Image

The image to be used to mask shape.
This image is used the alpha channel or grayscale, and cut or made hole to BaseImage.

UseMask1

Whether to work the mask processing.
If turn off this, it is displayed just as the base image instantly.

Mask1ImageTiling

To change the size(Number of repetitions) of MaskImage.
It is the same concept as Tiling of the shader settings of Unity.
If you want to mask the texture sheet animation, the WrapMode of the mask image settings to Repeat and set to be this values in the same division as the partition of the texture sheet animation. So you can mask in the same form throughout the animation.

Mask1TilingPivotToCenter

Pivot of Tiling is normally the bottom left corner of the image, this is so as to Tiling from the center of the image. This is useful such as when the Mask size is changed without moving the Mask position.

Mask1ImageOffset

To change the position of MaskImage.
It is the same concept as Offset of the shader settings of Unity.

Mask1Degree

To adjust the masking applicability.
When this is set at 0, it is displayed the same view as not masking.

Mask1Position

To change the position of MaskImage with Pivot of Tiling and Angle. It might be a little difficult to understand the difference between Offset. For example, a Mask is moved while rotation, Offset is like the revolution of the planet. In contrast, this make easier to move like the rotation of the planet.

Mask1Angle

The angle to rotate the mask part.
The pivot in the default is the center of the mask image.

Mask2Prescribe

It change the way of the processing of the mask. The mask is applied from Mask1. Therefore, there is no need mode that except behavior to hide the mask portion (Hide mode) in Mask1, so there is not this item (and variable) that Mask1Prescribe in Mask1. In addition, if there is not earlier number mask, you can not use this item in Masek2 and Mask3 too. If there is not already hidden part by other mask, it is no need mode that except behavior to hide the mask portion (Hide mode).

 - Hide
This mode is the behavior of a typical mask that hiding the mask range.

 - Add Visible Part
This mode is a behavior such as make the image applying only this mask for the base image and overlaying that display part on the result of until this mask. For example, it make a hole shape the big star and cut out the small star in that, and separate movement them in the Shader example in the demo scene. In a conventional, this is not possible in using the masks to one base image. The small star is hidden by the mask part of the larger star and the frame of the big star is hidden by the mask part of the small star.(You will see it if you change to Hide the mode of this item in the demo scene.) The demo scene enable that because this item of Mask2 is set 'AddVisiblePart', so it is made hole shape the big star and overlaying the small star of Mask2.

 - Invert
This mode reverse the alpha value of the mask portion.
It is hidden that display part of the image, it is displayed the part that had been hidden by until this masks.

ReverceMask1Area

Either cut or made hole the shape of the mask image.

GrayscaleMask1

When this is turn Off, the alpha channel of MaskImage is used for mask processing.
When this is turn On, the brightness of the MaskImage is used.

Support

If you have inquiry or demand, please feel free to write in the support forum.

When a new version comes out, it will be written on the support forums such as points of modification. Please take a look there occasionally. Or you can see the simple history, check the release notes in the linked page.

Please obtain from the asset store if a new version was out.