PXR_OverlayManager.cs 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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.Runtime.InteropServices;
  13. using UnityEngine;
  14. using UnityEngine.Rendering;
  15. namespace Unity.XR.PXR
  16. {
  17. public class PXR_OverlayManager : MonoBehaviour
  18. {
  19. private void OnEnable()
  20. {
  21. #if UNITY_2019_1_OR_NEWER
  22. if (GraphicsSettings.renderPipelineAsset != null)
  23. {
  24. RenderPipelineManager.beginFrameRendering += BeginRendering;
  25. RenderPipelineManager.endFrameRendering += EndRendering;
  26. }
  27. else
  28. {
  29. Camera.onPreRender += OnPreRenderCallBack;
  30. Camera.onPostRender += OnPostRenderCallBack;
  31. }
  32. #endif
  33. }
  34. private void OnDisable()
  35. {
  36. #if UNITY_2019_1_OR_NEWER
  37. if (GraphicsSettings.renderPipelineAsset != null)
  38. {
  39. RenderPipelineManager.beginFrameRendering -= BeginRendering;
  40. RenderPipelineManager.endFrameRendering -= EndRendering;
  41. }
  42. else
  43. {
  44. Camera.onPreRender -= OnPreRenderCallBack;
  45. Camera.onPostRender -= OnPostRenderCallBack;
  46. }
  47. #endif
  48. }
  49. private void Start()
  50. {
  51. // external surface
  52. if (PXR_OverLay.Instances.Count > 0)
  53. {
  54. foreach (var overlay in PXR_OverLay.Instances)
  55. {
  56. if (overlay.isExternalAndroidSurface)
  57. {
  58. overlay.CreateExternalSurface(overlay);
  59. }
  60. }
  61. }
  62. }
  63. private void BeginRendering(ScriptableRenderContext arg1, Camera[] arg2)
  64. {
  65. foreach (Camera cam in arg2)
  66. {
  67. if (cam != null && Camera.main == cam)
  68. {
  69. OnPreRenderCallBack(cam);
  70. }
  71. }
  72. }
  73. private void EndRendering(ScriptableRenderContext arg1, Camera[] arg2)
  74. {
  75. foreach (Camera cam in arg2)
  76. {
  77. if (cam != null && Camera.main == cam)
  78. {
  79. OnPostRenderCallBack(cam);
  80. }
  81. }
  82. }
  83. private void OnPreRenderCallBack(Camera cam)
  84. {
  85. // There is only one XR main camera in the scene.
  86. if (null == Camera.main) return;
  87. if (cam == null || cam != Camera.main || cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right) return;
  88. //CompositeLayers
  89. int boundaryState = PXR_Plugin.Boundary.UPxr_GetSeeThroughState();
  90. if (null == PXR_OverLay.Instances) return;
  91. if (PXR_OverLay.Instances.Count > 0 && boundaryState != 2)
  92. {
  93. foreach (var overlay in PXR_OverLay.Instances)
  94. {
  95. if (!overlay.isActiveAndEnabled) continue;
  96. if (null == overlay.layerTextures) continue;
  97. if (!overlay.isClones && overlay.layerTextures[0] == null && overlay.layerTextures[1] == null && !overlay.isExternalAndroidSurface) continue;
  98. if (overlay.overlayTransform != null && !overlay.overlayTransform.gameObject.activeSelf) continue;
  99. overlay.CreateTexture();
  100. PXR_Plugin.Render.UPxr_GetLayerNextImageIndex(overlay.overlayIndex, ref overlay.imageIndex);
  101. }
  102. }
  103. }
  104. private void OnPostRenderCallBack(Camera cam)
  105. {
  106. // There is only one XR main camera in the scene.
  107. if (null == Camera.main) return;
  108. if (cam == null || cam != Camera.main || cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right) return;
  109. int boundaryState = PXR_Plugin.Boundary.UPxr_GetSeeThroughState();
  110. if (null == PXR_OverLay.Instances) return;
  111. if (PXR_OverLay.Instances.Count > 0 && boundaryState != 2)
  112. {
  113. PXR_OverLay.Instances.Sort();
  114. foreach (var compositeLayer in PXR_OverLay.Instances)
  115. {
  116. if (null == compositeLayer) continue;
  117. compositeLayer.UpdateCoords();
  118. if (!compositeLayer.isActiveAndEnabled) continue;
  119. if (null == compositeLayer.layerTextures) continue;
  120. if (!compositeLayer.isClones && compositeLayer.layerTextures[0] == null && compositeLayer.layerTextures[1] == null && !compositeLayer.isExternalAndroidSurface) continue;
  121. if (compositeLayer.overlayTransform != null && null == compositeLayer.overlayTransform.gameObject) continue;
  122. if (compositeLayer.overlayTransform != null && !compositeLayer.overlayTransform.gameObject.activeSelf) continue;
  123. Vector4 colorScale = compositeLayer.GetLayerColorScale();
  124. Vector4 colorBias = compositeLayer.GetLayerColorOffset();
  125. bool isHeadLocked = false;
  126. if (compositeLayer.overlayTransform != null && compositeLayer.overlayTransform.parent == transform)
  127. {
  128. isHeadLocked = true;
  129. }
  130. if (!compositeLayer.isExternalAndroidSurface && !compositeLayer.CopyRT()) continue;
  131. if (null == compositeLayer.cameraRotations || null == compositeLayer.modelScales || null == compositeLayer.modelTranslations) continue;
  132. // set color matrics
  133. PXR_Plugin.Render.UPxr_SetConfigFloatArray(ConfigType.SetSubmitLayerEXTItemColorMatrix, compositeLayer.colorMatrix, 18);
  134. if (compositeLayer.overlayShape == PXR_OverLay.OverlayShape.Quad)
  135. {
  136. PxrLayerQuad2 layerSubmit2 = new PxrLayerQuad2();
  137. layerSubmit2.header.layerId = compositeLayer.overlayIndex;
  138. layerSubmit2.header.colorScaleX = colorScale.x;
  139. layerSubmit2.header.colorScaleY = colorScale.y;
  140. layerSubmit2.header.colorScaleZ = colorScale.z;
  141. layerSubmit2.header.colorScaleW = colorScale.w;
  142. layerSubmit2.header.colorBiasX = colorBias.x;
  143. layerSubmit2.header.colorBiasY = colorBias.y;
  144. layerSubmit2.header.colorBiasZ = colorBias.z;
  145. layerSubmit2.header.colorBiasW = colorBias.w;
  146. layerSubmit2.header.compositionDepth = compositeLayer.layerDepth;
  147. layerSubmit2.header.headPose.orientation.x = compositeLayer.cameraRotations[0].x;
  148. layerSubmit2.header.headPose.orientation.y = compositeLayer.cameraRotations[0].y;
  149. layerSubmit2.header.headPose.orientation.z = -compositeLayer.cameraRotations[0].z;
  150. layerSubmit2.header.headPose.orientation.w = -compositeLayer.cameraRotations[0].w;
  151. layerSubmit2.header.headPose.position.x = (compositeLayer.cameraTranslations[0].x + compositeLayer.cameraTranslations[1].x) / 2;
  152. layerSubmit2.header.headPose.position.y = (compositeLayer.cameraTranslations[0].y + compositeLayer.cameraTranslations[1].y) / 2;
  153. layerSubmit2.header.headPose.position.z = -(compositeLayer.cameraTranslations[0].z + compositeLayer.cameraTranslations[1].z) / 2;
  154. layerSubmit2.header.layerShape = PXR_OverLay.OverlayShape.Quad;
  155. layerSubmit2.header.useLayerBlend = (UInt32)(compositeLayer.useLayerBlend ? 1 : 0);
  156. layerSubmit2.header.layerBlend.srcColor = compositeLayer.srcColor;
  157. layerSubmit2.header.layerBlend.dstColor = compositeLayer.dstColor;
  158. layerSubmit2.header.layerBlend.srcAlpha = compositeLayer.srcAlpha;
  159. layerSubmit2.header.layerBlend.dstAlpha = compositeLayer.dstAlpha;
  160. layerSubmit2.header.useImageRect = (UInt32)(compositeLayer.useImageRect ? 1 : 0);
  161. layerSubmit2.header.imageRectLeft = compositeLayer.getPxrRectiLeft(true);
  162. layerSubmit2.header.imageRectRight = compositeLayer.getPxrRectiLeft(false);
  163. layerSubmit2.sizeLeft.x = compositeLayer.modelScales[0].x;
  164. layerSubmit2.sizeLeft.y = compositeLayer.modelScales[0].y;
  165. layerSubmit2.sizeRight.x = compositeLayer.modelScales[0].x;
  166. layerSubmit2.sizeRight.y = compositeLayer.modelScales[0].y;
  167. if (isHeadLocked)
  168. {
  169. layerSubmit2.poseLeft.orientation.x = compositeLayer.overlayTransform.localRotation.x;
  170. layerSubmit2.poseLeft.orientation.y = compositeLayer.overlayTransform.localRotation.y;
  171. layerSubmit2.poseLeft.orientation.z = -compositeLayer.overlayTransform.localRotation.z;
  172. layerSubmit2.poseLeft.orientation.w = -compositeLayer.overlayTransform.localRotation.w;
  173. layerSubmit2.poseLeft.position.x = compositeLayer.overlayTransform.localPosition.x;
  174. layerSubmit2.poseLeft.position.y = compositeLayer.overlayTransform.localPosition.y;
  175. layerSubmit2.poseLeft.position.z = -compositeLayer.overlayTransform.localPosition.z;
  176. layerSubmit2.poseRight.orientation.x = compositeLayer.overlayTransform.localRotation.x;
  177. layerSubmit2.poseRight.orientation.y = compositeLayer.overlayTransform.localRotation.y;
  178. layerSubmit2.poseRight.orientation.z = -compositeLayer.overlayTransform.localRotation.z;
  179. layerSubmit2.poseRight.orientation.w = -compositeLayer.overlayTransform.localRotation.w;
  180. layerSubmit2.poseRight.position.x = compositeLayer.overlayTransform.localPosition.x;
  181. layerSubmit2.poseRight.position.y = compositeLayer.overlayTransform.localPosition.y;
  182. layerSubmit2.poseRight.position.z = -compositeLayer.overlayTransform.localPosition.z;
  183. layerSubmit2.header.layerFlags = (UInt32)(
  184. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace |
  185. PxrLayerSubmitFlags.PxrLayerFlagHeadLocked);
  186. }
  187. else
  188. {
  189. layerSubmit2.poseLeft.orientation.x = compositeLayer.modelRotations[0].x;
  190. layerSubmit2.poseLeft.orientation.y = compositeLayer.modelRotations[0].y;
  191. layerSubmit2.poseLeft.orientation.z = -compositeLayer.modelRotations[0].z;
  192. layerSubmit2.poseLeft.orientation.w = -compositeLayer.modelRotations[0].w;
  193. layerSubmit2.poseLeft.position.x = compositeLayer.modelTranslations[0].x;
  194. layerSubmit2.poseLeft.position.y = compositeLayer.modelTranslations[0].y;
  195. layerSubmit2.poseLeft.position.z = -compositeLayer.modelTranslations[0].z;
  196. layerSubmit2.poseRight.orientation.x = compositeLayer.modelRotations[0].x;
  197. layerSubmit2.poseRight.orientation.y = compositeLayer.modelRotations[0].y;
  198. layerSubmit2.poseRight.orientation.z = -compositeLayer.modelRotations[0].z;
  199. layerSubmit2.poseRight.orientation.w = -compositeLayer.modelRotations[0].w;
  200. layerSubmit2.poseRight.position.x = compositeLayer.modelTranslations[0].x;
  201. layerSubmit2.poseRight.position.y = compositeLayer.modelTranslations[0].y;
  202. layerSubmit2.poseRight.position.z = -compositeLayer.modelTranslations[0].z;
  203. layerSubmit2.header.layerFlags = (UInt32)(
  204. PxrLayerSubmitFlags.PxrLayerFlagUseExternalHeadPose |
  205. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace);
  206. }
  207. if (compositeLayer.isPremultipliedAlpha)
  208. {
  209. layerSubmit2.header.layerFlags |= (UInt32)PxrLayerSubmitFlags.PxrLayerFlagPremultipliedAlpha;
  210. }
  211. if (compositeLayer.useImageRect)
  212. {
  213. layerSubmit2.poseLeft.position.x += -0.5f + compositeLayer.dstRectLeft.x + 0.5f * Mathf.Min(compositeLayer.dstRectLeft.width, 1 - compositeLayer.dstRectLeft.x);
  214. layerSubmit2.poseLeft.position.y += -0.5f + compositeLayer.dstRectLeft.y + 0.5f * Mathf.Min(compositeLayer.dstRectLeft.height, 1 - compositeLayer.dstRectLeft.y);
  215. layerSubmit2.poseRight.position.x += -0.5f + compositeLayer.dstRectRight.x + 0.5f * Mathf.Min(compositeLayer.dstRectRight.width, 1 - compositeLayer.dstRectRight.x);
  216. layerSubmit2.poseRight.position.y += -0.5f + compositeLayer.dstRectRight.y + 0.5f * Mathf.Min(compositeLayer.dstRectRight.height, 1 - compositeLayer.dstRectRight.y);
  217. layerSubmit2.sizeLeft.x = compositeLayer.modelScales[0].x * Mathf.Min(compositeLayer.dstRectLeft.width, 1 - compositeLayer.dstRectLeft.x);
  218. layerSubmit2.sizeLeft.y = compositeLayer.modelScales[0].y * Mathf.Min(compositeLayer.dstRectLeft.height, 1 - compositeLayer.dstRectLeft.y);
  219. layerSubmit2.sizeRight.x = compositeLayer.modelScales[0].x * Mathf.Min(compositeLayer.dstRectRight.width, 1 - compositeLayer.dstRectRight.x);
  220. layerSubmit2.sizeRight.y = compositeLayer.modelScales[0].y * Mathf.Min(compositeLayer.dstRectRight.height, 1 - compositeLayer.dstRectRight.y);
  221. }
  222. if (PXR_Plugin.Render.UPxr_SubmitLayerQuad2(layerSubmit2))
  223. {
  224. PxrLayerQuad layerSubmit = new PxrLayerQuad();
  225. layerSubmit.header.layerId = compositeLayer.overlayIndex;
  226. layerSubmit.header.colorScaleX = colorScale.x;
  227. layerSubmit.header.colorScaleY = colorScale.y;
  228. layerSubmit.header.colorScaleZ = colorScale.z;
  229. layerSubmit.header.colorScaleW = colorScale.w;
  230. layerSubmit.header.colorBiasX = colorBias.x;
  231. layerSubmit.header.colorBiasY = colorBias.y;
  232. layerSubmit.header.colorBiasZ = colorBias.z;
  233. layerSubmit.header.colorBiasW = colorBias.w;
  234. layerSubmit.header.compositionDepth = compositeLayer.layerDepth;
  235. layerSubmit.header.headPose.orientation.x = compositeLayer.cameraRotations[0].x;
  236. layerSubmit.header.headPose.orientation.y = compositeLayer.cameraRotations[0].y;
  237. layerSubmit.header.headPose.orientation.z = -compositeLayer.cameraRotations[0].z;
  238. layerSubmit.header.headPose.orientation.w = -compositeLayer.cameraRotations[0].w;
  239. layerSubmit.header.headPose.position.x = (compositeLayer.cameraTranslations[0].x + compositeLayer.cameraTranslations[1].x) / 2;
  240. layerSubmit.header.headPose.position.y = (compositeLayer.cameraTranslations[0].y + compositeLayer.cameraTranslations[1].y) / 2;
  241. layerSubmit.header.headPose.position.z = -(compositeLayer.cameraTranslations[0].z + compositeLayer.cameraTranslations[1].z) / 2;
  242. if (isHeadLocked)
  243. {
  244. layerSubmit.pose.orientation.x = compositeLayer.overlayTransform.localRotation.x;
  245. layerSubmit.pose.orientation.y = compositeLayer.overlayTransform.localRotation.y;
  246. layerSubmit.pose.orientation.z = -compositeLayer.overlayTransform.localRotation.z;
  247. layerSubmit.pose.orientation.w = -compositeLayer.overlayTransform.localRotation.w;
  248. layerSubmit.pose.position.x = compositeLayer.overlayTransform.localPosition.x;
  249. layerSubmit.pose.position.y = compositeLayer.overlayTransform.localPosition.y;
  250. layerSubmit.pose.position.z = -compositeLayer.overlayTransform.localPosition.z;
  251. layerSubmit.header.layerFlags = (UInt32)(
  252. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace |
  253. PxrLayerSubmitFlags.PxrLayerFlagHeadLocked);
  254. }
  255. else
  256. {
  257. layerSubmit.pose.orientation.x = compositeLayer.modelRotations[0].x;
  258. layerSubmit.pose.orientation.y = compositeLayer.modelRotations[0].y;
  259. layerSubmit.pose.orientation.z = -compositeLayer.modelRotations[0].z;
  260. layerSubmit.pose.orientation.w = -compositeLayer.modelRotations[0].w;
  261. layerSubmit.pose.position.x = compositeLayer.modelTranslations[0].x;
  262. layerSubmit.pose.position.y = compositeLayer.modelTranslations[0].y;
  263. layerSubmit.pose.position.z = -compositeLayer.modelTranslations[0].z;
  264. layerSubmit.header.layerFlags = (UInt32)(
  265. PxrLayerSubmitFlags.PxrLayerFlagUseExternalHeadPose |
  266. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace);
  267. }
  268. layerSubmit.width = compositeLayer.modelScales[0].x;
  269. layerSubmit.height = compositeLayer.modelScales[0].y;
  270. PXR_Plugin.Render.UPxr_SubmitLayerQuad(layerSubmit);
  271. }
  272. }
  273. else if (compositeLayer.overlayShape == PXR_OverLay.OverlayShape.Cylinder)
  274. {
  275. PxrLayerCylinder2 layerSubmit2 = new PxrLayerCylinder2();
  276. layerSubmit2.header.layerId = compositeLayer.overlayIndex;
  277. layerSubmit2.header.colorScaleX = colorScale.x;
  278. layerSubmit2.header.colorScaleY = colorScale.y;
  279. layerSubmit2.header.colorScaleZ = colorScale.z;
  280. layerSubmit2.header.colorScaleW = colorScale.w;
  281. layerSubmit2.header.colorBiasX = colorBias.x;
  282. layerSubmit2.header.colorBiasY = colorBias.y;
  283. layerSubmit2.header.colorBiasZ = colorBias.z;
  284. layerSubmit2.header.colorBiasW = colorBias.w;
  285. layerSubmit2.header.compositionDepth = compositeLayer.layerDepth;
  286. layerSubmit2.header.headPose.orientation.x = compositeLayer.cameraRotations[0].x;
  287. layerSubmit2.header.headPose.orientation.y = compositeLayer.cameraRotations[0].y;
  288. layerSubmit2.header.headPose.orientation.z = -compositeLayer.cameraRotations[0].z;
  289. layerSubmit2.header.headPose.orientation.w = -compositeLayer.cameraRotations[0].w;
  290. layerSubmit2.header.headPose.position.x = (compositeLayer.cameraTranslations[0].x + compositeLayer.cameraTranslations[1].x) / 2;
  291. layerSubmit2.header.headPose.position.y = (compositeLayer.cameraTranslations[0].y + compositeLayer.cameraTranslations[1].y) / 2;
  292. layerSubmit2.header.headPose.position.z = -(compositeLayer.cameraTranslations[0].z + compositeLayer.cameraTranslations[1].z) / 2;
  293. layerSubmit2.header.layerShape = PXR_OverLay.OverlayShape.Cylinder;
  294. layerSubmit2.header.useLayerBlend = (UInt32)(compositeLayer.useLayerBlend ? 1 : 0);
  295. layerSubmit2.header.layerBlend.srcColor = compositeLayer.srcColor;
  296. layerSubmit2.header.layerBlend.dstColor = compositeLayer.dstColor;
  297. layerSubmit2.header.layerBlend.srcAlpha = compositeLayer.srcAlpha;
  298. layerSubmit2.header.layerBlend.dstAlpha = compositeLayer.dstAlpha;
  299. layerSubmit2.header.useImageRect = (UInt32)(compositeLayer.useImageRect ? 1 : 0);
  300. layerSubmit2.header.imageRectLeft = compositeLayer.getPxrRectiLeft(true);
  301. layerSubmit2.header.imageRectRight = compositeLayer.getPxrRectiLeft(false);
  302. if (isHeadLocked)
  303. {
  304. layerSubmit2.poseLeft.orientation.x = compositeLayer.overlayTransform.localRotation.x;
  305. layerSubmit2.poseLeft.orientation.y = compositeLayer.overlayTransform.localRotation.y;
  306. layerSubmit2.poseLeft.orientation.z = -compositeLayer.overlayTransform.localRotation.z;
  307. layerSubmit2.poseLeft.orientation.w = -compositeLayer.overlayTransform.localRotation.w;
  308. layerSubmit2.poseLeft.position.x = compositeLayer.overlayTransform.localPosition.x;
  309. layerSubmit2.poseLeft.position.y = compositeLayer.overlayTransform.localPosition.y;
  310. layerSubmit2.poseLeft.position.z = -compositeLayer.overlayTransform.localPosition.z;
  311. layerSubmit2.poseRight.orientation.x = compositeLayer.overlayTransform.localRotation.x;
  312. layerSubmit2.poseRight.orientation.y = compositeLayer.overlayTransform.localRotation.y;
  313. layerSubmit2.poseRight.orientation.z = -compositeLayer.overlayTransform.localRotation.z;
  314. layerSubmit2.poseRight.orientation.w = -compositeLayer.overlayTransform.localRotation.w;
  315. layerSubmit2.poseRight.position.x = compositeLayer.overlayTransform.localPosition.x;
  316. layerSubmit2.poseRight.position.y = compositeLayer.overlayTransform.localPosition.y;
  317. layerSubmit2.poseRight.position.z = -compositeLayer.overlayTransform.localPosition.z;
  318. layerSubmit2.header.layerFlags = (UInt32)(
  319. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace |
  320. PxrLayerSubmitFlags.PxrLayerFlagHeadLocked);
  321. }
  322. else
  323. {
  324. layerSubmit2.poseLeft.orientation.x = compositeLayer.modelRotations[0].x;
  325. layerSubmit2.poseLeft.orientation.y = compositeLayer.modelRotations[0].y;
  326. layerSubmit2.poseLeft.orientation.z = -compositeLayer.modelRotations[0].z;
  327. layerSubmit2.poseLeft.orientation.w = -compositeLayer.modelRotations[0].w;
  328. layerSubmit2.poseLeft.position.x = compositeLayer.modelTranslations[0].x;
  329. layerSubmit2.poseLeft.position.y = compositeLayer.modelTranslations[0].y;
  330. layerSubmit2.poseLeft.position.z = -compositeLayer.modelTranslations[0].z;
  331. layerSubmit2.poseRight.orientation.x = compositeLayer.modelRotations[0].x;
  332. layerSubmit2.poseRight.orientation.y = compositeLayer.modelRotations[0].y;
  333. layerSubmit2.poseRight.orientation.z = -compositeLayer.modelRotations[0].z;
  334. layerSubmit2.poseRight.orientation.w = -compositeLayer.modelRotations[0].w;
  335. layerSubmit2.poseRight.position.x = compositeLayer.modelTranslations[0].x;
  336. layerSubmit2.poseRight.position.y = compositeLayer.modelTranslations[0].y;
  337. layerSubmit2.poseRight.position.z = -compositeLayer.modelTranslations[0].z;
  338. layerSubmit2.header.layerFlags = (UInt32)(
  339. PxrLayerSubmitFlags.PxrLayerFlagUseExternalHeadPose |
  340. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace);
  341. }
  342. if (compositeLayer.isPremultipliedAlpha)
  343. {
  344. layerSubmit2.header.layerFlags |= (UInt32)PxrLayerSubmitFlags.PxrLayerFlagPremultipliedAlpha;
  345. }
  346. if (compositeLayer.modelScales[0].z != 0)
  347. {
  348. layerSubmit2.centralAngleLeft = compositeLayer.modelScales[0].x / compositeLayer.modelScales[0].z;
  349. layerSubmit2.centralAngleRight = compositeLayer.modelScales[0].x / compositeLayer.modelScales[0].z;
  350. }
  351. else
  352. {
  353. Debug.LogError("PXRLog scale.z is 0");
  354. }
  355. layerSubmit2.heightLeft = compositeLayer.modelScales[0].y;
  356. layerSubmit2.heightRight = compositeLayer.modelScales[0].y;
  357. layerSubmit2.radiusLeft = compositeLayer.modelScales[0].z;
  358. layerSubmit2.radiusRight = compositeLayer.modelScales[0].z;
  359. if (PXR_Plugin.Render.UPxr_SubmitLayerCylinder2(layerSubmit2))
  360. {
  361. PxrLayerCylinder layerSubmit = new PxrLayerCylinder();
  362. layerSubmit.header.layerId = compositeLayer.overlayIndex;
  363. layerSubmit.header.colorScaleX = colorScale.x;
  364. layerSubmit.header.colorScaleY = colorScale.y;
  365. layerSubmit.header.colorScaleZ = colorScale.z;
  366. layerSubmit.header.colorScaleW = colorScale.w;
  367. layerSubmit.header.colorBiasX = colorBias.x;
  368. layerSubmit.header.colorBiasY = colorBias.y;
  369. layerSubmit.header.colorBiasZ = colorBias.z;
  370. layerSubmit.header.colorBiasW = colorBias.w;
  371. layerSubmit.header.compositionDepth = compositeLayer.layerDepth;
  372. layerSubmit.header.headPose.orientation.x = compositeLayer.cameraRotations[0].x;
  373. layerSubmit.header.headPose.orientation.y = compositeLayer.cameraRotations[0].y;
  374. layerSubmit.header.headPose.orientation.z = -compositeLayer.cameraRotations[0].z;
  375. layerSubmit.header.headPose.orientation.w = -compositeLayer.cameraRotations[0].w;
  376. layerSubmit.header.headPose.position.x = (compositeLayer.cameraTranslations[0].x + compositeLayer.cameraTranslations[1].x) / 2;
  377. layerSubmit.header.headPose.position.y = (compositeLayer.cameraTranslations[0].y + compositeLayer.cameraTranslations[1].y) / 2;
  378. layerSubmit.header.headPose.position.z = -(compositeLayer.cameraTranslations[0].z + compositeLayer.cameraTranslations[1].z) / 2;
  379. if (isHeadLocked)
  380. {
  381. layerSubmit.pose.orientation.x = compositeLayer.overlayTransform.localRotation.x;
  382. layerSubmit.pose.orientation.y = compositeLayer.overlayTransform.localRotation.y;
  383. layerSubmit.pose.orientation.z = -compositeLayer.overlayTransform.localRotation.z;
  384. layerSubmit.pose.orientation.w = -compositeLayer.overlayTransform.localRotation.w;
  385. layerSubmit.pose.position.x = compositeLayer.overlayTransform.localPosition.x;
  386. layerSubmit.pose.position.y = compositeLayer.overlayTransform.localPosition.y;
  387. layerSubmit.pose.position.z = -compositeLayer.overlayTransform.localPosition.z;
  388. layerSubmit.header.layerFlags = (UInt32)(
  389. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace |
  390. PxrLayerSubmitFlags.PxrLayerFlagHeadLocked);
  391. }
  392. else
  393. {
  394. layerSubmit.pose.orientation.x = compositeLayer.modelRotations[0].x;
  395. layerSubmit.pose.orientation.y = compositeLayer.modelRotations[0].y;
  396. layerSubmit.pose.orientation.z = -compositeLayer.modelRotations[0].z;
  397. layerSubmit.pose.orientation.w = -compositeLayer.modelRotations[0].w;
  398. layerSubmit.pose.position.x = compositeLayer.modelTranslations[0].x;
  399. layerSubmit.pose.position.y = compositeLayer.modelTranslations[0].y;
  400. layerSubmit.pose.position.z = -compositeLayer.modelTranslations[0].z;
  401. layerSubmit.header.layerFlags = (UInt32)(
  402. PxrLayerSubmitFlags.PxrLayerFlagUseExternalHeadPose |
  403. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace);
  404. }
  405. if (compositeLayer.modelScales[0].z != 0)
  406. {
  407. layerSubmit.centralAngle = compositeLayer.modelScales[0].x / compositeLayer.modelScales[0].z;
  408. }
  409. else
  410. {
  411. Debug.LogError("PXRLog scale.z is 0");
  412. }
  413. layerSubmit.height = compositeLayer.modelScales[0].y;
  414. layerSubmit.radius = compositeLayer.modelScales[0].z;
  415. PXR_Plugin.Render.UPxr_SubmitLayerCylinder(layerSubmit);
  416. }
  417. }
  418. else if (compositeLayer.overlayShape == PXR_OverLay.OverlayShape.Equirect)
  419. {
  420. PxrLayerEquirect2 layerSubmit2 = new PxrLayerEquirect2();
  421. layerSubmit2.header.layerId = compositeLayer.overlayIndex;
  422. layerSubmit2.header.layerFlags = (UInt32)(
  423. PxrLayerSubmitFlags.PxrLayerFlagUseExternalHeadPose |
  424. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace);
  425. layerSubmit2.header.colorScaleX = colorScale.x;
  426. layerSubmit2.header.colorScaleY = colorScale.y;
  427. layerSubmit2.header.colorScaleZ = colorScale.z;
  428. layerSubmit2.header.colorScaleW = colorScale.w;
  429. layerSubmit2.header.colorBiasX = colorBias.x;
  430. layerSubmit2.header.colorBiasY = colorBias.y;
  431. layerSubmit2.header.colorBiasZ = colorBias.z;
  432. layerSubmit2.header.colorBiasW = colorBias.w;
  433. layerSubmit2.header.compositionDepth = compositeLayer.layerDepth;
  434. layerSubmit2.header.headPose.orientation.x = compositeLayer.cameraRotations[0].x;
  435. layerSubmit2.header.headPose.orientation.y = compositeLayer.cameraRotations[0].y;
  436. layerSubmit2.header.headPose.orientation.z = -compositeLayer.cameraRotations[0].z;
  437. layerSubmit2.header.headPose.orientation.w = -compositeLayer.cameraRotations[0].w;
  438. layerSubmit2.header.headPose.position.x = (compositeLayer.cameraTranslations[0].x + compositeLayer.cameraTranslations[1].x) / 2;
  439. layerSubmit2.header.headPose.position.y = (compositeLayer.cameraTranslations[0].y + compositeLayer.cameraTranslations[1].y) / 2;
  440. layerSubmit2.header.headPose.position.z = -(compositeLayer.cameraTranslations[0].z + compositeLayer.cameraTranslations[1].z) / 2;
  441. layerSubmit2.header.layerShape = (PXR_OverLay.OverlayShape)4;
  442. layerSubmit2.header.useLayerBlend = (UInt32)(compositeLayer.useLayerBlend ? 1 : 0);
  443. layerSubmit2.header.layerBlend.srcColor = compositeLayer.srcColor;
  444. layerSubmit2.header.layerBlend.dstColor = compositeLayer.dstColor;
  445. layerSubmit2.header.layerBlend.srcAlpha = compositeLayer.srcAlpha;
  446. layerSubmit2.header.layerBlend.dstAlpha = compositeLayer.dstAlpha;
  447. layerSubmit2.header.useImageRect = (UInt32)(compositeLayer.useImageRect ? 1 : 0);
  448. layerSubmit2.header.imageRectLeft = compositeLayer.getPxrRectiLeft(true);
  449. layerSubmit2.header.imageRectRight = compositeLayer.getPxrRectiLeft(false);
  450. layerSubmit2.poseLeft.orientation.x = compositeLayer.modelRotations[0].x;
  451. layerSubmit2.poseLeft.orientation.y = compositeLayer.modelRotations[0].y;
  452. layerSubmit2.poseLeft.orientation.z = -compositeLayer.modelRotations[0].z;
  453. layerSubmit2.poseLeft.orientation.w = -compositeLayer.modelRotations[0].w;
  454. layerSubmit2.poseLeft.position.x = compositeLayer.modelTranslations[0].x;
  455. layerSubmit2.poseLeft.position.y = compositeLayer.modelTranslations[0].y;
  456. layerSubmit2.poseLeft.position.z = -compositeLayer.modelTranslations[0].z;
  457. layerSubmit2.poseRight.orientation.x = compositeLayer.modelRotations[0].x;
  458. layerSubmit2.poseRight.orientation.y = compositeLayer.modelRotations[0].y;
  459. layerSubmit2.poseRight.orientation.z = -compositeLayer.modelRotations[0].z;
  460. layerSubmit2.poseRight.orientation.w = -compositeLayer.modelRotations[0].w;
  461. layerSubmit2.poseRight.position.x = compositeLayer.modelTranslations[0].x;
  462. layerSubmit2.poseRight.position.y = compositeLayer.modelTranslations[0].y;
  463. layerSubmit2.poseRight.position.z = -compositeLayer.modelTranslations[0].z;
  464. layerSubmit2.radiusLeft = compositeLayer.radius;
  465. layerSubmit2.radiusRight = compositeLayer.radius;
  466. layerSubmit2.centralHorizontalAngleLeft = compositeLayer.dstRectLeft.width * 2 * Mathf.PI;
  467. layerSubmit2.centralHorizontalAngleRight = compositeLayer.dstRectRight.width * 2 * Mathf.PI;
  468. layerSubmit2.upperVerticalAngleLeft = (compositeLayer.dstRectLeft.height + compositeLayer.dstRectLeft.y - 0.5f) * Mathf.PI;
  469. layerSubmit2.upperVerticalAngleRight = (compositeLayer.dstRectRight.height + compositeLayer.dstRectRight.y - 0.5f) * Mathf.PI;
  470. layerSubmit2.lowerVerticalAngleLeft = (compositeLayer.dstRectLeft.y - 0.5f) * Mathf.PI;
  471. layerSubmit2.lowerVerticalAngleRight = (compositeLayer.dstRectRight.y - 0.5f) * Mathf.PI;
  472. if (compositeLayer.isPremultipliedAlpha)
  473. {
  474. layerSubmit2.header.layerFlags |= (UInt32)PxrLayerSubmitFlags.PxrLayerFlagPremultipliedAlpha;
  475. }
  476. if (PXR_Plugin.Render.UPxr_SubmitLayerEquirect2(layerSubmit2))
  477. {
  478. PxrLayerEquirect layerSubmit = new PxrLayerEquirect();
  479. layerSubmit.header.layerId = compositeLayer.overlayIndex;
  480. layerSubmit.header.layerFlags = (UInt32)(
  481. PxrLayerSubmitFlags.PxrLayerFlagUseExternalHeadPose |
  482. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace);
  483. layerSubmit.header.colorScaleX = colorScale.x;
  484. layerSubmit.header.colorScaleY = colorScale.y;
  485. layerSubmit.header.colorScaleZ = colorScale.z;
  486. layerSubmit.header.colorScaleW = colorScale.w;
  487. layerSubmit.header.colorBiasX = colorBias.x;
  488. layerSubmit.header.colorBiasY = colorBias.y;
  489. layerSubmit.header.colorBiasZ = colorBias.z;
  490. layerSubmit.header.colorBiasW = colorBias.w;
  491. layerSubmit.header.compositionDepth = compositeLayer.layerDepth;
  492. layerSubmit.header.headPose.orientation.x = compositeLayer.cameraRotations[0].x;
  493. layerSubmit.header.headPose.orientation.y = compositeLayer.cameraRotations[0].y;
  494. layerSubmit.header.headPose.orientation.z = -compositeLayer.cameraRotations[0].z;
  495. layerSubmit.header.headPose.orientation.w = -compositeLayer.cameraRotations[0].w;
  496. layerSubmit.header.headPose.position.x = (compositeLayer.cameraTranslations[0].x + compositeLayer.cameraTranslations[1].x) / 2;
  497. layerSubmit.header.headPose.position.y = (compositeLayer.cameraTranslations[0].y + compositeLayer.cameraTranslations[1].y) / 2;
  498. layerSubmit.header.headPose.position.z = -(compositeLayer.cameraTranslations[0].z + compositeLayer.cameraTranslations[1].z) / 2;
  499. layerSubmit.header.layerShape = PXR_OverLay.OverlayShape.Equirect;
  500. layerSubmit.header.useLayerBlend = (UInt32)(compositeLayer.useLayerBlend ? 1 : 0);
  501. layerSubmit.header.layerBlend.srcColor = compositeLayer.srcColor;
  502. layerSubmit.header.layerBlend.dstColor = compositeLayer.dstColor;
  503. layerSubmit.header.layerBlend.srcAlpha = compositeLayer.srcAlpha;
  504. layerSubmit.header.layerBlend.dstAlpha = compositeLayer.dstAlpha;
  505. layerSubmit.header.useImageRect = (UInt32)(compositeLayer.useImageRect ? 1 : 0);
  506. layerSubmit.header.imageRectLeft = compositeLayer.getPxrRectiLeft(true);
  507. layerSubmit.header.imageRectRight = compositeLayer.getPxrRectiLeft(false);
  508. layerSubmit.poseLeft.orientation.x = compositeLayer.modelRotations[0].x;
  509. layerSubmit.poseLeft.orientation.y = compositeLayer.modelRotations[0].y;
  510. layerSubmit.poseLeft.orientation.z = -compositeLayer.modelRotations[0].z;
  511. layerSubmit.poseLeft.orientation.w = -compositeLayer.modelRotations[0].w;
  512. layerSubmit.poseLeft.position.x = compositeLayer.modelTranslations[0].x;
  513. layerSubmit.poseLeft.position.y = compositeLayer.modelTranslations[0].y;
  514. layerSubmit.poseLeft.position.z = -compositeLayer.modelTranslations[0].z;
  515. layerSubmit.poseRight.orientation.x = compositeLayer.modelRotations[0].x;
  516. layerSubmit.poseRight.orientation.y = compositeLayer.modelRotations[0].y;
  517. layerSubmit.poseRight.orientation.z = -compositeLayer.modelRotations[0].z;
  518. layerSubmit.poseRight.orientation.w = -compositeLayer.modelRotations[0].w;
  519. layerSubmit.poseRight.position.x = compositeLayer.modelTranslations[0].x;
  520. layerSubmit.poseRight.position.y = compositeLayer.modelTranslations[0].y;
  521. layerSubmit.poseRight.position.z = -compositeLayer.modelTranslations[0].z;
  522. layerSubmit.radiusLeft = compositeLayer.radius;
  523. layerSubmit.radiusRight = compositeLayer.radius;
  524. layerSubmit.scaleXLeft = 1 / compositeLayer.dstRectLeft.width;
  525. layerSubmit.scaleXRight = 1 / compositeLayer.dstRectRight.width;
  526. layerSubmit.scaleYLeft = 1 / compositeLayer.dstRectLeft.height;
  527. layerSubmit.scaleYRight = 1 / compositeLayer.dstRectRight.height;
  528. layerSubmit.biasXLeft = -compositeLayer.dstRectLeft.x / compositeLayer.dstRectLeft.width;
  529. layerSubmit.biasXRight = -compositeLayer.dstRectRight.x / compositeLayer.dstRectRight.width;
  530. layerSubmit.biasYLeft = 1 + (compositeLayer.dstRectLeft.y - 1) / compositeLayer.dstRectLeft.height;
  531. layerSubmit.biasYRight = 1 + (compositeLayer.dstRectRight.y - 1) / compositeLayer.dstRectRight.height;
  532. if (compositeLayer.isPremultipliedAlpha)
  533. {
  534. layerSubmit.header.layerFlags |= (UInt32)PxrLayerSubmitFlags.PxrLayerFlagPremultipliedAlpha;
  535. }
  536. PXR_Plugin.Render.UPxr_SubmitLayerEquirect(layerSubmit);
  537. }
  538. }
  539. else if (compositeLayer.overlayShape == PXR_OverLay.OverlayShape.Cubemap)
  540. {
  541. PxrLayerCube2 layerSubmit2 = new PxrLayerCube2();
  542. layerSubmit2.header.layerId = compositeLayer.overlayIndex;
  543. layerSubmit2.header.colorScaleX = colorScale.x;
  544. layerSubmit2.header.colorScaleY = colorScale.y;
  545. layerSubmit2.header.colorScaleZ = colorScale.z;
  546. layerSubmit2.header.colorScaleW = colorScale.w;
  547. layerSubmit2.header.colorBiasX = colorBias.x;
  548. layerSubmit2.header.colorBiasY = colorBias.y;
  549. layerSubmit2.header.colorBiasZ = colorBias.z;
  550. layerSubmit2.header.colorBiasW = colorBias.w;
  551. layerSubmit2.header.compositionDepth = compositeLayer.layerDepth;
  552. layerSubmit2.header.headPose.orientation.x = compositeLayer.cameraRotations[0].x;
  553. layerSubmit2.header.headPose.orientation.y = compositeLayer.cameraRotations[0].y;
  554. layerSubmit2.header.headPose.orientation.z = -compositeLayer.cameraRotations[0].z;
  555. layerSubmit2.header.headPose.orientation.w = -compositeLayer.cameraRotations[0].w;
  556. layerSubmit2.header.headPose.position.x = (compositeLayer.cameraTranslations[0].x + compositeLayer.cameraTranslations[1].x) / 2;
  557. layerSubmit2.header.headPose.position.y = (compositeLayer.cameraTranslations[0].y + compositeLayer.cameraTranslations[1].y) / 2;
  558. layerSubmit2.header.headPose.position.z = -(compositeLayer.cameraTranslations[0].z + compositeLayer.cameraTranslations[1].z) / 2;
  559. layerSubmit2.header.layerShape = PXR_OverLay.OverlayShape.Cubemap;
  560. layerSubmit2.header.useLayerBlend = (UInt32)(compositeLayer.useLayerBlend ? 1 : 0);
  561. layerSubmit2.header.layerBlend.srcColor = compositeLayer.srcColor;
  562. layerSubmit2.header.layerBlend.dstColor = compositeLayer.dstColor;
  563. layerSubmit2.header.layerBlend.srcAlpha = compositeLayer.srcAlpha;
  564. layerSubmit2.header.layerBlend.dstAlpha = compositeLayer.dstAlpha;
  565. if (isHeadLocked)
  566. {
  567. layerSubmit2.poseLeft.orientation.x = compositeLayer.overlayTransform.localRotation.x;
  568. layerSubmit2.poseLeft.orientation.y = compositeLayer.overlayTransform.localRotation.y;
  569. layerSubmit2.poseLeft.orientation.z = -compositeLayer.overlayTransform.localRotation.z;
  570. layerSubmit2.poseLeft.orientation.w = -compositeLayer.overlayTransform.localRotation.w;
  571. layerSubmit2.poseLeft.position.x = compositeLayer.overlayTransform.localPosition.x;
  572. layerSubmit2.poseLeft.position.y = compositeLayer.overlayTransform.localPosition.y;
  573. layerSubmit2.poseLeft.position.z = -compositeLayer.overlayTransform.localPosition.z;
  574. layerSubmit2.poseRight.orientation.x = compositeLayer.overlayTransform.localRotation.x;
  575. layerSubmit2.poseRight.orientation.y = compositeLayer.overlayTransform.localRotation.y;
  576. layerSubmit2.poseRight.orientation.z = -compositeLayer.overlayTransform.localRotation.z;
  577. layerSubmit2.poseRight.orientation.w = -compositeLayer.overlayTransform.localRotation.w;
  578. layerSubmit2.poseRight.position.x = compositeLayer.overlayTransform.localPosition.x;
  579. layerSubmit2.poseRight.position.y = compositeLayer.overlayTransform.localPosition.y;
  580. layerSubmit2.poseRight.position.z = -compositeLayer.overlayTransform.localPosition.z;
  581. layerSubmit2.header.layerFlags = (UInt32)(
  582. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace |
  583. PxrLayerSubmitFlags.PxrLayerFlagHeadLocked);
  584. }
  585. else
  586. {
  587. layerSubmit2.poseLeft.orientation.x = compositeLayer.modelRotations[0].x;
  588. layerSubmit2.poseLeft.orientation.y = compositeLayer.modelRotations[0].y;
  589. layerSubmit2.poseLeft.orientation.z = -compositeLayer.modelRotations[0].z;
  590. layerSubmit2.poseLeft.orientation.w = -compositeLayer.modelRotations[0].w;
  591. layerSubmit2.poseLeft.position.x = compositeLayer.modelTranslations[0].x;
  592. layerSubmit2.poseLeft.position.y = compositeLayer.modelTranslations[0].y;
  593. layerSubmit2.poseLeft.position.z = -compositeLayer.modelTranslations[0].z;
  594. layerSubmit2.poseRight.orientation.x = compositeLayer.modelRotations[0].x;
  595. layerSubmit2.poseRight.orientation.y = compositeLayer.modelRotations[0].y;
  596. layerSubmit2.poseRight.orientation.z = -compositeLayer.modelRotations[0].z;
  597. layerSubmit2.poseRight.orientation.w = -compositeLayer.modelRotations[0].w;
  598. layerSubmit2.poseRight.position.x = compositeLayer.modelTranslations[0].x;
  599. layerSubmit2.poseRight.position.y = compositeLayer.modelTranslations[0].y;
  600. layerSubmit2.poseRight.position.z = -compositeLayer.modelTranslations[0].z;
  601. layerSubmit2.header.layerFlags = (UInt32)(
  602. PxrLayerSubmitFlags.PxrLayerFlagUseExternalHeadPose |
  603. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace);
  604. }
  605. if (compositeLayer.isPremultipliedAlpha)
  606. {
  607. layerSubmit2.header.layerFlags |= (UInt32)PxrLayerSubmitFlags.PxrLayerFlagPremultipliedAlpha;
  608. }
  609. PXR_Plugin.Render.UPxr_SubmitLayerCube2(layerSubmit2);
  610. }
  611. else if (compositeLayer.overlayShape == PXR_OverLay.OverlayShape.Eac)
  612. {
  613. PxrLayerEac2 layerSubmit2 = new PxrLayerEac2();
  614. layerSubmit2.header.layerId = compositeLayer.overlayIndex;
  615. layerSubmit2.header.colorScaleX = colorScale.x;
  616. layerSubmit2.header.colorScaleY = colorScale.y;
  617. layerSubmit2.header.colorScaleZ = colorScale.z;
  618. layerSubmit2.header.colorScaleW = colorScale.w;
  619. layerSubmit2.header.colorBiasX = colorBias.x;
  620. layerSubmit2.header.colorBiasY = colorBias.y;
  621. layerSubmit2.header.colorBiasZ = colorBias.z;
  622. layerSubmit2.header.colorBiasW = colorBias.w;
  623. layerSubmit2.header.compositionDepth = compositeLayer.layerDepth;
  624. layerSubmit2.header.headPose.orientation.x = compositeLayer.cameraRotations[0].x;
  625. layerSubmit2.header.headPose.orientation.y = compositeLayer.cameraRotations[0].y;
  626. layerSubmit2.header.headPose.orientation.z = -compositeLayer.cameraRotations[0].z;
  627. layerSubmit2.header.headPose.orientation.w = -compositeLayer.cameraRotations[0].w;
  628. layerSubmit2.header.headPose.position.x = (compositeLayer.cameraTranslations[0].x + compositeLayer.cameraTranslations[1].x) / 2;
  629. layerSubmit2.header.headPose.position.y = (compositeLayer.cameraTranslations[0].y + compositeLayer.cameraTranslations[1].y) / 2;
  630. layerSubmit2.header.headPose.position.z = -(compositeLayer.cameraTranslations[0].z + compositeLayer.cameraTranslations[1].z) / 2;
  631. layerSubmit2.header.layerShape = PXR_OverLay.OverlayShape.Eac;
  632. layerSubmit2.header.useLayerBlend = (UInt32)(compositeLayer.useLayerBlend ? 1 : 0);
  633. layerSubmit2.header.layerBlend.srcColor = compositeLayer.srcColor;
  634. layerSubmit2.header.layerBlend.dstColor = compositeLayer.dstColor;
  635. layerSubmit2.header.layerBlend.srcAlpha = compositeLayer.srcAlpha;
  636. layerSubmit2.header.layerBlend.dstAlpha = compositeLayer.dstAlpha;
  637. layerSubmit2.header.useImageRect = (UInt32)(compositeLayer.useImageRect ? 1 : 0);
  638. layerSubmit2.header.imageRectLeft = compositeLayer.getPxrRectiLeft(true);
  639. layerSubmit2.header.imageRectRight = compositeLayer.getPxrRectiLeft(false);
  640. if (isHeadLocked)
  641. {
  642. layerSubmit2.poseLeft.orientation.x = compositeLayer.overlayTransform.localRotation.x;
  643. layerSubmit2.poseLeft.orientation.y = compositeLayer.overlayTransform.localRotation.y;
  644. layerSubmit2.poseLeft.orientation.z = -compositeLayer.overlayTransform.localRotation.z;
  645. layerSubmit2.poseLeft.orientation.w = -compositeLayer.overlayTransform.localRotation.w;
  646. layerSubmit2.poseLeft.position.x = compositeLayer.overlayTransform.localPosition.x;
  647. layerSubmit2.poseLeft.position.y = compositeLayer.overlayTransform.localPosition.y;
  648. layerSubmit2.poseLeft.position.z = -compositeLayer.overlayTransform.localPosition.z;
  649. layerSubmit2.poseRight.orientation.x = compositeLayer.overlayTransform.localRotation.x;
  650. layerSubmit2.poseRight.orientation.y = compositeLayer.overlayTransform.localRotation.y;
  651. layerSubmit2.poseRight.orientation.z = -compositeLayer.overlayTransform.localRotation.z;
  652. layerSubmit2.poseRight.orientation.w = -compositeLayer.overlayTransform.localRotation.w;
  653. layerSubmit2.poseRight.position.x = compositeLayer.overlayTransform.localPosition.x;
  654. layerSubmit2.poseRight.position.y = compositeLayer.overlayTransform.localPosition.y;
  655. layerSubmit2.poseRight.position.z = -compositeLayer.overlayTransform.localPosition.z;
  656. layerSubmit2.header.layerFlags = (UInt32)(
  657. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace |
  658. PxrLayerSubmitFlags.PxrLayerFlagHeadLocked);
  659. }
  660. else
  661. {
  662. layerSubmit2.poseLeft.orientation.x = compositeLayer.modelRotations[0].x;
  663. layerSubmit2.poseLeft.orientation.y = compositeLayer.modelRotations[0].y;
  664. layerSubmit2.poseLeft.orientation.z = -compositeLayer.modelRotations[0].z;
  665. layerSubmit2.poseLeft.orientation.w = -compositeLayer.modelRotations[0].w;
  666. layerSubmit2.poseLeft.position.x = compositeLayer.modelTranslations[0].x;
  667. layerSubmit2.poseLeft.position.y = compositeLayer.modelTranslations[0].y;
  668. layerSubmit2.poseLeft.position.z = -compositeLayer.modelTranslations[0].z;
  669. layerSubmit2.poseRight.orientation.x = compositeLayer.modelRotations[0].x;
  670. layerSubmit2.poseRight.orientation.y = compositeLayer.modelRotations[0].y;
  671. layerSubmit2.poseRight.orientation.z = -compositeLayer.modelRotations[0].z;
  672. layerSubmit2.poseRight.orientation.w = -compositeLayer.modelRotations[0].w;
  673. layerSubmit2.poseRight.position.x = compositeLayer.modelTranslations[0].x;
  674. layerSubmit2.poseRight.position.y = compositeLayer.modelTranslations[0].y;
  675. layerSubmit2.poseRight.position.z = -compositeLayer.modelTranslations[0].z;
  676. layerSubmit2.header.layerFlags = (UInt32)(
  677. PxrLayerSubmitFlags.PxrLayerFlagUseExternalHeadPose |
  678. PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace);
  679. }
  680. layerSubmit2.offsetPosLeft.x = compositeLayer.offsetPosLeft.x;
  681. layerSubmit2.offsetPosLeft.y = compositeLayer.offsetPosLeft.y;
  682. layerSubmit2.offsetPosLeft.z = compositeLayer.offsetPosLeft.z;
  683. layerSubmit2.offsetPosRight.x = compositeLayer.offsetPosRight.x;
  684. layerSubmit2.offsetPosRight.y = compositeLayer.offsetPosRight.y;
  685. layerSubmit2.offsetPosRight.z = compositeLayer.offsetPosRight.z;
  686. layerSubmit2.offsetRotLeft.x = compositeLayer.offsetRotLeft.x;
  687. layerSubmit2.offsetRotLeft.y = compositeLayer.offsetRotLeft.y;
  688. layerSubmit2.offsetRotLeft.z = compositeLayer.offsetRotLeft.z;
  689. layerSubmit2.offsetRotLeft.w = compositeLayer.offsetRotLeft.w;
  690. layerSubmit2.offsetRotRight.x = compositeLayer.offsetRotRight.x;
  691. layerSubmit2.offsetRotRight.y = compositeLayer.offsetRotRight.y;
  692. layerSubmit2.offsetRotRight.z = compositeLayer.offsetRotRight.z;
  693. layerSubmit2.offsetRotRight.w = compositeLayer.offsetRotRight.w;
  694. layerSubmit2.degreeType = (uint)compositeLayer.eacModelType;
  695. layerSubmit2.overlapFactor = compositeLayer.overlapFactor;
  696. layerSubmit2.timestamp = compositeLayer.timestamp;
  697. if (compositeLayer.isPremultipliedAlpha)
  698. {
  699. layerSubmit2.header.layerFlags |= (UInt32)PxrLayerSubmitFlags.PxrLayerFlagPremultipliedAlpha;
  700. }
  701. PXR_Plugin.Render.UPxr_SubmitLayerEac2(layerSubmit2);
  702. }
  703. }
  704. }
  705. }
  706. }
  707. }
粤ICP备19079148号