AVProMovieCapture_ODSMerge.shader 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. Shader "Hidden/AVProMovieCapture/ODSMerge"
  2. {
  3. Properties
  4. {
  5. }
  6. SubShader
  7. {
  8. Lighting Off
  9. ZTest Always
  10. Cull Off
  11. ZWrite Off
  12. Fog { Mode off }
  13. Pass
  14. {
  15. CGPROGRAM
  16. #pragma vertex vert
  17. #pragma fragment frag
  18. #pragma target 3.0
  19. #pragma multi_compile LAYOUT_EQUIRECT360 LAYOUT_EQUIRECT180
  20. #include "UnityCG.cginc"
  21. struct appdata
  22. {
  23. float4 vertex : POSITION;
  24. float2 uv : TEXCOORD0;
  25. };
  26. struct v2f
  27. {
  28. float4 vertex : SV_POSITION;
  29. float2 uv : TEXCOORD0;
  30. };
  31. #define QUARTERPI 0.7853981633974483
  32. uniform sampler2D _leftTopTex;
  33. uniform sampler2D _leftBotTex;
  34. uniform sampler2D _rightTopTex;
  35. uniform sampler2D _rightBotTex;
  36. uniform float4 _leftTopTex_TexelSize;
  37. uniform float4 _leftBotTex_TexelSize;
  38. uniform float4 _rightTopTex_TexelSize;
  39. uniform float4 _rightBotTex_TexelSize;
  40. uniform float _sliceCenter;
  41. uniform float _pixelSliceSize;
  42. uniform int _paddingSize;
  43. uniform float _targetXTexelSize;
  44. v2f vert (appdata v)
  45. {
  46. v2f o;
  47. o.vertex = UnityObjectToClipPos(v.vertex);
  48. o.uv = v.uv;
  49. return o;
  50. }
  51. fixed4 computePixelColour(float2 uv)
  52. {
  53. fixed4 col;
  54. // uv.y > 0.5 is top of texture (left eye)
  55. // uv.y < 0.5 is bottom of texture (right eye)
  56. if (uv.y < 0.25f) {
  57. uv.y = uv.y * 4.0;
  58. float phi = ((uv.y - 0.5) * 2.0) * QUARTERPI;
  59. uv.y = (tan(phi) * 0.5) + 0.5;
  60. col = tex2D(_rightBotTex, uv);
  61. }
  62. else if (uv.y < 0.5) {
  63. uv.y = (uv.y - 0.25) * 4.0;
  64. float phi = ((uv.y - 0.5) * 2.0) * QUARTERPI;
  65. uv.y = (tan(phi) * 0.5) + 0.5;
  66. col = tex2D(_rightTopTex, uv);
  67. }
  68. else if (uv.y < 0.75) {
  69. uv.y = (uv.y - 0.5) * 4.0;
  70. float phi = ((uv.y - 0.5) * 2.0) * QUARTERPI;
  71. uv.y = (tan(phi) * 0.5) + 0.5;
  72. col = tex2D(_leftBotTex, uv);
  73. }
  74. else {
  75. uv.y = (uv.y - 0.75) * 4.0;
  76. float phi = ((uv.y - 0.5) * 2.0) * QUARTERPI;
  77. uv.y = (tan(phi) * 0.5) + 0.5;
  78. col = tex2D(_leftTopTex, uv);
  79. }
  80. return col;
  81. }
  82. fixed4 frag (v2f i) : SV_Target
  83. {
  84. fixed4 col = 0.0;
  85. float column = float(_sliceCenter) * _targetXTexelSize;
  86. float range = _pixelSliceSize * _targetXTexelSize / 2.0 + 0.000001;
  87. #if defined(LAYOUT_EQUIRECT180)
  88. float dif = ((i.uv.x + 0.5) * 0.5) - column;
  89. #else
  90. float dif = i.uv.x - column;
  91. #endif
  92. float adif = abs(dif);
  93. if (adif < range)
  94. {
  95. float r = _pixelSliceSize * _targetXTexelSize / 2.0;
  96. float rp = (_pixelSliceSize + 2.0 * _paddingSize) * _targetXTexelSize / 2.0;
  97. float xRescaled = (dif < 0 ? r - adif : r + adif) / (rp * 2.0) + _paddingSize * _targetXTexelSize;
  98. col = computePixelColour(float2(xRescaled, i.uv.y));
  99. }
  100. else
  101. {
  102. discard;
  103. }
  104. return col;
  105. }
  106. ENDCG
  107. }
  108. }
  109. }