2
0

SteamVR_SphericalProjection.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //======= Copyright (c) Valve Corporation, All rights reserved. ===============
  2. //
  3. // Purpose: Applies spherical projection to output.
  4. //
  5. //=============================================================================
  6. using UnityEngine;
  7. namespace Valve.VR
  8. {
  9. [ExecuteInEditMode]
  10. public class SteamVR_SphericalProjection : MonoBehaviour
  11. {
  12. static Material material;
  13. public void Set(Vector3 N,
  14. float phi0, float phi1, float theta0, float theta1, // in degrees
  15. Vector3 uAxis, Vector3 uOrigin, float uScale,
  16. Vector3 vAxis, Vector3 vOrigin, float vScale)
  17. {
  18. if (material == null)
  19. material = new Material(Shader.Find("Custom/SteamVR_SphericalProjection"));
  20. material.SetVector("_N", new Vector4(N.x, N.y, N.z));
  21. material.SetFloat("_Phi0", phi0 * Mathf.Deg2Rad);
  22. material.SetFloat("_Phi1", phi1 * Mathf.Deg2Rad);
  23. material.SetFloat("_Theta0", theta0 * Mathf.Deg2Rad + Mathf.PI / 2);
  24. material.SetFloat("_Theta1", theta1 * Mathf.Deg2Rad + Mathf.PI / 2);
  25. material.SetVector("_UAxis", uAxis);
  26. material.SetVector("_VAxis", vAxis);
  27. material.SetVector("_UOrigin", uOrigin);
  28. material.SetVector("_VOrigin", vOrigin);
  29. material.SetFloat("_UScale", uScale);
  30. material.SetFloat("_VScale", vScale);
  31. }
  32. void OnRenderImage(RenderTexture src, RenderTexture dest)
  33. {
  34. Graphics.Blit(src, dest, material);
  35. }
  36. }
  37. }