using UnityEngine; namespace Es.InkPainter.Effective { public static class TextureMorphing { private const string TEXTURE_MORPHING_MATERIAL = "Es.InkPainter.Effective.TextureMorphing"; private const string LERP_COEFFICIENT = "_LerpCoef"; private const string SRC_TEX = "_SrcTex"; private const string DST_TEX = "_DstTex"; private static Material morphingMaterial; public static void Lerp(Texture src, RenderTexture dst, float lerpCoef) { if (morphingMaterial == null) { InitMorphingMaterial(); } SetMorphingProperty(src, dst, lerpCoef); RenderTexture temporary = RenderTexture.GetTemporary(src.width, src.height); Graphics.Blit(src, temporary, morphingMaterial); Graphics.Blit(temporary, dst); RenderTexture.ReleaseTemporary(temporary); } private static void InitMorphingMaterial() { morphingMaterial = new Material(Resources.Load("Es.InkPainter.Effective.TextureMorphing")); } private static void SetMorphingProperty(Texture src, RenderTexture dst, float lerpCoef) { morphingMaterial.SetTexture(Shader.PropertyToID("_SrcTex"), src); morphingMaterial.SetTexture(Shader.PropertyToID("_DstTex"), dst); morphingMaterial.SetFloat(Shader.PropertyToID("_LerpCoef"), lerpCoef); } } }