Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.0 KiB

  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. Pass
  22. {
  23. CGPROGRAM
  24. #pragma vertex vert
  25. #pragma fragment frag
  26. #include "UnityCG.cginc"
  27. #include "OVRMRChromaKey.cginc"
  28. struct appdata
  29. {
  30. float4 vertex : POSITION;
  31. float2 texcoord : TEXCOORD0;
  32. };
  33. struct v2f
  34. {
  35. float4 vertex : SV_POSITION;
  36. float2 texcoord : TEXCOORD0;
  37. };
  38. sampler2D _MainTex;
  39. float4 _MainTex_ST;
  40. sampler2D _MaskTex;
  41. float4 _TextureDimension; // (w, h, 1/w, 1/h)
  42. fixed4 _Color;
  43. fixed _Visible;
  44. float4 _FlipParams; // (flip_h, flip_v, 0, 0)
  45. v2f vert (appdata v)
  46. {
  47. v2f o;
  48. o.vertex = UnityObjectToClipPos(v.vertex);
  49. o.vertex *= _Visible;
  50. o.texcoord = TRANSFORM_TEX(float2(v.texcoord.x, 1.0-v.texcoord.y), _MainTex);
  51. return o;
  52. }
  53. fixed GetMask(float2 uv)
  54. {
  55. return tex2D(_MaskTex, uv).r;
  56. }
  57. fixed4 GetCameraColor(float2 colorUV)
  58. {
  59. fixed4 c = tex2D(_MainTex, colorUV) * _Color;
  60. return c;
  61. }
  62. fixed4 frag (v2f i) : SV_Target
  63. {
  64. float2 colorUV = i.texcoord;
  65. if (_FlipParams.x > 0.0)
  66. {
  67. colorUV.x = 1.0 - colorUV.x;
  68. }
  69. if (_FlipParams.y > 0.0)
  70. {
  71. colorUV.y = 1.0 - colorUV.y;
  72. }
  73. float mask = GetMask(float2(colorUV.x, 1.0 - colorUV.y));
  74. if (mask == 0.0)
  75. {
  76. discard;
  77. }
  78. float4 col = GetColorAfterChromaKey(colorUV, _TextureDimension.zw, 1.0);
  79. if (col.a < 0.0)
  80. {
  81. discard;
  82. }
  83. return col;
  84. }
  85. ENDCG
  86. }
  87. }
  88. }