Reference Link: http://blog.csdn.net/stalendp/article/details/21993227
:
1. First, implement the grid background map
Shader "Custom/curve" {properties{_backgroundcolor ("BackgroundColor", Color) = (1, 1, 1, 1) _backgroundcolor2 (" BackgroundColor2 ", Color) = (0, 0, 0, 1) _space (" Space ", range (0, 1)) = 0.2_xoffset (" Xoffset ", Range ( -1, 1)) = 0.15_yoffs ET ("Yoffset", Range ( -1, 1)) = 0.05}subshader{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;};/ /lattice background fixed4 _backgroundcolor;fixed4 _backgroundcolor2;fixed _space;fixed _xoffset;fixed _yoffset;v2f vert (AppData v) { v2f O;o.vertex = Mul (UNITY_MATRIX_MVP, V.vertex); o.uv = V.uv;return o;} Fixed4 Frag (v2f i): Sv_target{//fmod (x, y): The remainder of x/y, and X. Have the same symbol//step (A, X): If x<a, return 0; if x>=a, return 1//to get a remainder less than _space, That is, the range of A is [0, _space] Fixed a = fmod (i.uv.x + _xoffset, _space);//1/2 probability returns 0, 1/2 probability returns 1, resulting in an interval effect a = Step (0.5 * _space, a); fixed b = Fmod (I.uv.y + _yoffset, _space); b = Step (0.5 * _space, b); return _backgroundcolor *A * b + _backgroundcolor2 * (1-a * b);} ENDCG}}}
2. Add a line in the middle
Shader "Custom/curve" {properties{_backgroundcolor ("BackgroundColor", Color) = (1, 1, 1, 1) _backgroundcolor2 (" BackgroundColor2 ", Color) = (0, 0, 0, 1) _space (" Space ", range (0, 1)) = 0.2_xoffset (" Xoffset ", Range ( -1, 1)) = 0.15_yoffs ET ("Yoffset", Range ( -1, 1)) = 0.05}subshader{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;};/ /lattice background fixed4 _backgroundcolor;fixed4 _backgroundcolor2;fixed _space;fixed _xoffset;fixed _yoffset;v2f vert (AppData v) { v2f O;o.vertex = Mul (UNITY_MATRIX_MVP, V.vertex); o.uv = V.uv;return o;} Fixed4 Frag (v2f i): Sv_target{//fmod (x, y): The remainder of x/y, and X. Have the same symbol//step (A, X): If x<a, return 0; if x>=a, return 1//to get a remainder less than _space, That is, the range of A is [0, _space] Fixed a = fmod (i.uv.x + _xoffset, _space);//1/2 probability returns 0, 1/2 probability returns 1, resulting in an interval effect a = Step (0.5 * _space, a); fixed b = Fmod (I.uv.y + _yoffset, _space); b = Step (0.5 * _space, b); Fixed4 Bgcol = _backgroundColor * A * b + _backgroundcolor2 * (1-a * b),//Range (1, 51), multiply 100 is widening the gap (the brightest other sides in the middle of the most light), plus 1 is to prevent 0 as a divisor, while ensuring the most intermediate brightest float V = ABS (i. uv.y-0.5) * + 1;v = 1/v;fixed4 Linecol = fixed4 (V, V, V, 1); return bgcol + Linecol;} ENDCG}}}
3. Linear variable Curve
Shader "Custom/curve" {properties{//adjust background _backgroundcolor ("BackgroundColor", Color) = (1, 1, 1, 1) _backgroundcolor2 (" BackgroundColor2 ", Color) = (0, 0, 0, 1) _space (" Space ", range (0, 1)) = 0.2_xoffset (" Xoffset ", Range ( -1, 1)) = 0.15_yoffs ET ("Yoffset", Range (-1, 1)) = 0.05//Adjusts the fluctuation of the Curve _frequency ("Frequency", range (0, 100)) = 10//frequency _amplitude ("amplitude", range (0, 1)) = 0.1//amplitude _speed ("Speed", Range (0, 100)) = 10//Velocity}subshader{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;};/ /lattice background fixed4 _backgroundcolor;fixed4 _backgroundcolor2;fixed _space;fixed _xoffset;fixed _yoffset;half _Frequency; Half _amplitude;half _speed;v2f Vert (AppData v) {v2f O;o.vertex = Mul (UNITY_MATRIX_MVP, V.vertex); o.uv = V.uv;return o;} Fixed4 Frag (v2f i): Sv_target{//fmod (x, y): The remainder of x/y, and X. Have the same symbol//step (A, X): If x<a, return 0; if x>=a, return 1//to get a remainder less than _space, That is, the range of A is [0, _space) Fixed a = Fmod (i.uv.x + _xoffset, _space);//There is a 1/2 probability of returning 0, with 1/2 probability of returning 1, thus forming the interval effect a = Step (0.5 * _space, a); fixed B = Fmod (i.uv.y + _yoffset, _space); b = Step (0.5 * _space, b); Fixed4 Bgcol = _backgroundcolor * A * b + _backgroundcolor2 * (1-a * b);// Range (1, 51), multiply by 100 is widening the gap (the middle brightest other sides basically not bright), plus 1 is to prevent 0 as a divisor, while ensuring the most intermediate brightest//float y = i.uv.y + sin (_time.y); scan line effect float y = i.uv.y + sin (i.u v.x * _frequency + _time.y * _speed) * _amplitude;//can be regarded as a y of the equation about x Float v = ABS (y-0.5) * + 1;v = 1/v;fixed4 Linec OL = Fixed4 (V, V, V, 1); return bgcol + Linecol;} ENDCG}}}
Comment out the scan line effect:
4. Multi-curve. In fact, it is a for loop, and then add some variables to the frequency and amplitude, you can form a number of different curves.
Shader "Custom/curve" {properties{//adjust background _backgroundcolor ("BackgroundColor", Color) = (1, 1, 1, 1) _backgroundcolor2 (" BackgroundColor2 ", Color) = (0, 0, 0, 1) _space (" Space ", range (0, 1)) = 0.2_xoffset (" Xoffset ", Range ( -1, 1)) = 0.15_yoffs ET ("Yoffset", Range (-1, 1)) = 0.05//Adjusts the fluctuation of the Curve _frequency ("Frequency", range (0, 100)) = 10//frequency _amplitude ("amplitude", range (0, 1)) = 0.1//amplitude _speed ("Speed", Range (0, 100)) = 10//Velocity}subshader{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;};/ /lattice background fixed4 _backgroundcolor;fixed4 _backgroundcolor2;fixed _space;fixed _xoffset;fixed _yoffset;half _Frequency; Half _amplitude;half _speed;v2f Vert (AppData v) {v2f O;o.vertex = Mul (UNITY_MATRIX_MVP, V.vertex); o.uv = V.uv;return o;} Fixed4 Frag (v2f i): Sv_target{//fmod (x, y): The remainder of x/y, and X. Have the same symbol//step (A, X): If x<a, return 0; if x>=a, return 1//to get a remainder less than _space, That is, the range of A is [0, _space) Fixed a = Fmod (i.uv.x + _xoffset, _space);//There is a 1/2 probability of returning 0, with 1/2 probability of returning 1, thus forming the interval effect a = Step (0.5 * _space, a); fixed B = Fmod (i.uv.y + _yoffset, _space); b = Step (0.5 * _space, b); Fixed4 Bgcol = _backgroundcolor * A * b + _backgroundcolor2 * (1-a * b);// Range (1, 51), multiply by 100 is widening the gap (the middle brightest other sides basically not bright), plus 1 is to prevent 0 as a divisor, while ensuring the most intermediate brightest//float y = i.uv.y + sin (_time.y); scan line effect fixed4 linecol;for (int Count = 0;count < 3;count++) {float y = i.uv.y + sin (i.uv.x * _frequency * count * 0.1 + _time.y * _speed) * (_amplitude + count * 0.1);//Can be regarded as a y of the equation about X y = saturate (y);//Remap to (0, 1) range float V = ABS (y-0.5) * + 1;v = 1/v;linecol + = Fixe D4 (V, V, V, 1);//Note is "+" operation, color overlay}return bgcol + linecol;} ENDCG}}}
[UnityShader3] Wave effect