Tanoda
TextureMorphing.cs
Go to the documentation of this file.
1using UnityEngine;
2
4{
8 public static class TextureMorphing
9 {
10 #region PrivateField
11
12 private const string TEXTURE_MORPHING_MATERIAL = "Es.InkPainter.Effective.TextureMorphing";
13 private const string LERP_COEFFICIENT = "_LerpCoef";
14 private const string SRC_TEX = "_SrcTex";
15 private const string DST_TEX = "_DstTex";
16
17 private static Material morphingMaterial;
18
19 #endregion PrivateField
20
21 #region PublicMethod
22
29 public static void Lerp(Texture src, RenderTexture dst, float lerpCoef)
30 {
31 if (morphingMaterial == null)
32 InitMorphingMaterial();
33 SetMorphingProperty(src, dst, lerpCoef);
34 var tmp = RenderTexture.GetTemporary(src.width, src.height);
35 Graphics.Blit(src, tmp, morphingMaterial);
36 Graphics.Blit(tmp, dst);
37 RenderTexture.ReleaseTemporary(tmp);
38 }
39
40 #endregion PublicMethod
41
42 #region PrivateMethod
43
44 private static void InitMorphingMaterial()
45 {
46 morphingMaterial = new Material(Resources.Load<Material>(TEXTURE_MORPHING_MATERIAL));
47 }
48
49 private static void SetMorphingProperty(Texture src, RenderTexture dst, float lerpCoef)
50 {
51 morphingMaterial.SetTexture(Shader.PropertyToID(SRC_TEX), src);
52 morphingMaterial.SetTexture(Shader.PropertyToID(DST_TEX), dst);
53 morphingMaterial.SetFloat(Shader.PropertyToID(LERP_COEFFICIENT), lerpCoef);
54 }
55
56 #endregion PrivateMethod
57 }
58}