FlipY.shader 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. Shader "NibiruXR/FlipY"
  2. {
  3. Properties
  4. {
  5. [KeywordEnum(Left, Right)] _EyeType("Eye", int) = 1
  6. _MainTex("Texture", 2D) = "white" {}
  7. }
  8. SubShader
  9. {
  10. // No culling or depth
  11. Cull Off ZWrite Off ZTest Always
  12. Pass
  13. {
  14. CGPROGRAM
  15. #pragma vertex vert
  16. #pragma fragment frag
  17. #include "UnityCG.cginc"
  18. int _EyeType;
  19. struct appdata
  20. {
  21. float4 vertex : POSITION;
  22. float2 uv : TEXCOORD0;
  23. };
  24. struct v2f
  25. {
  26. float2 uv : TEXCOORD0;
  27. float4 vertex : SV_POSITION;
  28. };
  29. v2f vert(appdata v)
  30. {
  31. v2f o;
  32. o.vertex = UnityObjectToClipPos(v.vertex);
  33. // -1,1 => -1,0
  34. if (_EyeType == 0) {
  35. o.vertex.x = o.vertex.x * 0.5f - 0.5f;
  36. }
  37. // -1,1 => 0,1
  38. if (_EyeType == 1) {
  39. o.vertex.x = o.vertex.x * 0.5f + 0.5f;
  40. }
  41. o.uv = v.uv;
  42. return o;
  43. }
  44. sampler2D _MainTex;
  45. fixed4 frag(v2f i) : SV_Target
  46. {
  47. i.uv.x = i.uv.x;
  48. if (_EyeType == 0) {
  49. i.uv.x = i.uv.x * 0.5f;
  50. }
  51. if (_EyeType == 1) {
  52. i.uv.x = i.uv.x * 0.5f + 0.5f;
  53. }
  54. i.uv.y = 1.0 - i.uv.y;
  55. fixed4 col = tex2D(_MainTex, i.uv);
  56. return col;
  57. }
  58. ENDCG
  59. }
  60. }
  61. }