Shader "Custom/DistortSelf" { Properties { [Header(Flag)] _MainTex("Texture", 2D) = "white" {} _Noise ("Noise", 2D) = "white" {} _distortFactorTime("FactorTime",Range(0,5)) = 0.5 _distortFactor("factor",Range(0.04,1)) = 0 [Space(20)] [Header(MainBackGround)] _2edTex ("Main Tex", 2D) = "white" {} //_Specular ("Specular", Color) = (1, 1, 1, 1) //_Gloss ("Gloss", Range(8.0, 256)) = 20 [Space(20)] [Header(Cloud)] _3rdTex ("3edTexture", 2D) = "white" {} _Speed("Rotate Speed",Float)=1 [Space(20)] [Header(Grass)] _4thTex ("Texture", 2D) = "white" {} _Noise2("Noise", 2D) = "black" {} _WindControl("WindControl(x:XSpeed y:YSpeed z:ZSpeed w:windMagnitude)",vector) = (1,0,1,0.5) //前面几个分量表示在各个轴向上自身摆动的速度, w表示摆动的强度 _WaveControl("WaveControl(x:XSpeed y:YSpeed z:ZSpeed w:worldSize)",vector) = (1,0,1,1) //前面几个分量表示在各个轴向上风浪的速度, w用来模拟地图的大小,值越小草摆动的越凌乱,越大摆动的越整体 [HDR]_Color("Color",Color) = (1,1,1,1) _XSpeed("XSpeed",Range(-1,1)) = 0 _YSpeed("YSpeed",Range(-1,1)) = 0 _AlphaScale("Alpha",Range(0,1)) =1 [Space(10)] [Header(Water)] _WaterCol ("Color", Color) = (1,1,1,1) _WaterCol_ROOT ("Color ROOT", Color) = (1,1,1,1) _WaterCol_image5 ("Color image5", Color) = (1,1,1,1) _WaterCol_image5copy ("Color image5copy", Color) = (1,1,1,1) _WaterCol_image8 ("Color image8", Color) = (1,1,1,1) _WaterCol_image8copy ("Color image8copy", Color) = (1,1,1,1) _WaterCol_image15 ("Color image15", Color) = (1,1,1,1) _5thTex ("_5thTex", 2D) = "white" { } _wave ("_wave", 2D) = "white" { } _view_mask0 ("_view_mask0", 2D) = "white" { } _smoke ("_smoke", 2D) = "white" { } _viewWaterfall ("_viewWaterfall", 2D) = "white" { } _view2 ("_view2", 2D) = "white" { } _view_mask1 ("_view_mask1", 2D) = "white" { } _Speed2("Speed2",Float) = 1 _Alpha("Alpha",Range(0,1))=1 [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 } SubShader { Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" "CanUseSpriteAtlas"="True"} LOD 100 Blend SrcAlpha OneMinusSrcAlpha Cull Off Lighting Off ZWrite Off Pass { ZWrite Off CGPROGRAM #pragma vertex vert #pragma fragment frag #include "Lighting.cginc" fixed4 _Color; sampler2D _2edTex; float4 _2edTex_ST; fixed4 _Specular; float _Gloss; struct a2v { float4 vertex : POSITION; float3 normal : NORMAL; float4 texcoord : TEXCOORD0; }; struct v2f { float4 pos : SV_POSITION; float3 worldNormal : TEXCOORD0; float3 worldPos : TEXCOORD1; float2 uv : TEXCOORD2; }; v2f vert(a2v v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.worldNormal = UnityObjectToWorldNormal(v.normal); o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; o.uv = v.texcoord.xy * _2edTex_ST.xy + _2edTex_ST.zw; // Or just call the built-in function // o.uv = TRANSFORM_TEX(v.texcoord, _2edTex); return o; } fixed4 frag(v2f i) : SV_Target { //fixed3 worldNormal = normalize(i.worldNormal); //fixed3 worldLightDir = normalize(UnityWorldSpaceLightDir(i.worldPos)); // Use the texture to sample the diffuse color fixed4 albedo = tex2D(_2edTex, i.uv); return albedo; } ENDCG } Pass { Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" sampler2D _3rdTex; float4 _3rdTex_ST; float _Speed; struct a2v{ float4 vertex:POSITION; float4 texcoord:TEXCOORD; }; struct v2f{ float4 pos:POSITION; float4 uv:texcoord; }; v2f vert(a2v v){ v2f o; o.pos=UnityObjectToClipPos(v.vertex); o.uv=v.texcoord; return o; } fixed4 frag(v2f i):SV_Target{ /*//扭曲效果 fixed2 uv = i.uv - fixed2(0.5,0.5); float angle = _Speed * 0.1745/(length(uv) + 0.1);//加0.1是放置length(uv)为0 float angle2 = angle * _Time.y; uv = float2(uv.x*cos(angle2)-uv.y*sin(angle2),uv.y*cos(angle2)+uv.x*sin(angle2)); uv+=fixed2(0.5,0.5); fixed4 c = tex2D(_3rdTex,uv); return c; */ //缩放 //float4 uv = i.uv; //uv.x*=_Speed; //uv.w=0.5; //return tex2D(_3rdTex,uv); //旋转 //float2 uv=i.uv.xy-float2(0.5,0.5); //uv=float2(uv.x*cos(_Speed*_Time.y)-uv.y*sin(_Speed*_Time.y),uv.y*cos(_Speed*_Time.y) + uv.x*sin(_Speed*_Time.y)); //uv+=float2(0.5,0.5); //fixed4 lateUV = tex2D(_3rdTex,uv); //return lateUV; //平移 return tex2D(_3rdTex,i.uv - _Time.x*fixed2(2,0)* _Speed); } ENDCG } Pass { ZWrite off 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; }; sampler2D _MainTex; float4 _MainTex_ST; sampler2D _Noise; fixed _distortFactorTime; fixed _distortFactor; fixed4 _Color; float _XSpeed; float _YSpeed; v2f vert (appdata v) { v2f o; o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); o.uv += float2(_XSpeed, _YSpeed)*_Time.y; return o; } fixed4 frag (v2f i) : SV_Target { // sample the texture fixed4 bias = tex2D(_Noise, i.uv+_Time.xy*_distortFactorTime); half4 color = tex2D(_MainTex, i.uv+bias.xy*_distortFactor); return color*_Color; } ENDCG } } }