You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
2 months ago
|
|
||
|
#pragma strict
|
||
|
|
||
|
@script ExecuteInEditMode
|
||
|
@script RequireComponent (Camera)
|
||
|
@script AddComponentMenu ("Image Effects/Fisheye")
|
||
|
|
||
|
class Fisheye extends PostEffectsBase {
|
||
|
public var strengthX : float = 0.05f;
|
||
|
public var strengthY : float = 0.05f;
|
||
|
|
||
|
public var fishEyeShader : Shader = null;
|
||
|
private var fisheyeMaterial : Material = null;
|
||
|
|
||
|
function OnDisable()
|
||
|
{
|
||
|
if (fisheyeMaterial)
|
||
|
DestroyImmediate(fisheyeMaterial);
|
||
|
}
|
||
|
function CheckResources () : boolean {
|
||
|
CheckSupport (false);
|
||
|
fisheyeMaterial = CheckShaderAndCreateMaterial(fishEyeShader,fisheyeMaterial);
|
||
|
|
||
|
if(!isSupported)
|
||
|
ReportAutoDisable ();
|
||
|
return isSupported;
|
||
|
}
|
||
|
|
||
|
function OnRenderImage (source : RenderTexture, destination : RenderTexture) {
|
||
|
if(CheckResources()==false) {
|
||
|
Graphics.Blit (source, destination);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var oneOverBaseSize : float = 80.0f / 512.0f; // to keep values more like in the old version of fisheye
|
||
|
|
||
|
var ar : float = (source.width * 1.0f) / (source.height * 1.0f);
|
||
|
|
||
|
fisheyeMaterial.SetVector ("intensity", Vector4 (strengthX * ar * oneOverBaseSize, strengthY * oneOverBaseSize, strengthX * ar * oneOverBaseSize, strengthY * oneOverBaseSize));
|
||
|
Graphics.Blit (source, destination, fisheyeMaterial);
|
||
|
}
|
||
|
}
|