Fisheye.js 838 B

123456789101112131415161718192021222324252627282930
  1. @script ExecuteInEditMode
  2. @script AddComponentMenu ("Image Effects/Fisheye")
  3. class Fisheye extends PostEffectsBase {
  4. public var strengthX : float = 0.05;
  5. public var strengthY : float = 0.05;
  6. public var fishEyeShader : Shader = null;
  7. private var _fisheyeMaterial : Material = null;
  8. function CreateMaterials () {
  9. _fisheyeMaterial = CheckShaderAndCreateMaterial(fishEyeShader,_fisheyeMaterial);
  10. }
  11. function Start () {
  12. CreateMaterials ();
  13. CheckSupport(false);
  14. }
  15. function OnRenderImage (source : RenderTexture, destination : RenderTexture)
  16. {
  17. CreateMaterials ();
  18. var ar : float = (source.width * 1.0) / (source.height * 1.0);
  19. _fisheyeMaterial.SetVector ("intensity", Vector4 (strengthX * ar, strengthY * ar, strengthX * ar, strengthY * ar));
  20. Graphics.Blit (source, destination, _fisheyeMaterial);
  21. }
  22. }