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

Unity Twist Effect Black Hole

时间:2016-03-12 18:40:23      阅读:389      评论:0      收藏:0      [点我收藏+]

标签:

 

技术分享

 

技术分享

Shader "Hidden/Twist Effect" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}

SubShader
{
Pass
{
ZTest Always Cull Off ZWrite Off
Fog { Mode off }

CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma fragmentoption ARB_precision_hint_fastest

#include "UnityCG.cginc"

uniform sampler2D _MainTex;

uniform float4 _MainTex_ST;

uniform float4 _MainTex_TexelSize;
uniform float _Angle;
uniform float4 _CenterRadius;

inline float TriWave(float x)
{
return abs(frac(x) * 2-1 )-0.5;

}
struct v2f {
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float2 uvOrig : TEXCOORD1;
};

v2f vert (appdata_img v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
float2 uv = v.texcoord.xy - _CenterRadius.xy;
o.uv = TRANSFORM_TEX(uv, _MainTex); //MultiplyUV (UNITY_MATRIX_TEXTURE0, uv);
o.uvOrig = uv;
return o;
}

float4 frag (v2f i) : COLOR
{
float2 offset = i.uvOrig;
float t = TriWave(_Time.y * 0.05);
float angle = 1.0 - length(offset / (_CenterRadius.zw*t ));
angle = max (0, angle);
angle = angle * _Angle * t;
float cosLength, sinLength;
sincos (angle, sinLength, cosLength);

float2 uv;
uv.x = cosLength * offset[0] - sinLength * offset[1];
uv.y = sinLength * offset[0] + cosLength * offset[1];
uv += _CenterRadius.xy;

return tex2D(_MainTex, uv) * (1 - abs(angle * 0.5));
}
ENDCG

}
}

Fallback off

}

Unity Twist Effect Black Hole

标签:

原文地址:http://www.cnblogs.com/bearworks/p/5269481.html

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