Unity Air Wall Shader

Without further ado, here are the renderings first

 The specific code is as follows:

Shader "Hidden/AirWall"
{
	Properties
	{
		_Color("Color",Color) = (1,1,1,1)     //颜色
		_Interval("Interval",float) = 10      //间隔
	}
		SubShader
	{
		Cull Back ZWrite On ZTest Less        //设置背面剔除 开启深度写入 和深度比较模式
		Blend SrcAlpha OneMinusSrcAlpha       //设置混合模式
		Tags{"Queue" = "Transparent"}         //设置渲染队列为‘透明’
		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;
		};

		float _Interval;
		fixed4 _Color;

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

		fixed4 frag(v2f i) : SV_Target
		{
			fixed2 uv = i.uv;
			float y = uv.y;                                             //保留最原始的uv.y分量 
			uv.y = fmod(uv.y * _Interval,1);                            //将uv分成 interval分,然后取小数部分
			uv.y += _Time.y;                                            //加上随时间变化的偏移
			uv.y = fmod(uv.y ,1);                                       //再次取小数部分
			float a = step(uv.y,0.2);                                   //设置不透明色带的宽度为0.2
			a = clamp(a, 0.2, 1);                                       //限制值域0.2-1
			a *= y;                                                     //与原始uv.y分量相乘  产生uv.y(纵轴)方向上的渐变
			a *= sin(uv.x * 3.1415926);                                 //计算uv.x(横轴)方向上的渐变
			return fixed4(_Color.rgb ,a);                               //最后与设置的颜色输出
		}
		ENDCG
	}
	}
}

Guess you like

Origin blog.csdn.net/chooselove/article/details/127156176