Search Unity

Object Using Shader That Should Always Show Up Dissapears When Behind Some Objects

Discussion in 'Shaders' started by wirelessdreamer, Apr 14, 2019.

  1. wirelessdreamer

    wirelessdreamer

    Joined:
    Apr 13, 2016
    Posts:
    134
    To Repro; when an object with this shader on is below the terrain, or behind some objects, it will sometimes dissapear. it almost feels like it shows up for 2 seconds while moving ,then dissapears, and does so with some regularity. What can i add to this shader to make sure it will always show up?

    Thanks.

    Render queue is set to 4001

    Code (CSharp):
    1. Shader "Custom/AlwaysShowUp"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.         _Color("Always visible color", Color) = (0,0,0,0)
    7.     }
    8.     SubShader
    9.     {
    10.         Tags { "Queue"="Overlay+2" }
    11.         LOD 100
    12.  
    13.         Pass{
    14.             Cull Off
    15.             ZWrite Off
    16.             Lighting Off
    17.             ZTest Always
    18.  
    19.             CGPROGRAM
    20.             #pragma vertex vert
    21.             #pragma fragment frag
    22.  
    23.             #include "UnityCG.cginc"
    24.            
    25.             struct appdata
    26.             {
    27.                 float4 vertex : POSITION;
    28.                 float2 uv : TEXCOORD0;
    29.             };
    30.  
    31.             struct v2f
    32.             {
    33.                 float2 uv : TEXCOORD0;
    34.                 float4 vertex : SV_POSITION;
    35.             };
    36.  
    37.             float4 _Color;
    38.  
    39.             v2f vert(appdata v)
    40.             {
    41.                 v2f o;
    42.                 o.vertex = UnityObjectToClipPos(v.vertex);
    43.                 return o;
    44.             }
    45.  
    46.             fixed4 frag(v2f i) : SV_Target
    47.             {
    48.                 return _Color;
    49.             }
    50.  
    51.             ENDCG
    52.         }
    53.     }
    54. }
    55.  
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    Sounds like occlusion culling is causing the object to simply not get rendered. Nothing you can really do from the shader side of things. The easiest solution would be to increase the bounds of the mesh to something ridiculous, or disable dynamic occlusion if it’s a mesh renderer.
     
  3. wirelessdreamer

    wirelessdreamer

    Joined:
    Apr 13, 2016
    Posts:
    134
    Thank you, i never had thought to disable dynamic occlusion, turning that off resolved my issue.