mirror of
https://github.com/ApfelTeeSaft/Slender.git
synced 2026-08-27 03:43:28 +00:00
60 lines
1.2 KiB
C#
60 lines
1.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
[ExecuteInEditMode]
|
|
[RequireComponent(typeof(Camera))]
|
|
[AddComponentMenu("Image Effects/Fisheye")]
|
|
public class Fisheye : PostEffectsBase
|
|
{
|
|
public float strengthX;
|
|
|
|
public float strengthY;
|
|
|
|
public Shader fishEyeShader;
|
|
|
|
private Material fisheyeMaterial;
|
|
|
|
public Fisheye()
|
|
{
|
|
strengthX = 0.05f;
|
|
strengthY = 0.05f;
|
|
}
|
|
|
|
public virtual void OnDisable()
|
|
{
|
|
if ((bool)fisheyeMaterial)
|
|
{
|
|
UnityEngine.Object.DestroyImmediate(fisheyeMaterial);
|
|
}
|
|
}
|
|
|
|
public override bool CheckResources()
|
|
{
|
|
CheckSupport(false);
|
|
fisheyeMaterial = CheckShaderAndCreateMaterial(fishEyeShader, fisheyeMaterial);
|
|
if (!isSupported)
|
|
{
|
|
ReportAutoDisable();
|
|
}
|
|
return isSupported;
|
|
}
|
|
|
|
public virtual void OnRenderImage(RenderTexture source, RenderTexture destination)
|
|
{
|
|
if (!CheckResources())
|
|
{
|
|
Graphics.Blit(source, destination);
|
|
return;
|
|
}
|
|
float num = 5f / 32f;
|
|
float num2 = (float)source.width * 1f / ((float)source.height * 1f);
|
|
fisheyeMaterial.SetVector("intensity", new Vector4(strengthX * num2 * num, strengthY * num, strengthX * num2 * num, strengthY * num));
|
|
Graphics.Blit(source, destination, fisheyeMaterial);
|
|
}
|
|
|
|
public override void Main()
|
|
{
|
|
}
|
|
}
|