I’m working with an artist on a UI based game and he wants to have a smooth “blend to white” effect on an image. The game is in black and white.
I wrote a very simple shader that clamps the minimum value of rgb to a float value between 0 and 1.
I made a material out of it and made a testing script that would change this material.
We want to achieve this effect !
)
At first I thought it did not work because of the UI Image not being instantiated like meshes material, so I sort of instantiated my material to reassign it at runtime (I’m not sure it would actually change anything I’m just poking in the dark here)
Here’s my code anyway :
private Image myImage;
public Material instanceOfMat;
public Shader shader;
public Color blendColor;
public float blendStrengh;
// Use this for initialization
void Awake () {
myImage = GetComponent<Image>();
instanceOfMat = new Material(shader);
instanceOfMat.SetColor("Blend Color", blendColor);
instanceOfMat.SetFloat("Flashing White", blendStrengh);
}
// Update is called once per frame
void Update () {
instanceOfMat.SetColor("Blend Color", blendColor);
instanceOfMat.SetFloat("Flashing White", blendStrengh);
myImage.material = instanceOfMat;
}
But it does not work at all and I’m out of solutions, maybe I’m not considering the problem the right way !
Thank you very much !
Also here’s my Fragment shader
fixed4 frag(v2f i) : SV_Target
{
fixed4 blendStr = _BlendStrengh;
// Sample the texture and blend with color
fixed4 col = tex2D(_MainTex, i.uv) * _BlendColor;
//Adjust how intense is the white flash
col.r = clamp(col.r, blendStr, 1);
col.g = clamp(col.g, blendStr, 1);
col.b = clamp(col.b, blendStr, 1);
return col;
}