Custom shader does not update if masked,

I have an issue that has been partially addressed elsewhere (like http://answers.unity3d.com/questions/980924/ui-mask-with-shader.html and
http://answers.unity3d.com/questions/1004826/custom-ui-material-with-mask.html), but in my case i am trying to also update the shader, and this solution : http://answers.unity3d.com/questions/1130203/ui-mask-override-my-shaders-custom-property.html did nothing in my case.

This is my shader :

Shader "MyLinearGradient"
{
	Properties{
		_TopColor("Top color", Color) = (1,1,1,1)
		_BottomColor("Bottom color", Color) = (1,1,1,1)
		_Offset("Offset",Float) = 0

		// required for UI.Mask
		_StencilComp("Stencil Comparison", Float) = 8
		_Stencil("Stencil ID", Float) = 0
		_StencilOp("Stencil Operation", Float) = 0
		_StencilWriteMask("Stencil Write Mask", Float) = 255
		_StencilReadMask("Stencil Read Mask", Float) = 255
		_ColorMask("Color Mask", Float) = 15
	}
		SubShader
	{
		Tags
		{
			"Queue" = "Transparent"
			"IgnoreProjector" = "True"
			"RenderType" = "Transparent"
			"PreviewType" = "Plane"
			"CanUseSpriteAtlas" = "True"
		}
		LOD 100

		Stencil
		{
			Ref[_Stencil]
			Comp[_StencilComp]
			Pass[_StencilOp]
			ReadMask[_StencilReadMask]
			WriteMask[_StencilWriteMask]
		}
		ColorMask[_ColorMask]
		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			#include "UnityCG.cginc"

			fixed4 _TopColor;
			fixed4 _BottomColor;
			float1 _Offset;

			struct v2f {
				float4 position : SV_POSITION;
				fixed4 color : COLOR;
			};

			v2f vert(appdata_full v)
			{
				v2f o;
				o.position = mul(UNITY_MATRIX_MVP, v.vertex);
				float1 IntOffset = v.texcoord.y + v.texcoord.x + _Offset;
				o.color.r = cos(IntOffset)*(_TopColor.r - _BottomColor.r) + _BottomColor.r;
				o.color.g = cos(IntOffset)*(_TopColor.g - _BottomColor.g) + _BottomColor.g;
				o.color.b = cos(IntOffset)*(_TopColor.b - _BottomColor.b) + _BottomColor.b;
				o.color.a = cos(IntOffset)*(_TopColor.a - _BottomColor.a) + _BottomColor.a;
				return o;
			}

			fixed4 frag(v2f i) : SV_Target
			{
				float4 color = i.color;
				color.a = 1;
				return color;
			}
			ENDCG
		}
	}
}

which i try to slide with the _offset parameter. The material works fine except if it is under a ui mask.
i also attach a [79778-cognichess.zip|79778] in order to see it live.

Thank you in advance

,

I have just experienced the same issue like in this case: https://forum.unity3d.com/threads/masked-ui-elements-shader-not-updating.371542/
One hint from that post could be that “[…] the material that you are referencing for the animation is not the one that is being used to draw (using the original vs the copied)” …
But I still have no clue nor any workaround …

I am actually trying to cover a kind of healthbar with a Material, who’s offset gets controlled via script to generate a flowing effect… The problem is, that my “healthbar” is not perfectly rectangular, so I tried to apply an UI Mask on the flowing Material.

I hope that someone will soon have a solution for this.