Пример #1
0
        /// <summary>
        /// OVRRender renderer
        /// </summary>
        protected override void Render()
        {
            int currentIndex = 0;

            if (this.IsConnected)
            {
                OVR.FrameTiming   frameTiming   = this.Hmd.GetFrameTiming(0);
                OVR.TrackingState trackingState = this.Hmd.GetTrackingState(frameTiming.DisplayMidpointSeconds);

                // Calculate the position and orientation of each eye.
                this.Oculus.CalcEyePoses(trackingState.HeadPose.ThePose, this.hmdToEyeViewOffsets, ref this.oculusEyePoses);

                trackingState.CameraPose.Position.ToVector3(out this.trackerCameraPose.Position);
                trackingState.CameraPose.Orientation.ToQuaternion(out this.trackerCameraPose.Orientation);

                currentIndex = this.eyeSwapTextureSet.CurrentIndex++;

                for (int eyeIndex = 0; eyeIndex < 2; eyeIndex++)
                {
                    this.oculusEyePoses[eyeIndex].Position.ToVector3(out this.eyePoses[eyeIndex].Position);
                    this.oculusEyePoses[eyeIndex].Orientation.ToQuaternion(out this.eyePoses[eyeIndex].Orientation);
                    this.eyeTextures[eyeIndex].RenderTarget = (this.msaaSampleCount > 1) ? this.msaaRenderTarget : this.swapRenderTargets[currentIndex];

                    // Get eye projection
                    OVR.ovrMatrix4f_Projection(this.eyeTextures[eyeIndex].FieldOfView, this.eyeTextures[eyeIndex].NearPlane, this.eyeTextures[eyeIndex].FarPlane, OVR.ProjectionModifier.RightHanded).ToMatrix(out this.eyePoses[eyeIndex].Projection);

                    this.layerEyeFov.RenderPose[eyeIndex] = this.oculusEyePoses[eyeIndex];
                }

                // Calc central position
                Vector3.Lerp(ref this.eyePoses[0].Position, ref this.eyePoses[1].Position, 0.5f, out this.eyePoses[2].Position);
                Quaternion.Lerp(ref this.eyePoses[0].Orientation, ref this.eyePoses[1].Orientation, 0.5f, out this.eyePoses[2].Orientation);
            }

            base.Render();

            if (this.IsConnected)
            {
                if (this.msaaSampleCount > 1)
                {
                    var rtManager = this.adapter.Graphics.RenderTargetManager as RenderTargetManager;
                    var dxRt      = rtManager.TargetFromHandle <DXRenderTarget>(this.msaaRenderTarget.TextureHandle);
                    var dxSwapRt  = rtManager.TargetFromHandle <DXRenderTarget>(this.swapRenderTargets[currentIndex].TextureHandle);

                    this.context.ResolveSubresource(dxRt.Target, 0, dxSwapRt.Target, 0, Format.R8G8B8A8_UNorm_SRgb);
                }

                // Submit frame to HMD
                this.Hmd.SubmitFrame(0, this.ovrLayers);

                if (this.ShowHMDMirrorTexture)
                {
                    // Show mirror texture into BackBuffer
                    this.device.ImmediateContext.CopyResource(this.mirrorTexture, this.backBuffer);
                }
            }
        }