Advertisement
daserge

Stereo.shader

Apr 5th, 2019
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1.  
  2. Shader "ShaderMan/Stereo"
  3. {
  4.  
  5. Properties{
  6. _MainTex("MainTex", 2D) = "white"{}
  7. _scale("Scale", Range(0.3, 0.49)) = 0.375
  8. _ipdShift("IPD shift", Range(-0.03, 0.03)) = 0.0
  9. }
  10.  
  11. SubShader
  12. {
  13. Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
  14.  
  15. Pass
  16. {
  17. ZTest Always
  18. ZWrite Off
  19. Blend SrcAlpha OneMinusSrcAlpha
  20.  
  21. CGPROGRAM
  22. #pragma vertex vert
  23. #pragma fragment frag
  24. #include "UnityCG.cginc"
  25.  
  26. struct VertexInput {
  27. fixed4 vertex : POSITION;
  28. fixed2 uv : TEXCOORD0;
  29. fixed4 tangent : TANGENT;
  30. fixed3 normal : NORMAL;
  31. //VertexInput
  32. };
  33.  
  34.  
  35. struct VertexOutput {
  36. fixed4 pos : SV_POSITION;
  37. fixed2 uv : TEXCOORD0;
  38. //VertexOutput
  39. };
  40.  
  41. //Variables
  42.  
  43.  
  44. sampler2D _MainTex;
  45. uniform float _scale = 0.375;
  46. uniform float _ipdShift = 0.005;
  47.  
  48.  
  49. VertexOutput vert(VertexInput v)
  50. {
  51. VertexOutput o;
  52. o.pos = UnityObjectToClipPos(v.vertex);
  53. o.uv = v.uv;
  54. //VertexFactory
  55. return o;
  56. }
  57. fixed4 frag(VertexOutput i) : SV_Target{
  58.  
  59. {
  60. fixed dx = (0.5 - _scale) / 2.0;
  61. fixed dy = (1.0 - _scale) / 2.0;
  62. // Normalized pixel coordinates (from 0 to 1)
  63. fixed2 uv = i.uv;
  64. fixed3 col;
  65. if (uv.x < dx + _ipdShift || uv.y < dy
  66. || uv.x > 1.0 - dx - _ipdShift || uv.y > 1.0 - dy
  67. || (uv.x > dx + _ipdShift + _scale && uv.x < dx + _scale + 2.0 * dx - _ipdShift)) {
  68. col = fixed3(0.0, 0.0, 0.0);
  69. return fixed4(col, 1.0);
  70. }
  71. if (uv.x < 0.5)
  72. uv.x = (uv.x - dx - _ipdShift) * 1.0 / _scale;
  73. else
  74. uv.x = (uv.x - 0.5 - dx + _ipdShift) * 1.0 / _scale;
  75. uv.y = (uv.y - dy) * 1.0 / _scale;
  76.  
  77. col = tex2D(_MainTex, uv);
  78. return fixed4(col, 1.0);
  79. }
  80. }ENDCG
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement