ImageEffects.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using UnityEngine;
  2. //using System;
  3. /// A Utility class for performing various image based rendering tasks.
  4. [AddComponentMenu("")]
  5. public class ImageEffects
  6. {
  7. public static void RenderDistortion(Material material, RenderTexture source, RenderTexture destination, float angle, Vector2 center, Vector2 radius)
  8. {
  9. bool invertY = source.texelSize.y < 0.0f;
  10. if (invertY)
  11. {
  12. center.y = 1.0f - center.y;
  13. angle = -angle;
  14. }
  15. Matrix4x4 rotationMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, angle), Vector3.one);
  16. material.SetMatrix("_RotationMatrix", rotationMatrix);
  17. material.SetVector("_CenterRadius", new Vector4(center.x, center.y, radius.x, radius.y));
  18. material.SetFloat("_Angle", angle * Mathf.Deg2Rad);
  19. Graphics.Blit(source, destination, material);
  20. }
  21. [System.Obsolete("Use Graphics.Blit(source,dest) instead")]
  22. public static void Blit(RenderTexture source, RenderTexture dest)
  23. {
  24. Graphics.Blit(source, dest);
  25. }
  26. [System.Obsolete("Use Graphics.Blit(source, destination, material) instead")]
  27. public static void BlitWithMaterial(Material material, RenderTexture source, RenderTexture dest)
  28. {
  29. Graphics.Blit(source, dest, material);
  30. }
  31. }