SteamVR_CameraMask.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Rendering;
  4. using Valve.VR;
  5. [RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
  6. public class SteamVR_CameraMask : MonoBehaviour
  7. {
  8. private void Awake()
  9. {
  10. this.meshFilter = base.GetComponent<MeshFilter>();
  11. if (SteamVR_CameraMask.material == null)
  12. {
  13. SteamVR_CameraMask.material = new Material(Shader.Find("Custom/SteamVR_HiddenArea"));
  14. }
  15. MeshRenderer component = base.GetComponent<MeshRenderer>();
  16. component.material = SteamVR_CameraMask.material;
  17. component.shadowCastingMode = ShadowCastingMode.Off;
  18. component.receiveShadows = false;
  19. component.lightProbeUsage = LightProbeUsage.Off;
  20. component.reflectionProbeUsage = ReflectionProbeUsage.Off;
  21. }
  22. public void Set(SteamVR vr, EVREye eye)
  23. {
  24. if (SteamVR_CameraMask.hiddenAreaMeshes[(int)eye] == null)
  25. {
  26. SteamVR_CameraMask.hiddenAreaMeshes[(int)eye] = SteamVR_Utils.CreateHiddenAreaMesh(vr.hmd.GetHiddenAreaMesh(eye), vr.textureBounds[(int)eye]);
  27. }
  28. this.meshFilter.mesh = SteamVR_CameraMask.hiddenAreaMeshes[(int)eye];
  29. }
  30. public void Clear()
  31. {
  32. this.meshFilter.mesh = null;
  33. }
  34. private static Material material;
  35. private static Mesh[] hiddenAreaMeshes = new Mesh[2];
  36. private MeshFilter meshFilter;
  37. }