コード例 #1
0
        public void UPxr_CopyMRCTexture(Camera cam)
        {
            if (cam.tag != Camera.main.tag || cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right)
            {
                return;
            }
            if (createMRCOverlaySucceed)
            {
                PXR_Plugin.Render.UPxr_GetLayerNextImageIndex(9999, ref imageIndex);

                for (int eyeId = 0; eyeId < 2; ++eyeId)
                {
                    Texture dstT = layerTexturesInfo[eyeId].swapChain[imageIndex];

                    if (dstT == null)
                    {
                        continue;
                    }

                    bool          isLinear = (QualitySettings.activeColorSpace == ColorSpace.Linear);
                    RenderTexture rt;
                    if (eyeId == 0)
                    {
                        rt = mrcRenderTexture as RenderTexture;
                    }
                    else
                    {
                        rt = foregroundMrcRenderTexture as RenderTexture;
                    }
                    bool          bypassBlit = !isLinear && rt != null && rt.format == RenderTextureFormat.ARGB32;
                    RenderTexture tempDstRT  = null;

                    if (!bypassBlit)
                    {
                        int width = (int)layerParam.width >> 0;
                        if (width < 1)
                        {
                            width = 1;
                        }
                        int height = (int)layerParam.height >> 0;
                        if (height < 1)
                        {
                            height = 1;
                        }

                        RenderTextureDescriptor descriptor = new RenderTextureDescriptor(width, height, RenderTextureFormat.ARGB32, 0);
                        descriptor.msaaSamples      = (int)layerParam.sampleCount;
                        descriptor.useMipMap        = true;
                        descriptor.autoGenerateMips = false;
                        descriptor.sRGB             = false;

                        tempDstRT = RenderTexture.GetTemporary(descriptor);

                        if (!tempDstRT.IsCreated())
                        {
                            tempDstRT.Create();
                        }
                        if (eyeId == 0)
                        {
                            mrcRenderTexture.DiscardContents();
                        }
                        else
                        {
                            foregroundMrcRenderTexture.DiscardContents();
                        }
                        tempDstRT.DiscardContents();
                    }

                    if (bypassBlit)
                    {
                        if (eyeId == 0)
                        {
                            Graphics.CopyTexture(mrcRenderTexture, 0, 0, dstT, 0, 0);
                        }
                        else
                        {
                            Graphics.CopyTexture(foregroundMrcRenderTexture, 0, 0, dstT, 0, 0);
                        }
                    }
                    else
                    {
                        if (eyeId == 0)
                        {
                            Graphics.Blit(mrcRenderTexture, tempDstRT);
                            Graphics.CopyTexture(tempDstRT, 0, 0, dstT, 0, 0);
                        }
                        else
                        {
                            Graphics.Blit(foregroundMrcRenderTexture, tempDstRT);
                            Graphics.CopyTexture(tempDstRT, 0, 0, dstT, 0, 0);
                        }
                    }

                    if (tempDstRT != null)
                    {
                        RenderTexture.ReleaseTemporary(tempDstRT);
                    }
                }


                PxrLayerQuad layerSubmit = new PxrLayerQuad();
                layerSubmit.header.layerId                = 9999;
                layerSubmit.header.layerFlags             = (UInt32)PxrLayerSubmitFlagsEXT.PxrLayerFlagMRCComposition;
                layerSubmit.width                         = 1.0f;
                layerSubmit.height                        = 1.0f;
                layerSubmit.header.colorScaleX            = 1.0f;
                layerSubmit.header.colorScaleY            = 1.0f;
                layerSubmit.header.colorScaleZ            = 1.0f;
                layerSubmit.header.colorScaleW            = 1.0f;
                layerSubmit.header.headPose.orientation.x = 0;
                layerSubmit.header.headPose.orientation.y = 0;
                layerSubmit.header.headPose.orientation.z = 0;
                layerSubmit.header.headPose.orientation.w = 1;
                PXR_Plugin.Render.UPxr_SubmitLayerQuad(layerSubmit);
            }
        }
コード例 #2
0
        private void OnPostRenderCallBack(Camera cam)
        {
            if (cam.tag != Camera.main.tag || cam.stereoActiveEye == Camera.MonoOrStereoscopicEye.Right)
            {
                return;
            }

            int boundaryState = PXR_Plugin.Boundary.UPxr_GetSeeThroughState();

            if (PXR_OverLay.Instances.Count > 0 && boundaryState != 2)
            {
                PXR_OverLay.Instances.Sort();
                foreach (var compositeLayer in PXR_OverLay.Instances)
                {
                    compositeLayer.UpdateCoords();
                    if (!compositeLayer.isActiveAndEnabled)
                    {
                        continue;
                    }
                    if (compositeLayer.layerTextures[0] == null && compositeLayer.layerTextures[1] == null && !compositeLayer.isExternalAndroidSurface)
                    {
                        continue;
                    }
                    if (compositeLayer.layerTransform != null && !compositeLayer.layerTransform.gameObject.activeSelf)
                    {
                        continue;
                    }


                    Vector4 colorScale   = compositeLayer.GetLayerColorScale();
                    Vector4 colorBias    = compositeLayer.GetLayerColorOffset();
                    bool    isHeadLocked = false;
                    if (compositeLayer.layerTransform != null && compositeLayer.layerTransform.parent == transform)
                    {
                        isHeadLocked = true;
                    }
                    if (!compositeLayer.isExternalAndroidSurface && !compositeLayer.CopyRT())
                    {
                        return;
                    }

                    if (compositeLayer.overlayShape == PXR_OverLay.OverlayShape.Quad)
                    {
                        PxrLayerQuad layerSubmit = new PxrLayerQuad();
                        layerSubmit.header.layerId                = compositeLayer.layerIndex;
                        layerSubmit.header.colorScaleX            = colorScale.x;
                        layerSubmit.header.colorScaleY            = colorScale.y;
                        layerSubmit.header.colorScaleZ            = colorScale.z;
                        layerSubmit.header.colorScaleW            = colorScale.w;
                        layerSubmit.header.colorBiasX             = colorBias.x;
                        layerSubmit.header.colorBiasY             = colorBias.y;
                        layerSubmit.header.colorBiasZ             = colorBias.z;
                        layerSubmit.header.colorBiasW             = colorBias.w;
                        layerSubmit.header.compositionDepth       = compositeLayer.layerDepth;
                        layerSubmit.header.headPose.orientation.x = compositeLayer.cameraRotations[0].x;
                        layerSubmit.header.headPose.orientation.y = compositeLayer.cameraRotations[0].y;
                        layerSubmit.header.headPose.orientation.z = -compositeLayer.cameraRotations[0].z;
                        layerSubmit.header.headPose.orientation.w = -compositeLayer.cameraRotations[0].w;
                        layerSubmit.header.headPose.position.x    = (compositeLayer.cameraTranslations[0].x + compositeLayer.cameraTranslations[1].x) / 2;
                        layerSubmit.header.headPose.position.y    = (compositeLayer.cameraTranslations[0].y + compositeLayer.cameraTranslations[1].y) / 2;
                        layerSubmit.header.headPose.position.z    = -(compositeLayer.cameraTranslations[0].z + compositeLayer.cameraTranslations[1].z) / 2;

                        if (isHeadLocked)
                        {
                            layerSubmit.pose.orientation.x = compositeLayer.layerTransform.localRotation.x;
                            layerSubmit.pose.orientation.y = compositeLayer.layerTransform.localRotation.y;
                            layerSubmit.pose.orientation.z = -compositeLayer.layerTransform.localRotation.z;
                            layerSubmit.pose.orientation.w = -compositeLayer.layerTransform.localRotation.w;
                            layerSubmit.pose.position.x    = compositeLayer.layerTransform.localPosition.x;
                            layerSubmit.pose.position.y    = compositeLayer.layerTransform.localPosition.y;
                            layerSubmit.pose.position.z    = -compositeLayer.layerTransform.localPosition.z;

                            layerSubmit.header.layerFlags = (UInt32)(
                                PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace |
                                PxrLayerSubmitFlags.PxrLayerFlagHeadLocked);
                        }
                        else
                        {
                            layerSubmit.pose.orientation.x = compositeLayer.modelRotations[0].x;
                            layerSubmit.pose.orientation.y = compositeLayer.modelRotations[0].y;
                            layerSubmit.pose.orientation.z = -compositeLayer.modelRotations[0].z;
                            layerSubmit.pose.orientation.w = -compositeLayer.modelRotations[0].w;
                            layerSubmit.pose.position.x    = compositeLayer.modelTranslations[0].x;
                            layerSubmit.pose.position.y    = compositeLayer.modelTranslations[0].y;
                            layerSubmit.pose.position.z    = -compositeLayer.modelTranslations[0].z;

                            layerSubmit.header.layerFlags = (UInt32)(
                                PxrLayerSubmitFlags.PxrLayerFlagUseExternalHeadPose |
                                PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace);
                        }

                        layerSubmit.width  = compositeLayer.modelScales[0].x;
                        layerSubmit.height = compositeLayer.modelScales[0].y;

                        PXR_Plugin.Render.UPxr_SubmitLayerQuad(layerSubmit);
                    }
                    else if (compositeLayer.overlayShape == PXR_OverLay.OverlayShape.Cylinder)
                    {
                        PxrLayerCylinder layerSubmit = new PxrLayerCylinder();
                        layerSubmit.header.layerId                = compositeLayer.layerIndex;
                        layerSubmit.header.colorScaleX            = colorScale.x;
                        layerSubmit.header.colorScaleY            = colorScale.y;
                        layerSubmit.header.colorScaleZ            = colorScale.z;
                        layerSubmit.header.colorScaleW            = colorScale.w;
                        layerSubmit.header.colorBiasX             = colorBias.x;
                        layerSubmit.header.colorBiasY             = colorBias.y;
                        layerSubmit.header.colorBiasZ             = colorBias.z;
                        layerSubmit.header.colorBiasW             = colorBias.w;
                        layerSubmit.header.compositionDepth       = compositeLayer.layerDepth;
                        layerSubmit.header.headPose.orientation.x = compositeLayer.cameraRotations[0].x;
                        layerSubmit.header.headPose.orientation.y = compositeLayer.cameraRotations[0].y;
                        layerSubmit.header.headPose.orientation.z = -compositeLayer.cameraRotations[0].z;
                        layerSubmit.header.headPose.orientation.w = -compositeLayer.cameraRotations[0].w;
                        layerSubmit.header.headPose.position.x    = (compositeLayer.cameraTranslations[0].x + compositeLayer.cameraTranslations[1].x) / 2;
                        layerSubmit.header.headPose.position.y    = (compositeLayer.cameraTranslations[0].y + compositeLayer.cameraTranslations[1].y) / 2;
                        layerSubmit.header.headPose.position.z    = -(compositeLayer.cameraTranslations[0].z + compositeLayer.cameraTranslations[1].z) / 2;

                        if (isHeadLocked)
                        {
                            layerSubmit.pose.orientation.x = compositeLayer.layerTransform.localRotation.x;
                            layerSubmit.pose.orientation.y = compositeLayer.layerTransform.localRotation.y;
                            layerSubmit.pose.orientation.z = -compositeLayer.layerTransform.localRotation.z;
                            layerSubmit.pose.orientation.w = -compositeLayer.layerTransform.localRotation.w;
                            layerSubmit.pose.position.x    = compositeLayer.layerTransform.localPosition.x;
                            layerSubmit.pose.position.y    = compositeLayer.layerTransform.localPosition.y;
                            layerSubmit.pose.position.z    = -compositeLayer.layerTransform.localPosition.z;

                            layerSubmit.header.layerFlags = (UInt32)(
                                PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace |
                                PxrLayerSubmitFlags.PxrLayerFlagHeadLocked);
                        }
                        else
                        {
                            layerSubmit.pose.orientation.x = compositeLayer.modelRotations[0].x;
                            layerSubmit.pose.orientation.y = compositeLayer.modelRotations[0].y;
                            layerSubmit.pose.orientation.z = -compositeLayer.modelRotations[0].z;
                            layerSubmit.pose.orientation.w = -compositeLayer.modelRotations[0].w;
                            layerSubmit.pose.position.x    = compositeLayer.modelTranslations[0].x;
                            layerSubmit.pose.position.y    = compositeLayer.modelTranslations[0].y;
                            layerSubmit.pose.position.z    = -compositeLayer.modelTranslations[0].z;

                            layerSubmit.header.layerFlags = (UInt32)(
                                PxrLayerSubmitFlags.PxrLayerFlagUseExternalHeadPose |
                                PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace);
                        }

                        if (compositeLayer.modelScales[0].z != 0)
                        {
                            layerSubmit.centralAngle = compositeLayer.modelScales[0].x / compositeLayer.modelScales[0].z;
                        }
                        else
                        {
                            Debug.LogError("PXRLog scale.z is 0");
                        }
                        layerSubmit.height = compositeLayer.modelScales[0].y;
                        layerSubmit.radius = compositeLayer.modelScales[0].z;

                        PXR_Plugin.Render.UPxr_SubmitLayerCylinder(layerSubmit);
                    }
                    else if (compositeLayer.overlayShape == PXR_OverLay.OverlayShape.Equirect)
                    {
                        PxrLayerEquirect layerSubmit = new PxrLayerEquirect();
                        layerSubmit.header.layerId    = compositeLayer.layerIndex;
                        layerSubmit.header.layerFlags = (UInt32)(
                            PxrLayerSubmitFlags.PxrLayerFlagUseExternalHeadPose |
                            PxrLayerSubmitFlags.PxrLayerFlagLayerPoseNotInTrackingSpace);
                        layerSubmit.header.colorScaleX            = colorScale.x;
                        layerSubmit.header.colorScaleY            = colorScale.y;
                        layerSubmit.header.colorScaleZ            = colorScale.z;
                        layerSubmit.header.colorScaleW            = colorScale.w;
                        layerSubmit.header.colorBiasX             = colorBias.x;
                        layerSubmit.header.colorBiasY             = colorBias.y;
                        layerSubmit.header.colorBiasZ             = colorBias.z;
                        layerSubmit.header.colorBiasW             = colorBias.w;
                        layerSubmit.header.compositionDepth       = compositeLayer.layerDepth;
                        layerSubmit.header.headPose.orientation.x = compositeLayer.cameraRotations[0].x;
                        layerSubmit.header.headPose.orientation.y = compositeLayer.cameraRotations[0].y;
                        layerSubmit.header.headPose.orientation.z = -compositeLayer.cameraRotations[0].z;
                        layerSubmit.header.headPose.orientation.w = -compositeLayer.cameraRotations[0].w;
                        layerSubmit.header.headPose.position.x    = (compositeLayer.cameraTranslations[0].x + compositeLayer.cameraTranslations[1].x) / 2;
                        layerSubmit.header.headPose.position.y    = (compositeLayer.cameraTranslations[0].y + compositeLayer.cameraTranslations[1].y) / 2;
                        layerSubmit.header.headPose.position.z    = -(compositeLayer.cameraTranslations[0].z + compositeLayer.cameraTranslations[1].z) / 2;

                        layerSubmit.pose.orientation.x = compositeLayer.modelRotations[0].x;
                        layerSubmit.pose.orientation.y = compositeLayer.modelRotations[0].y;
                        layerSubmit.pose.orientation.z = -compositeLayer.modelRotations[0].z;
                        layerSubmit.pose.orientation.w = -compositeLayer.modelRotations[0].w;
                        layerSubmit.pose.position.x    = compositeLayer.modelTranslations[0].x;
                        layerSubmit.pose.position.y    = compositeLayer.modelTranslations[0].y;
                        layerSubmit.pose.position.z    = -compositeLayer.modelTranslations[0].z;

                        layerSubmit.centralHorizontalAngle = compositeLayer.modelScales[0].x;
                        layerSubmit.upperVerticalAngle     = compositeLayer.modelScales[0].y / 2;
                        layerSubmit.lowerVerticalAngle     = -compositeLayer.modelScales[0].y / 2;
                        layerSubmit.radius = compositeLayer.modelScales[0].z;

                        PXR_Plugin.Render.UPxr_SubmitLayerEquirect(layerSubmit);
                    }
                }
            }
        }