As usual, I had to reinvent the wheel.
Here is a shader that use alpha blending(Iphone 4 friendly) instead of discard fragment. It has a X and Y crop variables that you can drive via script.
If you encounter issues with z-ordering change the render queue to a higher number.
Interesting approach @00christian00 , would you be ok with this being added to the UI Extensions project. As an ask, if you are ok with that. Could you also supply an alternate Mask script that would with with the new shader?
Sure! You are free to do whatever you want with it.
I am not familiar with Unity UI source. Where do I find the original mask script so that I can use it as a template?
Actually upon further testing I think I may be wrong on the assumption that it’s using discard fragment.
It seem it’s using a glStencil and the previous issue was probably some placeholder in my scene using Alpha testing.
Can anybody confirm?
Anyway the shader solution seem to be still quite faster, as the mask seem to produce lots of open gl calls.
It is several ms faster in my system and it did allow me to go from 20-22 to 22-24 fps. A nice 10% boost on a single mask.
Doesn’t necessarily need to be a copy of the UI mask. Just so it’s easily implementable by others as a component and any pre-reqs needed. UI Extensions link in sig.
Any update @00christian00 if you’re stuff, I can try and create a script anyway, but thought since you’d already worked on it, you would have the best idea.
Right, got them in and working on an example, however running into a slight usability issue. Possibly to to my miss-interpretation of the aim of this improved control.
If I have an image with the unity mask component added and a child image (larger that the mask( . It only draws within the bounds of the mask.
However if I do the same for the new Shader based mask here, the Mask doesn’t affect the base image.
if I reverse it have have the mask on top of the image, it just draws the image.
Is the aim of this to provide a partially drawn image (similar to the Filled Image type) or meant to mask a child / parent image?
It does only mask the gameobject where the script is. Doesn’t take into account child object as it’s just a shader rendering a portion of the image. Basically a blit operation and from reading the docs seem similar to filled image.
For example in my game I am using it to draw a fill bar, you just need the full bar graphics and set the crop ratio to make part of that bar disappear.
Ahh right, so it isn’t a mask at all really, just a shader way of drawing a partial image.
So more of a replacement way of doing the Image Fill. Ok, will see if I can find some interesting ways to apply it
Although as a feature request, would be good to also be able to position the fill position (only works from top-left currently) and support other fill modes (circular / radial, etc).
Have a look at the fill options in the ImageExtended control and see if you can do the same but using your shader method