{"id":3882,"date":"2016-09-16T19:20:13","date_gmt":"2016-09-16T19:20:13","guid":{"rendered":"http:\/\/www.drmop.com\/?p=3882"},"modified":"2016-09-16T19:20:13","modified_gmt":"2016-09-16T19:20:13","slug":"wavy-text-unity-shader","status":"publish","type":"post","link":"http:\/\/www.drmop.com\/index.php\/2016\/09\/16\/wavy-text-unity-shader\/","title":{"rendered":"Wavy Text Unity Shader"},"content":{"rendered":"<p>Just added a new wavy transparent shader to the <a title=\"Free Unity shaders collection\" href=\"https:\/\/github.com\/mrmop\/UnityShaders\" rel=\"nofollow\">free shaders collection<\/a>. This shade can be used to apply x and y axis waves to textures which looks nice on bitmapped based text, e.g.:<\/p>\n<figure id=\"attachment_3883\" aria-describedby=\"caption-attachment-3883\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/www.drmop.com\/wp-content\/uploads\/2016\/09\/WaveyText.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.drmop.com\/wp-content\/uploads\/2016\/09\/WaveyText-300x192.png\" alt=\"Wavy Transparent Unity Shader\" title=\"Wavy Transparent Unity Shader\" width=\"300\" height=\"192\" class=\"size-medium wp-image-3883\" srcset=\"http:\/\/www.drmop.com\/wp-content\/uploads\/2016\/09\/WaveyText-300x192.png 300w, http:\/\/www.drmop.com\/wp-content\/uploads\/2016\/09\/WaveyText.png 423w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-3883\" class=\"wp-caption-text\">Wavy Transparent Unity Shader<\/figcaption><\/figure>\n<p>The code for the shader is shown below:<\/p>\n<p>[sourcecode language=&#8221;js&#8221;]<br \/>\nShader &quot;Unlit\/WaveTransTexture&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_WaveSpeedX (&quot;X Axis WaveSpeed&quot;, Range(0, 100)) = 20<br \/>\n\t\t_FrequencyX (&quot;X Axis Frequency&quot;, Range(0, 100)) = 10<br \/>\n\t\t_AmplitudeX (&quot;X Axis Amplitude&quot;, Range(0, 100)) = 0.02<br \/>\n\t\t_WaveSpeedY (&quot;Y Axis WaveSpeed&quot;, Range(0, 100)) = 20<br \/>\n\t\t_FrequencyY (&quot;Y Axis Frequency&quot;, Range(0, 100)) = 10<br \/>\n\t\t_AmplitudeY (&quot;Y Axis Amplitude&quot;, Range(0, 100)) = 0.02<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 _FrequencyX;<br \/>\n\t\t\tfixed _AmplitudeX;<br \/>\n\t\t\tfixed _WaveSpeedX;<br \/>\n\t\t\tfixed _FrequencyY;<br \/>\n\t\t\tfixed _AmplitudeY;<br \/>\n\t\t\tfixed _WaveSpeedY;<\/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\tuvs.x += sin(uvs.y * _FrequencyX + _Time * _WaveSpeedX) * _AmplitudeX;<br \/>\n\t\t\t\tuvs.x = (uvs.x * 0.9) + 0.05;<br \/>\n\t\t\t\tuvs.y += cos(uvs.x * _FrequencyY + _Time * _WaveSpeedY) * _AmplitudeY;<br \/>\n\t\t\t\tuvs.y = (uvs.y * 0.9) + 0.05;<br \/>\n\t\t\t\tfixed4 col = tex2D(_MainTex, uvs);<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 code works by applying a sine wave to the y-axis source texture coordinate and pumping that into the x-axis texture coordinate, a similar thing is done with the x-axis source texture coordinate, except that a cosine wave is applied to it. Note that when using this shader you should leave a little space around the bitmap text (around 10% of the image size) to prevent borders from showing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just added a new wavy transparent shader to the free shaders collection. This shade can be used to apply x and y axis waves to textures which looks nice on bitmapped based text, e.g.: The code for the shader is shown below: [sourcecode language=&#8221;js&#8221;] Shader &quot;Unlit\/WaveTransTexture&quot; { Properties { _MainTex(&quot;Color (RGB) Alpha (A)&quot;, 2D) = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[630,625],"tags":[639],"class_list":["post-3882","post","type-post","status-publish","format-standard","hentry","category-shaders","category-unity3d","tag-wavy-text-effect"],"_links":{"self":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/posts\/3882","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=3882"}],"version-history":[{"count":3,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/posts\/3882\/revisions"}],"predecessor-version":[{"id":3886,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/posts\/3882\/revisions\/3886"}],"wp:attachment":[{"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/media?parent=3882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/categories?post=3882"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.drmop.com\/index.php\/wp-json\/wp\/v2\/tags?post=3882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}