2
0

SteamVR_SphericalProjection.shader 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. // UNITY_SHADER_NO_UPGRADE
  3. Shader "Custom/SteamVR_SphericalProjection" {
  4. Properties {
  5. _MainTex ("Base (RGB)", 2D) = "white" {}
  6. _N ("N (normal of plane)", Vector) = (0,0,0,0)
  7. _Phi0 ("Phi0", Float) = 0
  8. _Phi1 ("Phi1", Float) = 1
  9. _Theta0 ("Theta0", Float) = 0
  10. _Theta1 ("Theta1", Float) = 1
  11. _UAxis ("uAxis", Vector) = (0,0,0,0)
  12. _VAxis ("vAxis", Vector) = (0,0,0,0)
  13. _UOrigin ("uOrigin", Vector) = (0,0,0,0)
  14. _VOrigin ("vOrigin", Vector) = (0,0,0,0)
  15. _UScale ("uScale", Float) = 1
  16. _VScale ("vScale", Float) = 1
  17. }
  18. CGINCLUDE
  19. #include "UnityCG.cginc"
  20. sampler2D _MainTex;
  21. float4 _N;
  22. float _Phi0, _Phi1, _Theta0, _Theta1;
  23. float4 _UAxis, _VAxis;
  24. float4 _UOrigin, _VOrigin;
  25. float _UScale, _VScale;
  26. struct v2f {
  27. float4 pos : SV_POSITION;
  28. float2 tex : TEXCOORD0;
  29. };
  30. v2f vert(appdata_base v) {
  31. v2f o;
  32. #if UNITY_VERSION >= 540
  33. o.pos = UnityObjectToClipPos(v.vertex);
  34. #else
  35. o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
  36. #endif
  37. o.tex = float2(
  38. lerp(_Phi0, _Phi1, v.texcoord.x),
  39. lerp(_Theta0, _Theta1, v.texcoord.y));
  40. return o;
  41. }
  42. float3 cartesian(float phi, float theta)
  43. {
  44. float sinTheta = sin(theta);
  45. return float3(
  46. sinTheta * sin(phi),
  47. cos(theta),
  48. sinTheta * cos(phi));
  49. }
  50. float4 frag(v2f i) : COLOR {
  51. float3 V = cartesian(i.tex.x, i.tex.y);
  52. float3 P = V / dot(V, _N.xyz); // intersection point on plane
  53. float2 uv = float2(
  54. dot(P - _UOrigin.xyz, _UAxis.xyz) * _UScale,
  55. dot(P - _VOrigin.xyz, _VAxis.xyz) * _VScale);
  56. return tex2D(_MainTex, uv);
  57. }
  58. ENDCG
  59. SubShader {
  60. Pass {
  61. ZTest Always Cull Off ZWrite Off
  62. Fog { Mode Off }
  63. CGPROGRAM
  64. #pragma vertex vert
  65. #pragma fragment frag
  66. ENDCG
  67. }
  68. }
  69. }