69 lines
1.6 KiB
C#
69 lines
1.6 KiB
C#
using UnityEngine;
|
|
|
|
namespace Es.InkPainter.Effective
|
|
{
|
|
public static class ReverseUV
|
|
{
|
|
private const string REVERSE_UV_MATERIAL = "Es.InkPainter.Effective.ReverseUV";
|
|
|
|
private const string REVERSE_X = "_ReverseX";
|
|
|
|
private const string REVERSE_Y = "_ReverseY";
|
|
|
|
private const float DEFAULT = 1f;
|
|
|
|
private const float REVERSE = 0f;
|
|
|
|
private static Material reverseUVMaterial;
|
|
|
|
public static void Horizontal(Texture src, RenderTexture dst)
|
|
{
|
|
if (reverseUVMaterial == null)
|
|
{
|
|
InitReverseUVMaterial();
|
|
}
|
|
SetReverseUVProperty(0f, 1f);
|
|
Blit(src, dst);
|
|
}
|
|
|
|
public static void Vertical(Texture src, RenderTexture dst)
|
|
{
|
|
if (reverseUVMaterial == null)
|
|
{
|
|
InitReverseUVMaterial();
|
|
}
|
|
SetReverseUVProperty(1f, 0f);
|
|
Blit(src, dst);
|
|
}
|
|
|
|
public static void HorizontalAndVertical(Texture src, RenderTexture dst)
|
|
{
|
|
if (reverseUVMaterial == null)
|
|
{
|
|
InitReverseUVMaterial();
|
|
}
|
|
SetReverseUVProperty(0f, 0f);
|
|
Blit(src, dst);
|
|
}
|
|
|
|
private static void InitReverseUVMaterial()
|
|
{
|
|
reverseUVMaterial = new Material(Resources.Load<Material>("Es.InkPainter.Effective.ReverseUV"));
|
|
}
|
|
|
|
private static void SetReverseUVProperty(float x, float y)
|
|
{
|
|
reverseUVMaterial.SetFloat("_ReverseX", x);
|
|
reverseUVMaterial.SetFloat("_ReverseY", y);
|
|
}
|
|
|
|
private static void Blit(Texture src, RenderTexture dst)
|
|
{
|
|
RenderTexture temporary = RenderTexture.GetTemporary(src.width, src.height, 0);
|
|
Graphics.Blit(src, temporary, reverseUVMaterial);
|
|
Graphics.Blit(temporary, dst);
|
|
RenderTexture.ReleaseTemporary(temporary);
|
|
}
|
|
}
|
|
}
|