Unity特效(1) 梦幻旋屏


原文链接 :点击打开链接


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"
}



C#部分的代码:


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);
    }
}



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值