DisplayBackground.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #if UNITY_5_4_OR_NEWER || (UNITY_5 && !UNITY_5_0)
  2. #define UNITY_HELPATTRIB
  3. #endif
  4. using UnityEngine;
  5. //-----------------------------------------------------------------------------
  6. // Copyright 2015-2020 RenderHeads Ltd. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. namespace RenderHeads.Media.AVProVideo
  9. {
  10. /// <summary>
  11. /// Draws video over the whole background using the special "background" tag on the shader.
  12. /// Useful for augmented reality.
  13. /// NOTE: This doesn't work with the camera clear mode set to 'skybox'
  14. /// </summary>
  15. [AddComponentMenu("AVPro Video/Display Background", 200)]
  16. #if UNITY_HELPATTRIB
  17. [HelpURL("http://renderheads.com/products/avpro-video/")]
  18. #endif
  19. [ExecuteInEditMode]
  20. public class DisplayBackground : MonoBehaviour
  21. {
  22. public IMediaProducer _source;
  23. public Texture2D _texture;
  24. public Material _material;
  25. //-------------------------------------------------------------------------
  26. void OnRenderObject()
  27. {
  28. if (_material == null || _texture == null)
  29. return;
  30. Vector4 uv = new Vector4(0f, 0f, 1f, 1f);
  31. _material.SetPass(0);
  32. GL.PushMatrix();
  33. GL.LoadOrtho();
  34. GL.Begin(GL.QUADS);
  35. GL.TexCoord2(uv.x, uv.y);
  36. GL.Vertex3(0.0f, 0.0f, 0.1f);
  37. GL.TexCoord2(uv.z, uv.y);
  38. GL.Vertex3(1.0f, 0.0f, 0.1f);
  39. GL.TexCoord2(uv.z, uv.w);
  40. GL.Vertex3(1.0f, 1.0f, 0.1f);
  41. GL.TexCoord2(uv.x, uv.w);
  42. GL.Vertex3(0.0f, 1.0f, 0.1f);
  43. GL.End();
  44. GL.PopMatrix();
  45. }
  46. }
  47. }