ImageEffects.cs 1.4 KB

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