Search Unity

Making a character appear through 1 layer of objects but not 2 or more

Discussion in 'Shaders' started by fat-chunk, Mar 29, 2015.

  1. fat-chunk

    fat-chunk

    Joined:
    May 18, 2013
    Posts:
    5
    Hi,

    I am working on a project using Kinect and Zigfu. I have a Kinect feed object (a flat screen between the main camera and the rest of the scene) through which I want my character to appear. This works pretty well, I have written the following shader to achieve this:

    Code (CSharp):
    1. Shader "Custom/FriendShader" {
    2.     Properties {
    3.         _Color ("Main Color", Color) = (1,1,1,1)
    4.         _MainTex ("Base (RGB)", 2D) = "white" {}
    5.     }
    6.     Category {
    7.         SubShader {
    8.        
    9.             //sampler2D _MainTex;
    10.            
    11.             Tags { "Queue"="Overlay+1" }
    12.                                            
    13.              Pass
    14.             {
    15.                 ZTest Greater
    16.                 Lighting Off
    17.                 SetTexture [_MainTex] {combine texture}
    18.             }
    19.                                            
    20.             Pass
    21.             {
    22.                 ZTest Less
    23.                 SetTexture [_MainTex] {combine texture}
    24.             }
    25.            
    26.             CGPROGRAM
    27.             #pragma surface surf Lambert
    28.  
    29.             sampler2D _MainTex;
    30.             fixed4 _Color;
    31.  
    32.             struct Input {
    33.                 float2 uv_MainTex;
    34.             };
    35.  
    36.             void surf (Input IN, inout SurfaceOutput o) {
    37.                 fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
    38.                 o.Albedo = c.rgb;
    39.                 o.Alpha = c.a;
    40.             }
    41.             ENDCG
    42.         }
    43.     }
    44.     FallBack "VertexLit"
    45. }
    46.  
    However, if there is an object between this Kinect screen and the character, I want that part of the character to be occluded. Right now, the character appears through everything regardless of the number of objects standing between it and the camera. Is there a way for the character to only be rendered with 1 or less objects being between it and the camera?

    Also I think the CPROGRAM part of my shader is not doing anything. I included that as I wanted phong/specular shading applied to my model but right now it seems as though I am only getting diffuse. Any help with this would also be greatly appreciated.

    I'll answer any questions and provide more info if that makes it any easier.
     
  2. fat-chunk

    fat-chunk

    Joined:
    May 18, 2013
    Posts:
    5