PXR_OverLay.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. /*******************************************************************************
  2. Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved.
  3. NOTICE:All information contained herein is, and remains the property of
  4. PICO Technology Co., Ltd. The intellectual and technical concepts
  5. contained herein are proprietary to PICO Technology Co., Ltd. and may be
  6. covered by patents, patents in process, and are protected by trade secret or
  7. copyright law. Dissemination of this information or reproduction of this
  8. material is strictly forbidden unless prior written permission is obtained from
  9. PICO Technology Co., Ltd.
  10. *******************************************************************************/
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.Runtime.InteropServices;
  15. using UnityEditor;
  16. using UnityEngine;
  17. using UnityEngine.Experimental.Rendering;
  18. using UnityEngine.Rendering;
  19. using UnityEngine.XR;
  20. namespace Unity.XR.PXR
  21. {
  22. public class PXR_OverLay : MonoBehaviour, IComparable<PXR_OverLay>
  23. {
  24. private const string TAG = "[PXR_CompositeLayers]";
  25. public static List<PXR_OverLay> Instances = new List<PXR_OverLay>();
  26. private static int overlayID = 0;
  27. [NonSerialized]
  28. public int overlayIndex;
  29. public int layerDepth;
  30. public int imageIndex = 0;
  31. public OverlayType overlayType = OverlayType.Overlay;
  32. public OverlayShape overlayShape = OverlayShape.Quad;
  33. public TextureType textureType = TextureType.ExternalSurface;
  34. public Transform overlayTransform;
  35. public Camera xrRig;
  36. public Texture[] layerTextures = new Texture[2] { null, null };
  37. public bool isPremultipliedAlpha = false;
  38. public bool isDynamic = false;
  39. public int[] overlayTextureIds = new int[2];
  40. public Matrix4x4[] mvMatrixs = new Matrix4x4[2];
  41. public Vector3[] modelScales = new Vector3[2];
  42. public Quaternion[] modelRotations = new Quaternion[2];
  43. public Vector3[] modelTranslations = new Vector3[2];
  44. public Quaternion[] cameraRotations = new Quaternion[2];
  45. public Vector3[] cameraTranslations = new Vector3[2];
  46. public Camera[] overlayEyeCamera = new Camera[2];
  47. public bool overrideColorScaleAndOffset = false;
  48. public Vector4 colorScale = Vector4.one;
  49. public Vector4 colorOffset = Vector4.zero;
  50. // Eac
  51. public Vector3 offsetPosLeft = Vector3.zero;
  52. public Vector3 offsetPosRight = Vector3.zero;
  53. public Vector4 offsetRotLeft = new Vector4(0, 0, 0, 1);
  54. public Vector4 offsetRotRight = new Vector4(0,0,0,1);
  55. public EACModelType eacModelType = EACModelType.Eac360;
  56. public float overlapFactor = 1.0f;
  57. public ulong timestamp = 0;
  58. private Vector4 overlayLayerColorScaleDefault = Vector4.one;
  59. private Vector4 overlayLayerColorOffsetDefault = Vector4.zero;
  60. public bool isExternalAndroidSurface = false;
  61. public bool isExternalAndroidSurfaceDRM = false;
  62. public Surface3DType externalAndroidSurface3DType = Surface3DType.Single;
  63. public IntPtr externalAndroidSurfaceObject = IntPtr.Zero;
  64. public delegate void ExternalAndroidSurfaceObjectCreated();
  65. public ExternalAndroidSurfaceObjectCreated externalAndroidSurfaceObjectCreated = null;
  66. // 360
  67. public float radius = 0; // >0
  68. // ImageRect
  69. public bool useImageRect = false;
  70. public TextureRect textureRect = TextureRect.StereoScopic;
  71. public DestinationRect destinationRect = DestinationRect.Default;
  72. public Rect srcRectLeft = new Rect(0, 0, 1, 1);
  73. public Rect srcRectRight = new Rect(0, 0, 1, 1);
  74. public Rect dstRectLeft = new Rect(0, 0, 1, 1);
  75. public Rect dstRectRight = new Rect(0, 0, 1, 1);
  76. public PxrRecti imageRectLeft;
  77. public PxrRecti imageRectRight;
  78. // LayerBlend
  79. public bool useLayerBlend = false;
  80. public PxrBlendFactor srcColor = PxrBlendFactor.PxrBlendFactorOne;
  81. public PxrBlendFactor dstColor = PxrBlendFactor.PxrBlendFactorOne;
  82. public PxrBlendFactor srcAlpha = PxrBlendFactor.PxrBlendFactorOne;
  83. public PxrBlendFactor dstAlpha = PxrBlendFactor.PxrBlendFactorOne;
  84. public float[] colorMatrix = new float[18] {
  85. 1,0,0, // left
  86. 0,1,0,
  87. 0,0,1,
  88. 1,0,0, // right
  89. 0,1,0,
  90. 0,0,1,
  91. };
  92. public bool isClones = false;
  93. public bool isClonesToNew = false;
  94. public PXR_OverLay originalOverLay;
  95. private bool toCreateSwapChain = false;
  96. private bool toCopyRT = false;
  97. private bool copiedRT = false;
  98. private int eyeCount = 2;
  99. private UInt32 imageCounts = 0;
  100. private PxrLayerParam overlayParam = new PxrLayerParam();
  101. private struct NativeTexture
  102. {
  103. public Texture[] textures;
  104. };
  105. private NativeTexture[] nativeTextures;
  106. private static Material cubeM;
  107. private IntPtr leftPtr = IntPtr.Zero;
  108. private IntPtr rightPtr = IntPtr.Zero;
  109. private static Material textureM;
  110. public int CompareTo(PXR_OverLay other)
  111. {
  112. return layerDepth.CompareTo(other.layerDepth);
  113. }
  114. protected void Awake()
  115. {
  116. xrRig = Camera.main;
  117. Instances.Add(this);
  118. if (null == xrRig.gameObject.GetComponent<PXR_OverlayManager>())
  119. {
  120. xrRig.gameObject.AddComponent<PXR_OverlayManager>();
  121. }
  122. overlayEyeCamera[0] = xrRig;
  123. overlayEyeCamera[1] = xrRig;
  124. overlayTransform = GetComponent<Transform>();
  125. #if UNITY_ANDROID && !UNITY_EDITOR
  126. if (overlayTransform != null)
  127. {
  128. MeshRenderer render = overlayTransform.GetComponent<MeshRenderer>();
  129. if (render != null)
  130. {
  131. render.enabled = false;
  132. }
  133. }
  134. #endif
  135. if (!isClones)
  136. {
  137. InitializeBuffer();
  138. }
  139. }
  140. private void Start()
  141. {
  142. if (isClones)
  143. {
  144. InitializeBuffer();
  145. }
  146. if (PXR_Manager.Instance == null)
  147. {
  148. return;
  149. }
  150. Camera[] cam = PXR_Manager.Instance.GetEyeCamera();
  151. if (cam[0] != null && cam[0].enabled)
  152. {
  153. RefreshCamera(cam[0], cam[0]);
  154. }
  155. else if (cam[1] != null && cam[2] != null)
  156. {
  157. RefreshCamera(cam[1], cam[2]);
  158. }
  159. }
  160. public void RefreshCamera(Camera leftCamera,Camera rightCamera)
  161. {
  162. overlayEyeCamera[0] = leftCamera;
  163. overlayEyeCamera[1] = rightCamera;
  164. }
  165. private void InitializeBuffer()
  166. {
  167. overlayID++;
  168. overlayIndex = overlayID;
  169. if (0 == overlayShape)
  170. {
  171. overlayShape = OverlayShape.Quad;
  172. }
  173. overlayParam.layerId = overlayIndex;
  174. overlayParam.layerShape = overlayShape;
  175. overlayParam.layerType = overlayType;
  176. if (GraphicsDeviceType.Vulkan == SystemInfo.graphicsDeviceType)
  177. {
  178. overlayParam.format = QualitySettings.activeColorSpace == ColorSpace.Linear ? (UInt64)ColorForamt.VK_FORMAT_R8G8B8A8_SRGB : (UInt64)RenderTextureFormat.Default;
  179. }
  180. else
  181. {
  182. overlayParam.format = QualitySettings.activeColorSpace == ColorSpace.Linear ? (UInt64)ColorForamt.GL_SRGB8_ALPHA8 : (UInt64)RenderTextureFormat.Default;
  183. }
  184. if (null == layerTextures[0] && null != layerTextures[1])
  185. {
  186. layerTextures[0] = layerTextures[1];
  187. }
  188. if (layerTextures[1] != null)
  189. {
  190. overlayParam.width = (uint)layerTextures[1].width;
  191. overlayParam.height = (uint)layerTextures[1].height;
  192. }
  193. else
  194. {
  195. overlayParam.width = (uint)PXR_Plugin.System.UPxr_GetConfigInt(ConfigType.RenderTextureWidth);
  196. overlayParam.height = (uint)PXR_Plugin.System.UPxr_GetConfigInt(ConfigType.RenderTextureHeight);
  197. }
  198. overlayParam.sampleCount = 1;
  199. if (OverlayShape.Cubemap == overlayShape)
  200. {
  201. overlayParam.faceCount = 6;
  202. if (cubeM == null)
  203. cubeM = new Material(Shader.Find("PXR_SDK/PXR_CubemapBlit"));
  204. }
  205. else
  206. {
  207. overlayParam.faceCount = 1;
  208. if (textureM == null)
  209. textureM = new Material(Shader.Find("PXR_SDK/PXR_Texture2DBlit"));
  210. }
  211. overlayParam.arraySize = 1;
  212. overlayParam.mipmapCount = 1;
  213. overlayParam.layerFlags = 0;
  214. if (isClones)
  215. {
  216. if (null != originalOverLay)
  217. {
  218. overlayParam.layerFlags |= (UInt32)PxrLayerCreateFlags.PxrLayerFlagSharedImagesBetweenLayers;
  219. leftPtr = Marshal.AllocHGlobal(Marshal.SizeOf(originalOverLay.overlayIndex));
  220. rightPtr = Marshal.AllocHGlobal(Marshal.SizeOf(originalOverLay.overlayIndex));
  221. Marshal.WriteInt64(leftPtr, originalOverLay.overlayIndex);
  222. Marshal.WriteInt64(rightPtr, originalOverLay.overlayIndex);
  223. overlayParam.leftExternalImages = leftPtr;
  224. overlayParam.rightExternalImages = rightPtr;
  225. isExternalAndroidSurface = originalOverLay.isExternalAndroidSurface;
  226. isDynamic = originalOverLay.isDynamic;
  227. overlayParam.width = (UInt32)Mathf.Min(overlayParam.width, originalOverLay.overlayParam.width);
  228. overlayParam.height = (UInt32)Mathf.Min(overlayParam.height, originalOverLay.overlayParam.height);
  229. }
  230. else
  231. {
  232. PLog.e(TAG, "In clone state, originalOverLay cannot be empty!");
  233. }
  234. }
  235. if (isExternalAndroidSurface)
  236. {
  237. overlayParam.width = 1024;
  238. overlayParam.height = 1024;
  239. if (isExternalAndroidSurfaceDRM)
  240. {
  241. overlayParam.layerFlags |= (UInt32)(PxrLayerCreateFlags.PxrLayerFlagAndroidSurface | PxrLayerCreateFlags.PxrLayerFlagProtectedContent);
  242. }
  243. else
  244. {
  245. overlayParam.layerFlags |= (UInt32)PxrLayerCreateFlags.PxrLayerFlagAndroidSurface;
  246. }
  247. if (Surface3DType.LeftRight == externalAndroidSurface3DType)
  248. {
  249. overlayParam.layerFlags |= (UInt32)PxrLayerCreateFlags.PxrLayerFlag3DLeftRightSurface;
  250. }
  251. else if (Surface3DType.TopBottom == externalAndroidSurface3DType)
  252. {
  253. overlayParam.layerFlags |= (UInt32)PxrLayerCreateFlags.PxrLayerFlag3DTopBottomSurface;
  254. }
  255. overlayParam.layerLayout = LayerLayout.Mono;
  256. IntPtr layerParamPtr = Marshal.AllocHGlobal(Marshal.SizeOf(overlayParam));
  257. Marshal.StructureToPtr(overlayParam, layerParamPtr, false);
  258. PXR_Plugin.Render.UPxr_CreateLayer(layerParamPtr);
  259. Marshal.FreeHGlobal(layerParamPtr);
  260. }
  261. else
  262. {
  263. if (!isDynamic)
  264. {
  265. overlayParam.layerFlags |= (UInt32)PxrLayerCreateFlags.PxrLayerFlagStaticImage;
  266. }
  267. if ((layerTextures[0] != null && layerTextures[1] != null && layerTextures[0] == layerTextures[1]) || null == layerTextures[1])
  268. {
  269. eyeCount = 1;
  270. overlayParam.layerLayout = LayerLayout.Mono;
  271. }
  272. else
  273. {
  274. eyeCount = 2;
  275. overlayParam.layerLayout = LayerLayout.Stereo;
  276. }
  277. PXR_Plugin.Render.UPxr_CreateLayerParam(overlayParam);
  278. toCreateSwapChain = true;
  279. CreateTexture();
  280. }
  281. }
  282. public void CreateExternalSurface(PXR_OverLay overlayInstance)
  283. {
  284. #if UNITY_ANDROID && !UNITY_EDITOR
  285. if (IntPtr.Zero != overlayInstance.externalAndroidSurfaceObject)
  286. {
  287. return;
  288. }
  289. PXR_Plugin.Render.UPxr_GetLayerAndroidSurface(overlayInstance.overlayIndex, 0, ref overlayInstance.externalAndroidSurfaceObject);
  290. PLog.i(TAG, string.Format("CreateExternalSurface: Overlay Type:{0}, LayerDepth:{1}, SurfaceObject:{2}", overlayInstance.overlayType, overlayInstance.overlayIndex, overlayInstance.externalAndroidSurfaceObject));
  291. if (IntPtr.Zero == overlayInstance.externalAndroidSurfaceObject || null == overlayInstance.externalAndroidSurfaceObjectCreated)
  292. {
  293. return;
  294. }
  295. overlayInstance.externalAndroidSurfaceObjectCreated();
  296. #endif
  297. }
  298. public void UpdateCoords()
  299. {
  300. if (null == overlayTransform || !overlayTransform.gameObject.activeSelf || null == overlayEyeCamera[0] || null == overlayEyeCamera[1])
  301. {
  302. return;
  303. }
  304. for (int i = 0; i < mvMatrixs.Length; i++)
  305. {
  306. mvMatrixs[i] = overlayEyeCamera[i].worldToCameraMatrix * overlayTransform.localToWorldMatrix;
  307. if (overlayTransform is RectTransform uiTransform)
  308. {
  309. var rect = uiTransform.rect;
  310. var lossyScale = overlayTransform.lossyScale;
  311. modelScales[i] = new Vector3(rect.width * lossyScale.x,
  312. rect.height * lossyScale.y, 1);
  313. modelTranslations[i] = uiTransform.TransformPoint(rect.center);
  314. }
  315. else
  316. {
  317. modelScales[i] = overlayTransform.lossyScale;
  318. modelTranslations[i] = overlayTransform.position;
  319. }
  320. modelRotations[i] = overlayTransform.rotation;
  321. cameraRotations[i] = overlayEyeCamera[i].transform.rotation;
  322. cameraTranslations[i] = overlayEyeCamera[i].transform.position;
  323. }
  324. }
  325. public bool CreateTexture()
  326. {
  327. if (!toCreateSwapChain)
  328. {
  329. return false;
  330. }
  331. if (null == nativeTextures)
  332. nativeTextures = new NativeTexture[eyeCount];
  333. for (int i = 0; i < eyeCount; i++)
  334. {
  335. int ret = PXR_Plugin.Render.UPxr_GetLayerImageCount(overlayIndex, (EyeType)i, ref imageCounts);
  336. if (ret != 0 || imageCounts < 1)
  337. {
  338. return false;
  339. }
  340. if (null == nativeTextures[i].textures)
  341. {
  342. nativeTextures[i].textures = new Texture[imageCounts];
  343. }
  344. for (int j = 0; j < imageCounts; j++)
  345. {
  346. IntPtr ptr = IntPtr.Zero;
  347. PXR_Plugin.Render.UPxr_GetLayerImagePtr(overlayIndex, (EyeType)i, j, ref ptr);
  348. if (IntPtr.Zero == ptr)
  349. {
  350. return false;
  351. }
  352. Texture texture;
  353. if (OverlayShape.Cubemap == overlayShape)
  354. {
  355. texture = Cubemap.CreateExternalTexture((int)overlayParam.width, TextureFormat.RGBA32, false, ptr);
  356. }
  357. else
  358. {
  359. texture = Texture2D.CreateExternalTexture((int)overlayParam.width, (int)overlayParam.height, TextureFormat.RGBA32, false, true, ptr);
  360. }
  361. if (null == texture)
  362. {
  363. return false;
  364. }
  365. nativeTextures[i].textures[j] = texture;
  366. }
  367. }
  368. toCreateSwapChain = false;
  369. toCopyRT = true;
  370. copiedRT = false;
  371. FreePtr();
  372. return true;
  373. }
  374. public bool CopyRT()
  375. {
  376. if (isClones)
  377. {
  378. return true;
  379. }
  380. if (!toCopyRT)
  381. {
  382. return copiedRT;
  383. }
  384. if (!isDynamic && copiedRT)
  385. {
  386. return copiedRT;
  387. }
  388. if (null == nativeTextures)
  389. {
  390. return false;
  391. }
  392. for (int i = 0; i < eyeCount; i++)
  393. {
  394. Texture nativeTexture = nativeTextures[i].textures[imageIndex];
  395. if (null == nativeTexture || null == layerTextures[i])
  396. continue;
  397. RenderTexture texture = layerTextures[i] as RenderTexture;
  398. if (OverlayShape.Cubemap == overlayShape && null == layerTextures[i] as Cubemap)
  399. {
  400. return false;
  401. }
  402. for (int f = 0; f < (int)overlayParam.faceCount; f++)
  403. {
  404. if (QualitySettings.activeColorSpace == ColorSpace.Gamma && texture != null && texture.format == RenderTextureFormat.ARGB32)
  405. {
  406. Graphics.CopyTexture(layerTextures[i], f, 0, nativeTexture, f, 0);
  407. }
  408. else
  409. {
  410. RenderTextureDescriptor rtDes = new RenderTextureDescriptor((int)overlayParam.width, (int)overlayParam.height, RenderTextureFormat.ARGB32, 0);
  411. rtDes.msaaSamples = (int)overlayParam.sampleCount;
  412. rtDes.useMipMap = true;
  413. rtDes.autoGenerateMips = false;
  414. rtDes.sRGB = true;
  415. RenderTexture renderTexture = RenderTexture.GetTemporary(rtDes);
  416. if (!renderTexture.IsCreated())
  417. {
  418. renderTexture.Create();
  419. }
  420. renderTexture.DiscardContents();
  421. if (OverlayShape.Cubemap == overlayShape)
  422. {
  423. cubeM.SetInt("_d", f);
  424. Graphics.Blit(layerTextures[i], renderTexture, cubeM);
  425. }
  426. else
  427. {
  428. textureM.mainTexture = texture;
  429. textureM.SetPass(0);
  430. textureM.SetInt("_premultiply", isPremultipliedAlpha ? 1 : 0);
  431. Graphics.Blit(layerTextures[i], renderTexture, textureM);
  432. }
  433. Graphics.CopyTexture(renderTexture, 0, 0, nativeTexture, f, 0);
  434. RenderTexture.ReleaseTemporary(renderTexture);
  435. }
  436. }
  437. copiedRT = true;
  438. }
  439. return copiedRT;
  440. }
  441. public void SetTexture(Texture texture, bool dynamic)
  442. {
  443. if (isExternalAndroidSurface)
  444. {
  445. PLog.w(TAG, "Not support setTexture !");
  446. return;
  447. }
  448. if (isClones)
  449. {
  450. return;
  451. }
  452. else
  453. {
  454. foreach (PXR_OverLay overlay in PXR_OverLay.Instances)
  455. {
  456. if (overlay.isClones && null != overlay.originalOverLay && overlay.originalOverLay.overlayIndex == overlayIndex)
  457. {
  458. overlay.DestroyLayer();
  459. overlay.isClonesToNew = true;
  460. }
  461. }
  462. }
  463. toCopyRT = false;
  464. PXR_Plugin.Render.UPxr_DestroyLayerByRender(overlayIndex);
  465. ClearTexture();
  466. for (int i = 0; i < layerTextures.Length; i++)
  467. {
  468. layerTextures[i] = texture;
  469. }
  470. isDynamic = dynamic;
  471. InitializeBuffer();
  472. if (!isClones)
  473. {
  474. foreach (PXR_OverLay overlay in PXR_OverLay.Instances)
  475. {
  476. if (overlay.isClones && overlay.isClonesToNew)
  477. {
  478. overlay.originalOverLay = this;
  479. overlay.InitializeBuffer();
  480. overlay.isClonesToNew = false;
  481. }
  482. }
  483. }
  484. }
  485. private void FreePtr()
  486. {
  487. if (leftPtr != IntPtr.Zero)
  488. {
  489. Marshal.FreeHGlobal(leftPtr);
  490. leftPtr = IntPtr.Zero;
  491. }
  492. if (rightPtr != IntPtr.Zero)
  493. {
  494. Marshal.FreeHGlobal(rightPtr);
  495. rightPtr = IntPtr.Zero;
  496. }
  497. }
  498. public void OnDestroy()
  499. {
  500. DestroyLayer();
  501. Instances.Remove(this);
  502. }
  503. public void DestroyLayer()
  504. {
  505. if (!isClones)
  506. {
  507. List<PXR_OverLay> toDestroyClones = new List<PXR_OverLay>();
  508. foreach (PXR_OverLay overlay in Instances)
  509. {
  510. if (overlay.isClones && null != overlay.originalOverLay && overlay.originalOverLay.overlayIndex == overlayIndex)
  511. {
  512. toDestroyClones.Add(overlay);
  513. }
  514. }
  515. foreach (PXR_OverLay overLay in toDestroyClones)
  516. {
  517. PXR_Plugin.Render.UPxr_DestroyLayerByRender(overLay.overlayIndex);
  518. ClearTexture();
  519. }
  520. }
  521. PXR_Plugin.Render.UPxr_DestroyLayerByRender(overlayIndex);
  522. ClearTexture();
  523. if (isExternalAndroidSurface)
  524. {
  525. externalAndroidSurfaceObject = IntPtr.Zero;
  526. }
  527. }
  528. private void ClearTexture()
  529. {
  530. FreePtr();
  531. if (isExternalAndroidSurface || null == nativeTextures || isClones)
  532. {
  533. return;
  534. }
  535. for (int i = 0; i < eyeCount; i++)
  536. {
  537. if (null == nativeTextures[i].textures)
  538. {
  539. continue;
  540. }
  541. for (int j = 0; j < imageCounts; j++)
  542. DestroyImmediate(nativeTextures[i].textures[j]);
  543. }
  544. nativeTextures = null;
  545. }
  546. public void SetLayerColorScaleAndOffset(Vector4 scale, Vector4 offset)
  547. {
  548. colorScale = scale;
  549. colorOffset = offset;
  550. }
  551. public void SetEACOffsetPosAndRot(Vector3 leftPos, Vector3 rightPos, Vector4 leftRot, Vector4 rightRot)
  552. {
  553. offsetPosLeft = leftPos;
  554. offsetPosRight = rightPos;
  555. offsetRotLeft = leftRot;
  556. offsetRotRight = rightRot;
  557. }
  558. public void SetEACFactor(float factor)
  559. {
  560. overlapFactor = factor;
  561. }
  562. public Vector4 GetLayerColorScale()
  563. {
  564. if (!overrideColorScaleAndOffset)
  565. {
  566. return overlayLayerColorScaleDefault;
  567. }
  568. return colorScale;
  569. }
  570. public Vector4 GetLayerColorOffset()
  571. {
  572. if (!overrideColorScaleAndOffset)
  573. {
  574. return overlayLayerColorOffsetDefault;
  575. }
  576. return colorOffset;
  577. }
  578. public PxrRecti getPxrRectiLeft(bool left)
  579. {
  580. if (left)
  581. {
  582. imageRectLeft.x = (int)(overlayParam.width * srcRectLeft.x);
  583. imageRectLeft.y = (int)(overlayParam.height * srcRectLeft.y);
  584. imageRectLeft.width = (int)(overlayParam.width * Mathf.Min(srcRectLeft.width, 1 - srcRectLeft.x));
  585. imageRectLeft.height = (int)(overlayParam.height * Mathf.Min(srcRectLeft.height, 1 - srcRectLeft.y));
  586. return imageRectLeft;
  587. }
  588. else
  589. {
  590. imageRectRight.x = (int)(overlayParam.width * srcRectRight.x);
  591. imageRectRight.y = (int)(overlayParam.height * srcRectRight.y);
  592. imageRectRight.width = (int)(overlayParam.width * Mathf.Min(srcRectRight.width, 1 - srcRectRight.x));
  593. imageRectRight.height = (int)(overlayParam.height * Mathf.Min(srcRectRight.height, 1 - srcRectRight.y));
  594. return imageRectRight;
  595. }
  596. }
  597. public enum OverlayShape
  598. {
  599. Quad = 1,
  600. Cylinder = 2,
  601. Equirect = 3,
  602. Cubemap = 5,
  603. Eac = 6
  604. }
  605. public enum OverlayType
  606. {
  607. Overlay = 0,
  608. Underlay = 1
  609. }
  610. public enum TextureType
  611. {
  612. ExternalSurface,
  613. DynamicTexture,
  614. StaticTexture
  615. }
  616. public enum LayerLayout
  617. {
  618. Stereo = 0,
  619. DoubleWide = 1,
  620. Array = 2,
  621. Mono = 3
  622. }
  623. public enum Surface3DType
  624. {
  625. Single = 0,
  626. LeftRight,
  627. TopBottom
  628. }
  629. public enum TextureRect
  630. {
  631. MonoScopic,
  632. StereoScopic,
  633. Custom
  634. }
  635. public enum DestinationRect
  636. {
  637. Default,
  638. Custom
  639. }
  640. public enum EACModelType
  641. {
  642. Eac360 = 0,
  643. Eac360ViewPort = 1,
  644. Eac180 = 4,
  645. Eac180ViewPort = 5,
  646. }
  647. public enum ColorForamt
  648. {
  649. VK_FORMAT_R8G8B8A8_UNORM = 37,
  650. VK_FORMAT_R8G8B8A8_SRGB = 43,
  651. GL_SRGB8_ALPHA8 = 0x8c43,
  652. GL_RGBA8 = 0x8058
  653. }
  654. }
  655. }
粤ICP备19079148号