U3D流光效果

流光效果是一个非常常见的效果,不仅仅是游戏,一些广告之类的也都会有这种效果。

实现原理:
需要一张流光图,流光图的大部分都是黑色的,然后又一条亮线。
在采样的时候,最终输出叠加上这张图的采样值,根据时间调整采样UV就可以有流光效果。

流光图

Shader "Sprite2D/Flash2D"
{
	Properties
	{
		_MainTex("Main Texture", 2D) = "white" {}
		_FlashTex("Flash Texture",2D) = "white"{}
		_FlashColor("Flash Color",Color) = (1,1,1,1)
		_FlashIntensity("Flash Intensity", Range(0, 1)) = 0.6
		_Radian("Radian", Range(0, 3.14)) = 2.4
		_FlashSpeed("Flash Speed", Range(-5, 5)) = 0
		_Limit("Limit Start",float) = 0.5
		_Limit2("Limit End",float) = 1.9
	    _RunDelay("Run Delay",float) = 5
	}
	SubShader
	{
		Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
		Blend SrcAlpha OneMinusSrcAlpha
		Cull Off
		ZWrite Off
		Pass
		{
		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag

		#include "UnityCG.cginc"

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

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

		sampler2D _FlashTex;
		sampler2D _MainTex;
		float4 _MainTex_ST;
		fixed4 _FlashColor;
		fixed _FlashIntensity;
		fixed _Radian;
		fixed _FlashSpeed;
		fixed _Limit;
		fixed _Limit2;
		fixed _RunDelay;

		v2f vert(appdata v)
		{
			v2f o;
			o.vertex = UnityObjectToClipPos(v.vertex);
			o.uv = TRANSFORM_TEX(v.uv, _MainTex);
			
			return o;
		}

		fixed4 frag(v2f i) : SV_Target
		{
			fixed4 col = tex2D(_MainTex, i.uv);
			float2 flashUV = i.uv;
			flashUV.y += _Time.y % _RunDelay *_FlashSpeed;
			if (flashUV.y >= _Limit && flashUV.y <= _Limit2)
			{
				fixed cosV = cos(_Radian);
				fixed sinV = sin(_Radian);
				fixed2x2 rotMatrix = fixed2x2(cosV, -sinV, sinV, cosV);
				flashUV = mul(rotMatrix, flashUV);
				fixed4 flashValue = tex2D(_FlashTex, flashUV);
				fixed3 flashColor = flashValue.rgb * _FlashIntensity * _FlashColor;
				col.rgb = flashValue.a*flashColor + col.rgb;
			}
			return col;
		}
		ENDCG
		}
	}
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值