原文链接 :点击打开链接
shader部分代码:
Shader "Custom/ScreenRot"
{
Properties
{
_MainTex ("Main Tex", 2D) = "white" {}
_Rot ("Rotation", float) = 0
}
SubShader
{
Tags {"Queue" = "Geometry"}
Pass
{
Tags {"LightMode" = "ForwardBase"}
ZWrite Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#define PI 3.14159265358979
sampler2D _MainTex;
float _Rot;
struct a2v
{
float4 vertex : POSITION;
float3 texcoord : TEXCOORD0;
};
struct v2f
{
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
v2f vert(a2v v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.texcoord;
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float distance = sqrt((i.uv.x - 0.5) * (i.uv.x - 0.5) + (i.uv.y - 0.5) * (i.uv.y - 0.5));
_Rot *= distance;
float angle = step(i.uv.x, 0.5) * PI + atan((i.uv.y - 0.5) / (i.uv.x - 0.5)) + _Rot;
i.uv.x = 0.5 + distance * cos(angle);
i.uv.y = 0.5 + distance * sin(angle);
fixed4 c = tex2D(_MainTex, i.uv);
return c;
}
ENDCG
}
}
FallBack "Specular"
}
using UnityEngine;
using System.Collections;
public class ScreenRot : MonoBehaviour
{
public Material mtl;
public float rot;
// Update is called once per frame
void Update()
{
if (rot > 0)
rot -= 1.5f;
else
rot = 0;
}
void OnRenderImage(RenderTexture src, RenderTexture dest)
{
if (rot == 0.0)
return;
mtl.SetFloat("_Rot", rot);
Graphics.Blit(src, dest, mtl);
}
}