{"id":3887,"date":"2016-09-16T21:51:18","date_gmt":"2016-09-16T21:51:18","guid":{"rendered":"http:\/\/www.drmop.com\/?p=3887"},"modified":"2016-09-16T21:51:18","modified_gmt":"2016-09-16T21:51:18","slug":"colour-cycle-effect-unity-shader","status":"publish","type":"post","link":"http:\/\/www.drmop.com\/index.php\/2016\/09\/16\/colour-cycle-effect-unity-shader\/","title":{"rendered":"Colour Cycle Effect Unity Shader"},"content":{"rendered":"<p>Just added a new colour cycle effect transparent Unity shader to the <a title=\"Free Unity shaders collection\" href=\"https:\/\/github.com\/mrmop\/UnityShaders\" rel=\"nofollow\">free shaders collection<\/a>. This shader can be used to overlay a y-axis colour cycle effect over a texture<\/p>\n<p>The code for the shader is shown below:<\/p>\n<p>[sourcecode language=&#8221;js&#8221;]<br \/>\nShader &quot;Unlit\/ColourCycleTexture&quot;<br \/>\n{<br \/>\n\tProperties<br \/>\n\t{<br \/>\n\t\t_MainTex(&quot;Color (RGB) Alpha (A)&quot;, 2D) = &quot;white&quot; {}<br \/>\n\t\t_WaveSpeed (&quot;WaveSpeed&quot;, Range(-1000, 1000)) = 20<br \/>\n\t\t_Frequency (&quot;Frequency&quot;, Range(0, 100)) = 10<br \/>\n\t\t_Amplitude (&quot;Amplitude&quot;, Range(0, 3)) = 0.02<br \/>\n\t\t_RedScale(&quot;Red Scale&quot;, Range(0, 3)) = 1<br \/>\n\t\t_GreenScale(&quot;Green Scale&quot;, Range(0, 3)) = 1<br \/>\n\t\t_BlueScale(&quot;Blue Scale&quot;, Range(0, 3)) = 1<br \/>\n\t}<br \/>\n\tSubShader<br \/>\n\t{<br \/>\n\t\tTags{ &quot;Queue&quot; = &quot;Transparent&quot; &quot;RenderType&quot; = &quot;Transparent&quot; }<br \/>\n\t\tBlend SrcAlpha OneMinusSrcAlpha<br \/>\n\t\tLOD 100<\/p>\n<p>\t\tPass<br \/>\n\t\t{<br \/>\n\t\t\tCGPROGRAM<br \/>\n\t\t\t#pragma vertex vert<br \/>\n\t\t\t#pragma fragment frag<\/p>\n<p>\t\t\t#include &quot;UnityCG.cginc&quot;<\/p>\n<p>\t\t\tstruct appdata<br \/>\n\t\t\t{<br \/>\n\t\t\t\tfloat4 vertex : POSITION;<br \/>\n\t\t\t\tfloat2 uv : TEXCOORD0;<br \/>\n\t\t\t};<\/p>\n<p>\t\t\tstruct v2f<br \/>\n\t\t\t{<br \/>\n\t\t\t\tfloat2 uv : TEXCOORD0;<br \/>\n\t\t\t\tfloat4 vertex : SV_POSITION;<br \/>\n\t\t\t};<\/p>\n<p>\t\t\tsampler2D _MainTex;<br \/>\n\t\t\tfloat4 _MainTex_ST;<br \/>\n\t\t\tfixed _Frequency;<br \/>\n\t\t\tfixed _WaveSpeed;<br \/>\n\t\t\tfixed _Amplitude;<br \/>\n\t\t\tfixed _RedScale;<br \/>\n\t\t\tfixed _GreenScale;<br \/>\n\t\t\tfixed _BlueScale;<\/p>\n<p>\t\t\tv2f vert (appdata v)<br \/>\n\t\t\t{<br \/>\n\t\t\t\tv2f o;<br \/>\n\t\t\t\to.vertex = mul(UNITY_MATRIX_MVP, v.vertex);<br \/>\n\t\t\t\to.uv = TRANSFORM_TEX(v.uv, _MainTex);<br \/>\n\t\t\t\treturn o;<br \/>\n\t\t\t}<\/p>\n<p>\t\t\tfixed4 frag (v2f i) : SV_Target<br \/>\n\t\t\t{<br \/>\n\t\t\t\tfixed2 uvs = i.uv;<br \/>\n\t\t\t\tfixed4 col = tex2D(_MainTex, uvs);<br \/>\n\t\t\t\tfixed d = sin(uvs.y * _Frequency + _Time * _WaveSpeed) * _Amplitude;<br \/>\n\t\t\t\tcol.r += d * _RedScale;<br \/>\n\t\t\t\tcol.g += d * _GreenScale;<br \/>\n\t\t\t\tcol.b += d * _BlueScale;<br \/>\n\t\t\t\treturn col;<br \/>\n\t\t\t}<br \/>\n\t\t\tENDCG<br \/>\n\t\t}<br \/>\n\t}<br \/>\n}<br \/>\n[\/sourcecode]<\/p>\n<p>The shader works by adjusting the colour of the texel pulled from the texture applying a wave effect which is then scaled by red, green and blue scaling factors which can be used to change the colour of the overlaid effect. Here are a few parameters to try:<\/p>\n<p>Produce a nice upwards red scroll effect:<br \/>\nWave Speed &#8211; -150<br \/>\nFrequency &#8211; -20<br \/>\nAmplitude &#8211; -1<br \/>\nRed Scale &#8211; 0<br \/>\nGreen Scale &#8211; 0.4<br \/>\nBlue Scale &#8211; 0<\/p>\n<p>Produce a slow flash:<br \/>\nWave Speed &#8211; 150<br \/>\nFrequency &#8211; 1<br \/>\nAmplitude &#8211; 1<br \/>\nRed Scale &#8211; 0<br \/>\nGreen Scale &#8211; 0.4<br \/>\nBlue Scale &#8211; 0<\/p>\n<p>You may need to adjust the red, green and blue scaling factors to match the colour of your texture.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just added a new colour cycle effect transparent Unity shader to the free shaders collection. This shader can be used to overlay a y-axis colour cycle effect over a texture The code for the shader is shown below: [sourcecode language=&#8221;js&#8221;] Shader &quot;Unlit\/ColourCycleTexture&quot; { Properties { _MainTex(&quot;Color (RGB) Alpha (A)&quot;, 2D) = &quot;white&quot; {} _WaveSpeed (&quot;WaveSpeed&quot;, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44,3,630,625],"tags":[640],"class_list":["post-3887","post","type-post","status-publish","format-standard","hentry","category-game-and-app-development","category-programming","category-shaders","category-unity3d","tag-colour-cycle-shader"],"_links":{"self":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/posts\/3887","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/comments?post=3887"}],"version-history":[{"count":2,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/posts\/3887\/revisions"}],"predecessor-version":[{"id":3889,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/posts\/3887\/revisions\/3889"}],"wp:attachment":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/media?parent=3887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/categories?post=3887"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/tags?post=3887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}