Search Unity

Vive Controller render over UI Overlay Shader?

Discussion in 'Shaders' started by Deleted User, Jun 14, 2017.

  1. Deleted User

    Deleted User

    Guest

    Hallo everyone,

    I am using the GUIOverlay shader (code below) from the VR Samples packages which let's you draw World-Space UIs on top of all scene objects.

    What I need is to have my Vive Controller models render ON TOP of all these overlay UIs. I know I could probably duplicate the stereo rig and work with Culling masks so that one camera renders everything but the controllers and another camera set to "Depth only" renders only the controllers with a higher Depth value. But I am not sure if it is a good idea to work with duplicate VR stereo rigs in terms of performance. Maybe these has other implications as well?

    Alternatively, is there a way to have my controllers "cut holes" into the UIs so that they work as masks for the UIs? Does this go into the field of stencil shaders? Any idea how I could accomplish this effect?

    Thank you very much for any help!

    Sean


    Code (CSharp):
    1. Shader "UI/Overlay"
    2. {
    3.     Properties
    4.     {
    5.         [PerRendererData] _MainTex ("Font Texture", 2D) = "white" {}
    6.  
    7.         _Color("Tint", Color) = (1,1,1,1)
    8.  
    9.         _StencilComp ("Stencil Comparison", Float) = 8
    10.         _Stencil ("Stencil ID", Float) = 0
    11.         _StencilOp ("Stencil Operation", Float) = 0
    12.         _StencilWriteMask ("Stencil Write Mask", Float) = 255
    13.         _StencilReadMask ("Stencil Read Mask", Float) = 255
    14.  
    15.         _ColorMask ("Color Mask", Float) = 15
    16.     }
    17.    
    18.     SubShader
    19.     {
    20.         LOD 100
    21.  
    22.         Tags
    23.         {
    24.             "Queue" = "Transparent"
    25.             "IgnoreProjector" = "True"
    26.             "RenderType" = "Transparent"
    27.             "PreviewType"="Plane"
    28.             "CanUseSpriteAtlas" = "True"
    29.         }
    30.  
    31.         Stencil
    32.         {
    33.             Ref [_Stencil]
    34.             Comp [_StencilComp]
    35.             Pass [_StencilOp]
    36.             ReadMask [_StencilReadMask]
    37.             WriteMask [_StencilWriteMask]
    38.         }
    39.        
    40.         Cull Off
    41.         Lighting Off
    42.         ZWrite Off
    43.         ZTest Always
    44.         Offset -1, -1
    45.         Blend SrcAlpha OneMinusSrcAlpha
    46.         ColorMask [_ColorMask]
    47.  
    48.         Pass
    49.         {
    50.             CGPROGRAM
    51.                 #pragma vertex vert
    52.                 #pragma fragment frag
    53.                 #include "UnityCG.cginc"
    54.                 #include "UnityUI.cginc"
    55.  
    56.                 struct appdata_t
    57.                 {
    58.                     float4 vertex : POSITION;
    59.                     float2 texcoord : TEXCOORD0;
    60.                     float4 color : COLOR;
    61.                 };
    62.    
    63.                 struct v2f
    64.                 {
    65.                     float4 vertex : SV_POSITION;
    66.                     half2 texcoord : TEXCOORD0;
    67.                     fixed4 color : COLOR;
    68.                 };
    69.    
    70.                 sampler2D _MainTex;
    71.                 float4 _MainTex_ST;
    72.                 fixed4 _Color;
    73.                 fixed4 _TextureSampleAdd;
    74.                
    75.                 v2f vert (appdata_t v)
    76.                 {
    77.                     v2f o;
    78.                     o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    79.                     o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
    80.                     o.color = v.color * _Color;
    81. #ifdef UNITY_HALF_TEXEL_OFFSET
    82.                     o.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
    83. #endif
    84.  
    85.                     return o;
    86.                 }
    87.                
    88.                 fixed4 frag (v2f i) : SV_Target
    89.                 {
    90.                     fixed4 col = (tex2D(_MainTex, i.texcoord) + _TextureSampleAdd) * i.color;
    91.                     clip (col.a - 0.01);
    92.                     return col;
    93.                 }
    94.             ENDCG
    95.         }
    96.     }
    97. }
    98.  
     
    tabulatouch likes this.
  2. tabulatouch

    tabulatouch

    Joined:
    Mar 12, 2015
    Posts:
    23
    Hi Sean.
    Ever found a simple solution to this?