Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3 KiB

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