Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by DorianF · Nov 07, 2016 at 03:54 PM · shadersocclusion culling

Non static occludee hidden by occluder

Hi,

On a VR project, I had some GUI I wanted to be drawn over everything, no matter what, but since I had to use World Space canvas, the best I came up with was to add a material to all my drawn GUI element using a shader to have it drawn over everything (I don't fully understand the shader, I found it on the internet while looking for means to draw world space GUI over everything).

I've had no problems with this technique, actually, until now, it has worked wonders. But then I tried mixing that with occlusion areas and, somehow, my GUI gets hidden behind occluders.

Of course, neither my GUI nor any of it's parents, nor children are marked as occludee static, so I don't understand why it disappears. I did check that it was an occlusion problem by checking that the item was still in the scene, but when going into the "visualisation" tab of the occlusion window, it is hidden.

Any hint on what I might be doing wrong? Here is the code of the shader :

 Shader "UI/MenuOverEverything"
  {
      Properties
      {
          [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
          _Color ("Tint", Color) = (1,1,1,1)
           
          _StencilComp ("Stencil Comparison", Float) = 8
          _Stencil ("Stencil ID", Float) = 0
          _StencilOp ("Stencil Operation", Float) = 0
          _StencilWriteMask ("Stencil Write Mask", Float) = 255
          _StencilReadMask ("Stencil Read Mask", Float) = 255
   
          _ColorMask ("Color Mask", Float) = 15
      }
   
      SubShader
      {
          Tags
          { 
              "Queue"="Overlay+1" 
              "IgnoreProjector"="True" 
              "RenderType"="Transparent" 
              "PreviewType"="Plane"
              "CanUseSpriteAtlas"="True"
          }
           
          Stencil
          {
              Ref [_Stencil]
              Comp [_StencilComp]
              Pass [_StencilOp] 
              ReadMask [_StencilReadMask]
              WriteMask [_StencilWriteMask]
          }
   
          Cull Off
          Lighting Off
          ZWrite Off
          ZTest Off
          Blend SrcAlpha OneMinusSrcAlpha
          ColorMask [_ColorMask]
   
          Pass
          {
          CGPROGRAM
              #pragma vertex vert
              #pragma fragment frag
              #include "UnityCG.cginc"
               
              struct appdata_t
              {
                  float4 vertex   : POSITION;
                  float4 color    : COLOR;
                  float2 texcoord : TEXCOORD0;
              };
   
              struct v2f
              {
                  float4 vertex   : SV_POSITION;
                  fixed4 color    : COLOR;
                  half2 texcoord  : TEXCOORD0;
              };
               
              fixed4 _Color;
              fixed4 _TextureSampleAdd; //Added for font color support
   
              v2f vert(appdata_t IN)
              {
                  v2f OUT;
                  OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
                  OUT.texcoord = IN.texcoord;
  #ifdef UNITY_HALF_TEXEL_OFFSET
                  OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
  #endif
                  OUT.color = IN.color * _Color;
                  return OUT;
              }
   
              sampler2D _MainTex;
   
              fixed4 frag(v2f IN) : SV_Target
              {
              half4 color = (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;  //Added for font color support
              clip (color.a - 0.01);
              return color;
              }
          ENDCG
          }
      }
  }
 

Note : I'm currently using Unity 5.4.2f2

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DorianF · Nov 15, 2016 at 03:49 PM 0
Share

Can someone at least confirm that occluders are supposed to hide occludees only?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by hexagonius · Jan 28, 2017 at 01:44 PM

If your UI always stays infront of everything, create a second camera, set it's depth higher than the game cam and let it render the UI only. This way it has nothing ever than can occlude it.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DorianF · Jan 30, 2017 at 07:54 AM 0
Share

I'll try that, and let you know how did it go, thanks

avatar image DorianF · Jan 30, 2017 at 09:27 AM 1
Share

EDIT : never$$anonymous$$d what was written here before (if you read it)

This works great ! Just a heads up for other people that might come around here, this is how you should configure the second camera :

  • DO NOT make it a child of the first camera (it would apply twice your VR headset rotation to the second camera)

  • Set "Clear Flags" to "Depth Only"

  • Set the culling mask to your UI layer

  • Reduce the clipping planes as much as possible for optimization

  • Set the "Depth" to a value higher than the Depth of the first camera

  • Uncheck "occlusion culling" (although you are not culling other layers with this camera, you wouldn't see your UI through occluding elements)

The other parameters should be the same than the parameters of your first camera.
Also, don't forget to remove the scripts attached to this camera other than the Camera script itself unless you are sure it makes sense for this script to be on your two cameras.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

80 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple UV on mesh 1 Answer

How to achieve smooth (non Rippling) skybox gradient with shaders? 0 Answers

Unity shaders/materials outside unity enviroment,Unity object export with shaders from shadergraph 0 Answers

Trouble with having object appear when an something is hovering over it and disapear if something Isn't 0 Answers

Issue with BuiltinDebugViewsComponent 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges