How to Lerp between two materials

Hey,

I’m trying to make a transition between 2 materials, but I’m not having success as the example given in the documentation.

I need to change a material [Shader: Sprites / Default] to [Shader: Sprites / Diffuse], is it possible?

public class ChangeMaterial : MonoBehaviour {

    public Material materialA;
    public Material materialB;

    public float duration = 2.0f;

    void Update()
    {
        var sprite = GetComponent<SpriteRenderer>();
        var lerp = Mathf.PingPong(Time.time, duration) / duration;
        sprite.material.Lerp(materialA, materialB, lerp);
    }
}

With this code nothing happens!

What could be wrong?

Every help is welcome!

I don’t believe this is possible on the CPU, no. You’d have to write a custom shader. Start with the source code of the two you’re using now. Identify the differences, add a lerp variable and in the pixel shader lerp between the two results. Optimizing that could be tricky, and you’ll have to make sure you condense the logic so you don’t exceed the shader instruction limit.