{"id":576,"date":"2012-02-09T20:18:00","date_gmt":"2012-02-09T17:18:00","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=576"},"modified":"2012-02-09T20:18:00","modified_gmt":"2012-02-09T17:18:00","slug":"distance-blur-shader-for-texture","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2012\/02\/09\/distance-blur-shader-for-texture\/","title":{"rendered":"Distance Blur Shader for Texture"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"577\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/02\/09\/distance-blur-shader-for-texture\/distance_blur_shader\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/02\/distance_blur_shader.jpg?fit=680%2C418&amp;ssl=1\" data-orig-size=\"680,418\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"distance_blur_shader\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/02\/distance_blur_shader.jpg?fit=680%2C418&amp;ssl=1\" class=\"alignnone size-full wp-image-577\" title=\"distance_blur_shader\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/02\/distance_blur_shader.jpg?resize=680%2C418\" alt=\"\" width=\"680\" height=\"418\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/02\/distance_blur_shader.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/02\/distance_blur_shader.jpg?resize=300%2C184&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>Testing texture blurring in shader..using camera depth to determinate distance.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ DistanceBlurShader for Texture - not very useful.. - Unity version : mgear - http:\/\/unitycoder.com\/blog\r\n\/\/ Original shader: Field shaders by Google\r\n\/*\r\n* Copyright 2009, Google Inc. All rights reserved.\r\n* Redistribution and use in source and binary forms, with or without\r\n* modification, are permitted provided that the following conditions are met:\r\n*\u00a0\u00a0\u00a0\u00a0 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\r\n*\u00a0\u00a0\u00a0\u00a0 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and\/or other materials provided with the distribution.\r\n*\u00a0\u00a0\u00a0\u00a0 * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.\r\n* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r\n* &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r\n* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r\n* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r\n* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r\n* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r\n* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r\n* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r\n* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r\n* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r\n* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r\n*\/\r\nShader &quot;mShaders\/DistanceBlur1&quot; {\r\nProperties {\r\nblurSizeX(&quot;BlurSizeX&quot;, Float) = 0\r\nblurSizeY(&quot;BlurSizeY&quot;, Float) = 0\r\n_MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; { }\r\n\r\n}\r\nSubShader {\r\nPass {\r\nCGPROGRAM\r\n#pragma vertex vert\r\n#pragma fragment frag\r\n#include &quot;UnityCG.cginc&quot;\r\nfloat blurSizeX;\r\nfloat blurSizeY;\r\nsampler2D _MainTex;\r\nstruct v2f {\r\nfloat4\u00a0 pos : SV_POSITION;\r\nfloat2\u00a0 uv : TEXCOORD0;\r\nfloat2 depth : TEXCOORD1;\r\n};\r\nfloat4 _MainTex_ST;\r\nv2f vert (appdata_base v)\r\n{\r\nv2f o;\r\no.pos = mul (UNITY_MATRIX_MVP, v.vertex);\r\nUNITY_TRANSFER_DEPTH(o.depth);\r\no.uv = TRANSFORM_TEX (v.texcoord, _MainTex);\r\nreturn o;\r\n}\r\nhalf4 frag (v2f i) : COLOR\r\n{\r\nhalf4 sum = half4(0.0);\r\nfloat depth = 1-i.depth.r*0.0005;\r\n\/\/ gather pixel color from neighbours, distance to look for depends on camera distance..\r\nsum += tex2D(_MainTex, float2(i.uv.x - 5.0 * depth, i.uv.y - 5.0 * depth)) * 0.025;\r\nsum += tex2D(_MainTex, float2(i.uv.x - 4.0 * depth, i.uv.y - 4.0 * depth)) * 0.05;\r\nsum += tex2D(_MainTex, float2(i.uv.x - 3.0 * depth, i.uv.y - 3.0 * depth)) * 0.09;\r\nsum += tex2D(_MainTex, float2(i.uv.x - 2.0 * depth, i.uv.y - 2.0 * depth)) * 0.12;\r\nsum += tex2D(_MainTex, float2(i.uv.x - 1.0 * depth, i.uv.y - 1.0 * depth)) * 0.15;\r\nsum += tex2D(_MainTex, float2(i.uv.x, i.uv.y)) * 0.16;\r\nsum += tex2D(_MainTex, float2(i.uv.x + 1.0 * depth, i.uv.y + 1.0 * depth)) * 0.15;\r\nsum += tex2D(_MainTex, float2(i.uv.x + 2.0 * depth, i.uv.y + 2.0 * depth)) * 0.12;\r\nsum += tex2D(_MainTex, float2(i.uv.x + 3.0 * depth, i.uv.y + 3.0 * depth)) * 0.09;\r\nsum += tex2D(_MainTex, float2(i.uv.x + 4.0 * depth, i.uv.y + 4.0 * depth)) * 0.05;\r\nsum += tex2D(_MainTex, float2(i.uv.x + 5.0 * depth, i.uv.y + 5.0 * depth)) * 0.025;\r\nreturn sum;\r\n}\r\nENDCG\r\n}\r\n}\r\nFallback &quot;VertexLit&quot;\r\n} <\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Testing texture blurring in shader..using camera depth to determinate distance. \/\/ DistanceBlurShader for Texture &#8211; not very useful.. &#8211; Unity version : mgear &#8211; http:\/\/unitycoder.com\/blog \/\/ Original shader: Field shaders by Google \/* * Copyright 2009, Google Inc. All rights reserved. * Redistribution and use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":577,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[13,3],"tags":[160,159,14,142],"class_list":["post-576","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-shaders","category-unity3d","tag-blur","tag-distance","tag-shader","tag-texture"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/02\/distance_blur_shader.jpg?fit=680%2C418&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-9i","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/576","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=576"}],"version-history":[{"count":1,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/576\/revisions"}],"predecessor-version":[{"id":578,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/576\/revisions\/578"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/577"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=576"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=576"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=576"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}