示例#1
0
        void RenderSteroOculurRift(RenderTargetTexture left, RenderTargetTexture right)
        {
            RenderContext11.SetDisplayRenderTargets();
            RenderContext11.ClearRenderTarget(SharpDX.Color.Black);


            if (ScreenVertexBuffer == null)
            {
                if (ScreenVertexBuffer != null)
                {
                    ScreenVertexBuffer.Dispose();
                    GC.SuppressFinalize(ScreenVertexBuffer);
                    ScreenVertexBuffer = null;
                }

                ScreenVertexBuffer = new TansformedPositionTexturedVertexBuffer11(6, RenderContext11.PrepDevice);

                //PreTransformed
                TansformedPositionTextured[] quad = (TansformedPositionTextured[])ScreenVertexBuffer.Lock(0, 0);


                quad[0].Position = new SharpDX.Vector4(-1, 1, .9f, 1);
                quad[0].Tu = 0;
                quad[0].Tv = 0;

                quad[1].Position = new SharpDX.Vector4(1, 1, .9f, 1);
                quad[1].Tu = 1;
                quad[1].Tv = 0;

                quad[2].Position = new SharpDX.Vector4(-1, -1, .9f, 1);
                quad[2].Tu = 0;
                quad[2].Tv = 1;

                quad[3].Position = new SharpDX.Vector4(-1, -1, .9f, 1);
                quad[3].Tu = 0;
                quad[3].Tv = 1;

                quad[4].Position = new SharpDX.Vector4(1, 1, .9f, 1);
                quad[4].Tu = 1;
                quad[4].Tv = 0;

                quad[5].Position = new SharpDX.Vector4(1, -1, .9f, 1);
                quad[5].Tu = 1;
                quad[5].Tv = 1;

                ScreenVertexBuffer.Unlock();

            }


            RenderContext11.SetVertexBuffer(ScreenVertexBuffer);

            RenderContext11.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

            RenderContext11.BlendMode = BlendMode.Additive;

            RenderContext11.setRasterizerState(TriangleCullMode.Off);


            float lensOffset = riftInfo.LensSeparationDistance * 0.5f;
            float lensShift = riftInfo.HScreenSize * 0.25f - lensOffset;
            float lensViewportShift = 4.0f * lensShift / riftInfo.HScreenSize;
            float XCenterOffset = lensViewportShift;


            // Convert fit value to distortion-centered coordinates before fit radius
            // calculation.
            float stereoAspect = (float)ViewWidth / (float)ViewHeight;
            float dx = -1 - XCenterOffset;
            float dy = 0 / stereoAspect;
            float fitRadius = (float)Math.Sqrt(dx * dx + dy * dy);
            float Scale = DistortionFn(fitRadius) / fitRadius;
            Scale = .5f;
            RiftStereoShader.constants.Scale = new SharpDX.Vector2(Scale * 1f, Scale * stereoAspect);
            RiftStereoShader.constants.ScaleIn = new SharpDX.Vector2(2.0f, 2f * (1f / stereoAspect));
            RiftStereoShader.constants.LensCenterLeft = new SharpDX.Vector2(.5f + (iod / 2), .5f);
            RiftStereoShader.constants.LensCenterRight = new SharpDX.Vector2(.5f - (iod / 2), .5f);
            RiftStereoShader.constants.HmdWarpParam = new SharpDX.Vector4(riftInfo.DistortionK0, riftInfo.DistortionK1, riftInfo.DistortionK2, riftInfo.DistortionK3);
            RiftStereoShader.Use(RenderContext11.devContext);


            RenderContext11.devContext.PixelShader.SetShaderResource(0, left.RenderTexture.ResourceView);
            RenderContext11.devContext.PixelShader.SetShaderResource(1, right.RenderTexture.ResourceView);


            RenderContext11.devContext.Draw(ScreenVertexBuffer.Count, 0);

            RenderContext11.BlendMode = BlendMode.Alpha;

            PresentFrame11(false);
        }
示例#2
0
        void RenderSteroPairAnaglyph(RenderTargetTexture left, RenderTargetTexture right)
        {

            RenderContext11.SetDisplayRenderTargets();
            RenderContext11.ClearRenderTarget(SharpDX.Color.Black);


            if (ScreenVertexBuffer == null)
            {
                if (ScreenVertexBuffer != null)
                {
                    ScreenVertexBuffer.Dispose();
                    GC.SuppressFinalize(ScreenVertexBuffer);
                    ScreenVertexBuffer = null;
                }

                ScreenVertexBuffer = new TansformedPositionTexturedVertexBuffer11(6, RenderContext11.PrepDevice);

                //PreTransformed
                TansformedPositionTextured[] quad = (TansformedPositionTextured[])ScreenVertexBuffer.Lock(0, 0);


                quad[0].Position = new SharpDX.Vector4(-1, 1, .9f, 1);
                quad[0].Tu = 0;
                quad[0].Tv = 0;

                quad[1].Position = new SharpDX.Vector4(1, 1, .9f, 1);
                quad[1].Tu = 1;
                quad[1].Tv = 0;

                quad[2].Position = new SharpDX.Vector4(-1, -1, .9f, 1);
                quad[2].Tu = 0;
                quad[2].Tv = 1;

                quad[3].Position = new SharpDX.Vector4(-1, -1, .9f, 1);
                quad[3].Tu = 0;
                quad[3].Tv = 1;

                quad[4].Position = new SharpDX.Vector4(1, 1, .9f, 1);
                quad[4].Tu = 1;
                quad[4].Tv = 0;

                quad[5].Position = new SharpDX.Vector4(1, -1, .9f, 1);
                quad[5].Tu = 1;
                quad[5].Tv = 1;

                ScreenVertexBuffer.Unlock();

            }
            Color leftEyeColor = Color.Red;
            Color rightEyeColor = Color.Cyan;



            if (StereoMode == StereoModes.AnaglyphYellowBlue)
            {
                leftEyeColor = Color.Yellow;
                rightEyeColor = Color.Blue;

            }

            if (StereoMode == StereoModes.AnaglyphMagentaGreen)
            {
                leftEyeColor = Color.Yellow;
                rightEyeColor = Color.Blue;

            }


            RenderContext11.SetVertexBuffer(ScreenVertexBuffer);

            RenderContext11.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

            RenderContext11.BlendMode = BlendMode.Additive;

            RenderContext11.setRasterizerState(TriangleCullMode.Off);


            //Left Eye

            AnaglyphStereoShader.Color = new SharpDX.Color4(leftEyeColor.R / 255f, leftEyeColor.G / 255f, leftEyeColor.B / 255f, leftEyeColor.A / 255f);
            AnaglyphStereoShader.Use(RenderContext11.devContext);


            RenderContext11.devContext.PixelShader.SetShaderResource(0, leftEye.RenderTexture.ResourceView);


            RenderContext11.devContext.Draw(ScreenVertexBuffer.Count, 0);

            //Right Eye
            RenderContext11.devContext.PixelShader.SetShaderResource(0, rightEye.RenderTexture.ResourceView);
            AnaglyphStereoShader.Color = new SharpDX.Color4(rightEyeColor.R / 255f, rightEyeColor.G / 255f, rightEyeColor.B / 255f, rightEyeColor.A / 255f);
            AnaglyphStereoShader.Use(RenderContext11.devContext);
            RenderContext11.devContext.Draw(ScreenVertexBuffer.Count, 0);

            RenderContext11.BlendMode = BlendMode.Alpha;

            PresentFrame11(false);
        }
示例#3
0
        void RenderSteroPairSideBySide(RenderTargetTexture left, RenderTargetTexture right)
        {
            RenderContext11.SetDisplayRenderTargets();
            RenderContext11.ClearRenderTarget(SharpDX.Color.Black);


            if (ScreenVertexBuffer == null)
            {
                if (ScreenVertexBuffer != null)
                {
                    ScreenVertexBuffer.Dispose();
                    GC.SuppressFinalize(ScreenVertexBuffer);
                    ScreenVertexBuffer = null;
                }

                ScreenVertexBuffer = new TansformedPositionTexturedVertexBuffer11(6, RenderContext11.PrepDevice);

                //PreTransformed
                TansformedPositionTextured[] quad = (TansformedPositionTextured[])ScreenVertexBuffer.Lock(0, 0);


                quad[0].Position = new SharpDX.Vector4(-1, 1, .9f, 1);
                quad[0].Tu = 0;
                quad[0].Tv = 0;

                quad[1].Position = new SharpDX.Vector4(1, 1, .9f, 1);
                quad[1].Tu = 1;
                quad[1].Tv = 0;

                quad[2].Position = new SharpDX.Vector4(-1, -1, .9f, 1);
                quad[2].Tu = 0;
                quad[2].Tv = 1;

                quad[3].Position = new SharpDX.Vector4(-1, -1, .9f, 1);
                quad[3].Tu = 0;
                quad[3].Tv = 1;

                quad[4].Position = new SharpDX.Vector4(1, 1, .9f, 1);
                quad[4].Tu = 1;
                quad[4].Tv = 0;

                quad[5].Position = new SharpDX.Vector4(1, -1, .9f, 1);
                quad[5].Tu = 1;
                quad[5].Tv = 1;

                ScreenVertexBuffer.Unlock();

            }


            RenderContext11.SetVertexBuffer(ScreenVertexBuffer);

            RenderContext11.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

            RenderContext11.BlendMode = BlendMode.Additive;

            RenderContext11.setRasterizerState(TriangleCullMode.Off);

            SideBySideStereoShader.Use(RenderContext11.devContext);


            RenderContext11.devContext.PixelShader.SetShaderResource(0, right.RenderTexture.ResourceView);
            RenderContext11.devContext.PixelShader.SetShaderResource(1, left.RenderTexture.ResourceView);


            RenderContext11.devContext.Draw(ScreenVertexBuffer.Count, 0);

            RenderContext11.BlendMode = BlendMode.Alpha;

            PresentFrame11(false);
        }
示例#4
0
        void RenderSteroPairInterline(RenderTargetTexture left, RenderTargetTexture right)
        {
            if (renderWindow.ClientSize.Height != RenderContext11.DisplayViewport.Height ||
                renderWindow.ClientSize.Width != RenderContext11.DisplayViewport.Width)
            {
                RenderContext11.Resize(renderWindow);
            }

            RenderContext11.SetDisplayRenderTargets();
            RenderContext11.ClearRenderTarget(SharpDX.Color.Black);


            if (ScreenVertexBuffer == null)
            {
                if (ScreenVertexBuffer != null)
                {
                    ScreenVertexBuffer.Dispose();
                    GC.SuppressFinalize(ScreenVertexBuffer);
                    ScreenVertexBuffer = null;
                }

                ScreenVertexBuffer = new TansformedPositionTexturedVertexBuffer11(6, RenderContext11.PrepDevice);

                //PreTransformed
                var quad = (TansformedPositionTextured[])ScreenVertexBuffer.Lock(0, 0);


                quad[0].Position = new Vector4(-1, 1, .9f, 1);
                quad[0].Tu = 0;
                quad[0].Tv = 0;

                quad[1].Position = new Vector4(1, 1, .9f, 1);
                quad[1].Tu = 1;
                quad[1].Tv = 0;

                quad[2].Position = new Vector4(-1, -1, .9f, 1);
                quad[2].Tu = 0;
                quad[2].Tv = 1;

                quad[3].Position = new Vector4(-1, -1, .9f, 1);
                quad[3].Tu = 0;
                quad[3].Tv = 1;

                quad[4].Position = new Vector4(1, 1, .9f, 1);
                quad[4].Tu = 1;
                quad[4].Tv = 0;

                quad[5].Position = new Vector4(1, -1, .9f, 1);
                quad[5].Tu = 1;
                quad[5].Tv = 1;

                ScreenVertexBuffer.Unlock();

            }


            RenderContext11.SetVertexBuffer(ScreenVertexBuffer);

            RenderContext11.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;

            RenderContext11.BlendMode = BlendMode.Additive;

            RenderContext11.setRasterizerState(TriangleCullMode.Off);


            InterlineStereoShader.Lines = renderWindow.Height;
            InterlineStereoShader.Odd = StereoMode == StereoModes.InterlineOdd ? 1.0f : 0.0f;

            InterlineStereoShader.Use(RenderContext11.devContext);

            RenderContext11.devContext.PixelShader.SetShaderResource(0, right.RenderTexture.ResourceView);
            RenderContext11.devContext.PixelShader.SetShaderResource(1, left.RenderTexture.ResourceView);

            RenderContext11.devContext.Draw(ScreenVertexBuffer.Count, 0);

            RenderContext11.BlendMode = BlendMode.Alpha;

            PresentFrame11(false);
        }