| 1 | Shader "Oculus/OVRMRCameraFrame" |
| 2 | { |
| 3 | Properties |
| 4 | { |
| 5 | _Color("Main Color", Color) = (1,1,1,1) |
| 6 | _MainTex("Main Texture", 2D) = "white" {} |
| 7 | _Visible("Visible", Range(0.0,1.0)) = 1.0 |
| 8 | _ChromaAlphaCutoff("ChromaAlphaCutoff", Range(0.0,1.0)) = 0.01 |
| 9 | _ChromaToleranceA("ChromaToleranceA", Range(0.0,50.0)) = 20.0 |
| 10 | _ChromaToleranceB("ChromaToleranceB", Range(0.0,50.0)) = 15.0 |
| 11 | _ChromaShadows("ChromaShadows", Range(0.0,1.0)) = 0.02 |
| 12 | } |
| 13 | SubShader |
| 14 | { |
| 15 | Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" } |
| 16 | Blend SrcAlpha OneMinusSrcAlpha |
| 17 | AlphaTest Greater .01 |
| 18 | Fog{ Mode Off } |
| 19 | LOD 100 |
| 20 | Cull Off |
| 21 | |
| 22 | Pass |
| 23 | { |
| 24 | CGPROGRAM |
| 25 | #pragma vertex vert |
| 26 | #pragma fragment frag |
| 27 | |
| 28 | #include "UnityCG.cginc" |
| 29 | #include "OVRMRChromaKey.cginc" |
| 30 | |
| 31 | struct appdata |
| 32 | { |
| 33 | float4 vertex : POSITION; |
| 34 | float2 texcoord : TEXCOORD0; |
| 35 | }; |
| 36 | |
| 37 | struct v2f |
| 38 | { |
| 39 | float4 vertex : SV_POSITION; |
| 40 | float2 texcoord : TEXCOORD0; |
| 41 | }; |
| 42 | |
| 43 | sampler2D _MainTex; |
| 44 | float4 _MainTex_ST; |
| 45 | sampler2D _MaskTex; |
| 46 | |
| 47 | float4 _TextureDimension; // (w, h, 1/w, 1/h) |
| 48 | |
| 49 | fixed4 _Color; |
| 50 | fixed _Visible; |
| 51 | float4 _FlipParams; // (flip_h, flip_v, 0, 0) |
| 52 | |
| 53 | v2f vert (appdata v) |
| 54 | { |
| 55 | v2f o; |
| 56 | o.vertex = UnityObjectToClipPos(v.vertex); |
| 57 | o.vertex *= _Visible; |
| 58 | o.texcoord = TRANSFORM_TEX(float2(v.texcoord.x, 1.0-v.texcoord.y), _MainTex); |
| 59 | return o; |
| 60 | } |
| 61 | |
| 62 | fixed GetMask(float2 uv) |
| 63 | { |
| 64 | return tex2D(_MaskTex, uv).r; |
| 65 | } |
| 66 | |
| 67 | fixed4 GetCameraColor(float2 colorUV) |
| 68 | { |
| 69 | fixed4 c = tex2D(_MainTex, colorUV) * _Color; |
| 70 | return c; |
| 71 | } |
| 72 | |
| 73 | fixed4 frag (v2f i) : SV_Target |
| 74 | { |
| 75 | float2 colorUV = i.texcoord; |
| 76 | if (_FlipParams.x > 0.0) |
| 77 | { |
| 78 | colorUV.x = 1.0 - colorUV.x; |
| 79 | } |
| 80 | if (_FlipParams.y > 0.0) |
| 81 | { |
| 82 | colorUV.y = 1.0 - colorUV.y; |
| 83 | } |
| 84 | float mask = GetMask(float2(colorUV.x, 1.0 - colorUV.y)); |
| 85 | if (mask == 0.0) |
| 86 | { |
| 87 | discard; |
| 88 | } |
| 89 | float4 col = GetColorAfterChromaKey(colorUV, _TextureDimension.zw, 1.0); |
| 90 | if (col.a < 0.0) |
| 91 | { |
| 92 | discard; |
| 93 | } |
| 94 | return col; |
| 95 | } |
| 96 | ENDCG |
| 97 | } |
| 98 | } |
| 99 | } |