mirror of
https://github.com/ApfelTeeSaft/Slender.git
synced 2026-08-27 03:43:28 +00:00
187 lines
4.3 KiB
C#
187 lines
4.3 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
[Serializable]
|
|
[ExecuteInEditMode]
|
|
[RequireComponent(typeof(Camera))]
|
|
public class PostEffectsHelper : MonoBehaviour
|
|
{
|
|
public virtual void Start()
|
|
{
|
|
}
|
|
|
|
public virtual void OnRenderImage(RenderTexture source, RenderTexture destination)
|
|
{
|
|
Debug.Log("OnRenderImage in Helper called ...");
|
|
}
|
|
|
|
public static void DrawLowLevelPlaneAlignedWithCamera(float dist, RenderTexture source, RenderTexture dest, Material material, Camera cameraForProjectionMatrix)
|
|
{
|
|
RenderTexture.active = dest;
|
|
material.SetTexture("_MainTex", source);
|
|
bool flag = true;
|
|
GL.PushMatrix();
|
|
GL.LoadIdentity();
|
|
GL.LoadProjectionMatrix(cameraForProjectionMatrix.projectionMatrix);
|
|
float f = cameraForProjectionMatrix.fieldOfView * 0.5f * ((float)Math.PI / 180f);
|
|
float num = Mathf.Cos(f) / Mathf.Sin(f);
|
|
float aspect = cameraForProjectionMatrix.aspect;
|
|
float num2 = aspect / (0f - num);
|
|
float num3 = aspect / num;
|
|
float num4 = 1f / (0f - num);
|
|
float num5 = 1f / num;
|
|
float num6 = 1f;
|
|
num2 *= dist * num6;
|
|
num3 *= dist * num6;
|
|
num4 *= dist * num6;
|
|
num5 *= dist * num6;
|
|
float z = 0f - dist;
|
|
for (int i = 0; i < material.passCount; i++)
|
|
{
|
|
material.SetPass(i);
|
|
GL.Begin(7);
|
|
float num7 = default(float);
|
|
float num8 = default(float);
|
|
if (flag)
|
|
{
|
|
num7 = 1f;
|
|
num8 = 0f;
|
|
}
|
|
else
|
|
{
|
|
num7 = 0f;
|
|
num8 = 1f;
|
|
}
|
|
GL.TexCoord2(0f, num7);
|
|
GL.Vertex3(num2, num4, z);
|
|
GL.TexCoord2(1f, num7);
|
|
GL.Vertex3(num3, num4, z);
|
|
GL.TexCoord2(1f, num8);
|
|
GL.Vertex3(num3, num5, z);
|
|
GL.TexCoord2(0f, num8);
|
|
GL.Vertex3(num2, num5, z);
|
|
GL.End();
|
|
}
|
|
GL.PopMatrix();
|
|
}
|
|
|
|
public static void DrawBorder(RenderTexture dest, Material material)
|
|
{
|
|
float num = default(float);
|
|
float num2 = default(float);
|
|
float num3 = default(float);
|
|
float num4 = default(float);
|
|
RenderTexture.active = dest;
|
|
bool flag = true;
|
|
GL.PushMatrix();
|
|
GL.LoadOrtho();
|
|
for (int i = 0; i < material.passCount; i++)
|
|
{
|
|
material.SetPass(i);
|
|
float num5 = default(float);
|
|
float num6 = default(float);
|
|
if (flag)
|
|
{
|
|
num5 = 1f;
|
|
num6 = 0f;
|
|
}
|
|
else
|
|
{
|
|
num5 = 0f;
|
|
num6 = 1f;
|
|
}
|
|
num = 0f;
|
|
num2 = 0f + 1f / ((float)dest.width * 1f);
|
|
num3 = 0f;
|
|
num4 = 1f;
|
|
GL.Begin(7);
|
|
GL.TexCoord2(0f, num5);
|
|
GL.Vertex3(num, num3, 0.1f);
|
|
GL.TexCoord2(1f, num5);
|
|
GL.Vertex3(num2, num3, 0.1f);
|
|
GL.TexCoord2(1f, num6);
|
|
GL.Vertex3(num2, num4, 0.1f);
|
|
GL.TexCoord2(0f, num6);
|
|
GL.Vertex3(num, num4, 0.1f);
|
|
num = 1f - 1f / ((float)dest.width * 1f);
|
|
num2 = 1f;
|
|
num3 = 0f;
|
|
num4 = 1f;
|
|
GL.TexCoord2(0f, num5);
|
|
GL.Vertex3(num, num3, 0.1f);
|
|
GL.TexCoord2(1f, num5);
|
|
GL.Vertex3(num2, num3, 0.1f);
|
|
GL.TexCoord2(1f, num6);
|
|
GL.Vertex3(num2, num4, 0.1f);
|
|
GL.TexCoord2(0f, num6);
|
|
GL.Vertex3(num, num4, 0.1f);
|
|
num = 0f;
|
|
num2 = 1f;
|
|
num3 = 0f;
|
|
num4 = 0f + 1f / ((float)dest.height * 1f);
|
|
GL.TexCoord2(0f, num5);
|
|
GL.Vertex3(num, num3, 0.1f);
|
|
GL.TexCoord2(1f, num5);
|
|
GL.Vertex3(num2, num3, 0.1f);
|
|
GL.TexCoord2(1f, num6);
|
|
GL.Vertex3(num2, num4, 0.1f);
|
|
GL.TexCoord2(0f, num6);
|
|
GL.Vertex3(num, num4, 0.1f);
|
|
num = 0f;
|
|
num2 = 1f;
|
|
num3 = 1f - 1f / ((float)dest.height * 1f);
|
|
num4 = 1f;
|
|
GL.TexCoord2(0f, num5);
|
|
GL.Vertex3(num, num3, 0.1f);
|
|
GL.TexCoord2(1f, num5);
|
|
GL.Vertex3(num2, num3, 0.1f);
|
|
GL.TexCoord2(1f, num6);
|
|
GL.Vertex3(num2, num4, 0.1f);
|
|
GL.TexCoord2(0f, num6);
|
|
GL.Vertex3(num, num4, 0.1f);
|
|
GL.End();
|
|
}
|
|
GL.PopMatrix();
|
|
}
|
|
|
|
public static void DrawLowLevelQuad(float x1, float x2, float y1, float y2, RenderTexture source, RenderTexture dest, Material material)
|
|
{
|
|
RenderTexture.active = dest;
|
|
material.SetTexture("_MainTex", source);
|
|
bool flag = true;
|
|
GL.PushMatrix();
|
|
GL.LoadOrtho();
|
|
for (int i = 0; i < material.passCount; i++)
|
|
{
|
|
material.SetPass(i);
|
|
GL.Begin(7);
|
|
float num = default(float);
|
|
float num2 = default(float);
|
|
if (flag)
|
|
{
|
|
num = 1f;
|
|
num2 = 0f;
|
|
}
|
|
else
|
|
{
|
|
num = 0f;
|
|
num2 = 1f;
|
|
}
|
|
GL.TexCoord2(0f, num);
|
|
GL.Vertex3(x1, y1, 0.1f);
|
|
GL.TexCoord2(1f, num);
|
|
GL.Vertex3(x2, y1, 0.1f);
|
|
GL.TexCoord2(1f, num2);
|
|
GL.Vertex3(x2, y2, 0.1f);
|
|
GL.TexCoord2(0f, num2);
|
|
GL.Vertex3(x1, y2, 0.1f);
|
|
GL.End();
|
|
}
|
|
GL.PopMatrix();
|
|
}
|
|
|
|
public virtual void Main()
|
|
{
|
|
}
|
|
}
|