Created
March 11, 2020 08:10
-
-
Save stilllisisi/49391049bf401aa2861d2d76c06d5d2a to your computer and use it in GitHub Desktop.
【游戏-unity】Shader实现渐变效果。为了让效果更加的酷炫,在一些场景中可能会用到渐变效果,本篇给大家分享下使用shader实现渐变效果
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader"QQ/Gradient/Bias" | |
{ | |
Properties | |
{ | |
_Color("Color",Color)=(.5,.5,.5,1) | |
_MainTex("Texture",2D)="white"{} | |
_Gradient("Gradient,x:slope,y:speed,zw:gradual",vector)=(-.1,5,.3,.01) | |
} | |
SubShader | |
{ | |
Tags{"RenderType"="Transparent" | |
"Queue"="Transparent" | |
} | |
LOD100 | |
Pass | |
{ | |
ZwriteOff | |
BlendSrcAlphaOneMinusSrcAlpha | |
CGPROGRAM | |
#pragmavertexvert | |
#pragmafragmentfrag | |
#include"UnityCG.cginc" | |
structa2v | |
{ | |
float4vertex:POSITION; | |
float2uv:TEXCOORD0; | |
}; | |
structv2f | |
{ | |
float4pos:SV_POSITION; | |
float2uv:TEXCOORD0; | |
float2local_uv:TEXCOORD1; | |
}; | |
sampler2D_MainTex; | |
float4_MainTex_ST; | |
fixed4_Color; | |
float4_Gradient; | |
float_Speed; | |
v2fvert(a2vv) | |
{ | |
v2fo; | |
o.pos=mul(UNITY_MATRIX_MVP,v.vertex); | |
o.uv=TRANSFORM_TEX(v.uv,_MainTex); | |
o.local_uv=v.uv; | |
returno; | |
} | |
fixed4frag(v2fi):SV_Target | |
{ | |
_Speed+=_Time.x*_Gradient.y; | |
fixed4col=tex2D(_MainTex,i.uv); | |
_Speed+=_Gradient.x*i.local_uv.y; | |
floatgradient=i.local_uv.x-(_Speed%1.5); | |
gradient=gradient>0? | |
max(_Gradient.w-gradient,0)/_Gradient.w: | |
max(_Gradient.z+gradient,0)/_Gradient.z; | |
col.rgb=lerp(col.rgb,_Color.rgb,gradient); | |
returncol; | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gameinstitute.qq.com/community/detail/128719