UnityMol  0.9.6-875
UnityMol viewer / In developement
Fisheye.cs
Go to the documentation of this file.
1 using System;
2 using UnityEngine;
3 
4 namespace UnityStandardAssets.ImageEffects
5 {
6  [ExecuteInEditMode]
7  [RequireComponent (typeof(Camera))]
8  [AddComponentMenu ("Image Effects/Displacement/Fisheye")]
9  public class Fisheye : PostEffectsBase
10  {
11  [Range(0.0f, 1.5f)]
12  public float strengthX = 0.05f;
13  [Range(0.0f, 1.5f)]
14  public float strengthY = 0.05f;
15 
16  public Shader fishEyeShader = null;
17  private Material fisheyeMaterial = null;
18 
19 
20  public override bool CheckResources ()
21  {
22  CheckSupport (false);
23  fisheyeMaterial = CheckShaderAndCreateMaterial(fishEyeShader,fisheyeMaterial);
24 
25  if (!isSupported)
26  ReportAutoDisable ();
27  return isSupported;
28  }
29 
30  void OnRenderImage (RenderTexture source, RenderTexture destination)
31  {
32  if (CheckResources()==false)
33  {
34  Graphics.Blit (source, destination);
35  return;
36  }
37 
38  float oneOverBaseSize = 80.0f / 512.0f; // to keep values more like in the old version of fisheye
39 
40  float ar = (source.width * 1.0f) / (source.height * 1.0f);
41 
42  fisheyeMaterial.SetVector ("intensity", new Vector4 (strengthX * ar * oneOverBaseSize, strengthY * oneOverBaseSize, strengthX * ar * oneOverBaseSize, strengthY * oneOverBaseSize));
43  Graphics.Blit (source, destination, fisheyeMaterial);
44  }
45  }
46 }
void OnRenderImage(RenderTexture source, RenderTexture destination)
Definition: Fisheye.cs:30