当前位置:   article > 正文

unity ui 扫光shader_ui扫光shader

ui扫光shader

在这里插入图片描述
_LightTex 1:扫光贴图
_Color 2:扫光颜色
_Intensity 3:强度
_Speed 4:运动速度
_Angle 5:扫光贴图uv中心点旋转

Shader "Unlit/UIWalklight"
{
	Properties
	{
		_MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {}
		_LightTex ("Light", 2D) = "black" {}
		_Color ("Color", Color) = (255,255,255,1)
		_Intensity("Intensity", Float) = 1
		_Speed("Speed", Float) = 1
		_Angle("Angle", Float) = 0
		
	}
	
	SubShader
	{
		LOD 100
		Tags
		{
			"Queue" = "Transparent"
			"IgnoreProjector" = "True"
			"RenderType" = "Transparent"
		}
		Pass
		{
			Cull Off
			Lighting Off
			ZWrite Off
			Fog { Mode Off }
			Offset -1, -1
			Blend SrcAlpha OneMinusSrcAlpha

			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag

			#include "UnityCG.cginc"

			sampler2D _MainTex;
			float4 _MainTex_ST;
			sampler2D _LightTex;
			float4 _LightTex_ST;
			float4 _Color;
			float _Speed,_Angle,_Intensity;
			struct appdata_t
			{
				float4 vertex : POSITION;
				float2 texcoord : TEXCOORD0;
				//float2 texcoord1 : TEXCOORD1;
				fixed4 color : COLOR;
			};
	
			struct v2f
			{
				float4 vertex : SV_POSITION;
				float2 texcoord : TEXCOORD0;
				//float2 texcoord1 : TEXCOORD1;
				fixed4 color : COLOR;
				//half2 posInPanel : TEXCOORD3;
			};
	
			v2f o;

			v2f vert (appdata_t v)
			{
				o.vertex = UnityObjectToClipPos(v.vertex);
				//float2 clipSpace = o.vertex.xy / o.vertex.w;  
			    //o.posInPanel = (clipSpace.xy + 1) * 0.5 - _PanelRect.xy;// Fix to 0-1//
				o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
				//o.texcoord1 = v.texcoord1;
				o.color = v.color;
				return o;
			}
				
			fixed4 frag (v2f IN) : COLOR
			{
				fixed4 main = tex2D(_MainTex, IN.texcoord);
				float2 newUV = IN.texcoord.xy-float2(0.5,0.5);
			    newUV =  float2(newUV.x*cos(_Angle)-newUV.y*sin(_Angle),newUV.y*cos(_Angle) + newUV.x*sin(_Angle));
				newUV += float2(0.5,0.5);
                half lightU = newUV.x - frac(_Time.y*_Speed);
                half2 lightUV = half2(lightU, newUV.y) * _LightTex_ST.xy + _LightTex_ST.zw;
                fixed4 light = tex2D(_LightTex, lightUV)*_Intensity;
				fixed4 col = main + main * light.r*_Color;
				return  col * IN.color;

				return col;
			}
			ENDCG
		}
	}

	SubShader
	{
		LOD 100

		Tags
		{
			"Queue" = "Transparent"
			"IgnoreProjector" = "True"
			"RenderType" = "Transparent"
		}
		
		Pass
		{
			Cull Off
			Lighting Off
			ZWrite Off
			Fog { Mode Off }
			Offset -1, -1
			ColorMask RGB
			Blend SrcAlpha OneMinusSrcAlpha
			ColorMaterial AmbientAndDiffuse
			
			SetTexture [_MainTex]
			{
				Combine Texture * Primary
			}
		}
	}
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/109450
推荐阅读
相关标签
  

闽ICP备14008679号