码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3D Shader图像扭曲过场效果

时间:2017-09-20 00:51:23      阅读:390      评论:0      收藏:0      [点我收藏+]

标签:one   des   target   graph   nbsp   highlight   alt   int   material   

技术分享

 

把脚本挂在摄像机上

using UnityEngine;
using System.Collections;


[RequireComponent(typeof(Camera))]
public class PostEffectTwist : MonoBehaviour {

	public Material ma;


	void OnRenderImage(RenderTexture src, RenderTexture dest)
	{
		Graphics.Blit (src, dest, ma);
	}
}

 

创建一个材质,再创建一个Shader

Shader "Hidden/NewImageEffectShader"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
		_Angle ("Rotation", Float) = 0
	}
	SubShader
	{
		// No culling or depth
		Cull Off ZWrite Off ZTest Always

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			
			#include "UnityCG.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
			};

			v2f vert (appdata v)
			{
				v2f o;
				o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
				o.uv = v.uv;
				return o;
			}
			
			sampler2D _MainTex;
			float _Angle;

			fixed4 frag (v2f i) : SV_Target
			{
				float2 uv = float2(i.uv.x-0.5,i.uv.y-0.5);
				float f = distance(uv,float2(0,0));
				float s = sin(lerp(0,_Angle,f));
				float c = cos(lerp(0,_Angle,f));
				// -c s
				// s  c

				uv = float2(-uv.x*c+uv.y*s,uv.x*s+uv.y*c);
				uv = float2(uv.x+0.5,uv.y+0.5);
				fixed4 col = tex2D(_MainTex, uv);

				return col;
			}
			ENDCG
		}
	}
}

  

 

Unity3D Shader图像扭曲过场效果

标签:one   des   target   graph   nbsp   highlight   alt   int   material   

原文地址:http://www.cnblogs.com/mrblue/p/7554806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!