{"id":4498,"date":"2017-01-14T17:35:14","date_gmt":"2017-01-14T09:35:14","guid":{"rendered":"http:\/\/1darray.com\/blog\/?p=4498"},"modified":"2021-06-29T09:17:21","modified_gmt":"2021-06-29T06:17:21","slug":"shader-draw-world-space-ui-always-on-top","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2017\/01\/14\/shader-draw-world-space-ui-always-on-top\/","title":{"rendered":"[Shader] Draw World Space UI Always On Top"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4499\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2017\/01\/14\/shader-draw-world-space-ui-always-on-top\/worldspace-always-on-top\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2017\/01\/worldspace-always-on-top.jpg?fit=377%2C427&amp;ssl=1\" data-orig-size=\"377,427\" 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=\"worldspace-always-on-top\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2017\/01\/worldspace-always-on-top.jpg?fit=377%2C427&amp;ssl=1\" class=\"alignnone size-full wp-image-4499\" src=\"https:\/\/i0.wp.com\/1darray.com\/blog\/wp-content\/uploads\/2017\/01\/worldspace-always-on-top.jpg?resize=377%2C427\" alt=\"\" width=\"377\" height=\"427\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2017\/01\/worldspace-always-on-top.jpg?w=377&amp;ssl=1 377w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2017\/01\/worldspace-always-on-top.jpg?resize=265%2C300&amp;ssl=1 265w\" sizes=\"auto, (max-width: 377px) 100vw, 377px\" \/><\/p>\n<p>If you want to draw UI in VR (for example Google Cardboard), it doesn&#8217;t support ScreenSpace rendermode in canvas..<br \/>\nSo all the UI&#8217;s are using WorldSpace RenderMode.. which causes issues when UI goes behind geometry.<\/p>\n<p>Fix: You can modify UI shader to disable ZTest<\/p>\n<p><strong>Shader source:<\/strong> (tested with 5.6.0b3)<br \/>\n<a href=\"https:\/\/github.com\/UnityCommunity\/UnityLibrary\/blob\/master\/Assets\/Shaders\/2D\/UI\/UI_Always_On_Top.shader\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/UnityCommunity\/UnityLibrary\/blob\/master\/Assets\/Shaders\/2D\/UI\/UI_Always_On_Top.shader<\/a><\/p>\n<p>*Only one line was modified from original UI shader,<br \/>\n\/\/ From<br \/>\nZTest [unity_GUIZTestMode]<\/p>\n<p>\/\/ To<br \/>\nZTest Off<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you want to draw UI in VR (for example Google Cardboard), it doesn&#8217;t support ScreenSpace rendermode in canvas.. So all the UI&#8217;s are using WorldSpace RenderMode.. which causes issues when UI goes behind geometry. Fix: You can modify UI shader to disable ZTest Shader [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4499,"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":"[Shader] Draw World Space Canvas UI Always On Top","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},"jetpack_post_was_ever_published":false},"categories":[13,3],"tags":[956,961,959,247,957,650,960,955,958],"class_list":["post-4498","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-shaders","category-unity3d","tag-alway","tag-canvas","tag-cardboard","tag-draw","tag-on-top","tag-ui","tag-vr","tag-worldspace","tag-ztest"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2017\/01\/worldspace-always-on-top.jpg?fit=377%2C427&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-1ay","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/4498","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=4498"}],"version-history":[{"count":3,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/4498\/revisions"}],"predecessor-version":[{"id":5389,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/4498\/revisions\/5389"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/4499"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=4498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=4498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=4498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}