{"id":5075,"date":"2019-09-21T15:51:04","date_gmt":"2019-09-21T07:51:04","guid":{"rendered":"https:\/\/unitycoder.com\/blog\/?p=5075"},"modified":"2019-10-01T00:06:02","modified_gmt":"2019-09-30T16:06:02","slug":"modified-standard-shader-to-start-fading-based-on-camera-y-distance","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2019\/09\/21\/modified-standard-shader-to-start-fading-based-on-camera-y-distance\/","title":{"rendered":"Modified Standard shader to start fading based on Camera Y distance"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"680\" height=\"333\" data-attachment-id=\"5076\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2019\/09\/21\/modified-standard-shader-to-start-fading-based-on-camera-y-distance\/unity-standard-shader-fade-height-y\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/09\/unity-standard-shader-fade-height-y.gif?fit=680%2C333&amp;ssl=1\" data-orig-size=\"680,333\" 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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"unity-standard-shader-fade-height-y\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/09\/unity-standard-shader-fade-height-y.gif?fit=300%2C147&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/09\/unity-standard-shader-fade-height-y.gif?fit=680%2C333&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/09\/unity-standard-shader-fade-height-y.gif?resize=680%2C333&#038;ssl=1\" alt=\"\" class=\"wp-image-5076\"\/><\/figure>\n\n\n\n<p>Needed this kind of effect for a small game, where:<br>&#8211; objects below would be faded out<br>&#8211; player can move up and down (fade should &#8220;follow&#8221;)<br>&#8211; realtime lights should be supported<br><br>basically like the old unity <a rel=\"noreferrer noopener\" aria-label=\"global fog (opens in a new tab)\" href=\"https:\/\/docs.unity3d.com\/540\/Documentation\/Manual\/script-GlobalFog.html\" target=\"_blank\">global fog<\/a> for height, but that one doesn&#8217;t work with newer unitys.. and shadergraph might have helped to create this effect, but i&#8217;m not using new render pipelines..<br><br><strong>Source:<\/strong><br><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/UnityCommunity\/UnityLibrary\/blob\/master\/Assets\/Shaders\/3D\/Effects\/VerticalCameraDistanceFade.shader\" target=\"_blank\">https:\/\/github.com\/UnityCommunity\/UnityLibrary\/blob\/master\/Assets\/Shaders\/3D\/Effects\/VerticalCameraDistanceFade.shader<\/a><\/p>\n\n\n\n<p>Without custom lighting in shader, it didn&#8217;t work, even with black ambient color, since there are lights in the scene (image below)<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"415\" height=\"384\" data-attachment-id=\"5077\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2019\/09\/21\/modified-standard-shader-to-start-fading-based-on-camera-y-distance\/image-5-2\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/09\/image-5.png?fit=415%2C384&amp;ssl=1\" data-orig-size=\"415,384\" 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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image-5\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/09\/image-5.png?fit=300%2C278&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/09\/image-5.png?fit=415%2C384&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/09\/image-5.png?resize=415%2C384&#038;ssl=1\" alt=\"\" class=\"wp-image-5077\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/09\/image-5.png?w=415&amp;ssl=1 415w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/09\/image-5.png?resize=300%2C278&amp;ssl=1 300w\" sizes=\"auto, (max-width: 415px) 100vw, 415px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Needed this kind of effect for a small game, where:&#8211; objects below would be faded out&#8211; player can move up and down (fade should &#8220;follow&#8221;)&#8211; realtime lights should be supported basically like the old unity global fog for height, but that one doesn&#8217;t work with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5076,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[13,3],"tags":[159,1126,273,1127,459,14,1125],"class_list":["post-5075","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-shaders","category-unity3d","tag-distance","tag-fade","tag-fog","tag-global","tag-height","tag-shader","tag-standard"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2019\/09\/unity-standard-shader-fade-height-y.gif?fit=680%2C333&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-1jR","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/5075","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=5075"}],"version-history":[{"count":2,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/5075\/revisions"}],"predecessor-version":[{"id":5086,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/5075\/revisions\/5086"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/5076"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=5075"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=5075"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=5075"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}