The problem is that I can not find easy solution for masking. Line renderer can not be sprite mask but that might have been the easiest way.
The easiest way is to instantiate some mask pointer (sprite mask) in every move but for me it’s not complex solution because we get too many objects.
How can I get result like in example in the simplest and performance way?
You could just paint a texture with C#, it is not that complex. For most performance you should use native pixel data. Also for a simple mask just a single channel texture will work. Lower resolution textures will work faster
For more performance, you can use an additional non-native pixel array to modify its values only if those pixels are not painted; then copy the data to the native pixel array periodically or something; test this yourself. I do this to skip complex paint logic. Periodically updating data instead of every frame might also help with reducing cpu-gpu bus usage
Here is some example code Unity - Scripting API: Texture2D.GetPixelData
Note that this example uses mipmaps, you probably won’t want to use them. Also the example uses a 4 channel texture, hence why it does this:
CustomMask.shader (1.0 KB)
I think i’m super late at this point but this is a very basic shader that may look clumsy but i created a material using this shader, and then assigned that material to a line renderer, and the line renderer actually acted as a mask.
If you want a normal mask with no extra condition, this works perfectly fine.
The problem with this shader is that it can only work as a common “SpriteMask”, compared to “SpriteMask” component of Unity, which has the ability to mask a specific range of sorting layers, this shader feels like a very unuseful thing to use.
But again, if a common mask for line renderer is all you want then this works perfectly fine.
If you found out how to do this already, i’d love to know how and if your solution is usable for specific layers instead of just a bland common mask.