示例#1
0
 public void SetDevice(GraphicsDevice device, Effect effect)
 {
     XDevice = device;
     XEffect = effect;
     if (DataTexture != null)
     {
         DataTexture.Dispose();
         DataTexture = null;
     }
     RefreshTexture();
     Rect = new Microsoft.Xna.Framework.Rectangle(0, 0, XDevice.PresentationParameters.BackBufferWidth, XDevice.PresentationParameters.BackBufferHeight);
     XPlane.SetDevice(XDevice);
 }
示例#2
0
        public virtual void CreateDevice(Control control)
        {
            //Device
            XDevice = new GraphicsDevice(
                GraphicsAdapter.DefaultAdapter,
                GraphicsProfile.HiDef,
                new PresentationParameters()
            {
                IsFullScreen         = false,
                DeviceWindowHandle   = control.Handle,
                PresentationInterval = PresentInterval.One,
                BackBufferWidth      = control.Width,
                BackBufferHeight     = control.Height,
                DepthStencilFormat   = DepthFormat.Depth16,
                RenderTargetUsage    = RenderTargetUsage.PreserveContents
            });
            XDevice.RasterizerState   = RasterizerState.CullNone;
            XDevice.DepthStencilState = DepthStencilState.Default;
            InitGraphicsDeviceService();
            XContent = new ContentManager(this);
            XEffect  = XContent.Load <Effect>("Content/RotatingScannerEffects");

            //Textures
            TRawDepth        = new Texture2D(XDevice, Context.DepthWidth, Context.DepthHeight, false, SurfaceFormat.Bgra4444);
            TDepth           = new Texture2D(XDevice, Context.DepthWidth, Context.DepthHeight, false, SurfaceFormat.Single);
            TDepthCorrection = new Texture2D(XDevice, Context.DepthWidth, Context.DepthHeight, false, SurfaceFormat.Vector2);
            TDepthCorrection.SetData <float>(Context.DepthCorrection);

            //Render targets
            SingleTargetA  = new RenderTarget2D(XDevice, Context.DepthWidth, Context.DepthHeight, false, SurfaceFormat.Single, DepthFormat.Depth16);
            SingleTargetB  = new RenderTarget2D(XDevice, Context.DepthWidth, Context.DepthHeight, false, SurfaceFormat.Single, DepthFormat.Depth16);
            Vector2TargetA = new RenderTarget2D(XDevice, Context.DepthWidth, Context.DepthHeight, false, SurfaceFormat.Vector2, DepthFormat.Depth16);
            Vector2TargetB = new RenderTarget2D(XDevice, Context.DepthWidth, Context.DepthHeight, false, SurfaceFormat.Vector2, DepthFormat.Depth16);
            Vector4Target  = new RenderTarget2D(XDevice, Context.DepthWidth, Context.DepthHeight, false, SurfaceFormat.Vector4, DepthFormat.Depth16);

            //Samplers
            MainSampler            = XEffect.Parameters["MainTexture"];
            DepthSampler           = XEffect.Parameters["DepthTexture"];
            DepthCorrectionSampler = XEffect.Parameters["DepthCorrectionTexture"];
            DepthSamplerA          = XEffect.Parameters["DepthTextureA"];
            DepthSamplerB          = XEffect.Parameters["DepthTextureB"];

            //Transforms
            ReprojectionTransform = XEffect.Parameters["ReprojectionTransform"];
            SpaceTransform        = XEffect.Parameters["SpaceTransform"];
            FusionTransform       = XEffect.Parameters["FusionTransform"];

            //Parameters
            TriangleRemoveLimit = XEffect.Parameters["TriangleRemoveLimit"];
            SideSelector        = XEffect.Parameters["SideSelector"];
            SplitPlaneVector    = XEffect.Parameters["SplitPlaneVector"];
            MinY          = XEffect.Parameters["ProjYMin"];
            MaxHeight     = XEffect.Parameters["ProjHeightMax"];
            DepthZLimit   = XEffect.Parameters["DepthLimitZ"];
            ShadingColor  = XEffect.Parameters["ShadingColor"];
            MaxClipRadius = XEffect.Parameters["ClipRadiusMax"];
            MinClipRadius = XEffect.Parameters["ClipRadiusMin"];
            ClipOn        = XEffect.Parameters["ClipOn"];
            MinAvgCount   = XEffect.Parameters["DepthAvgCountMin"];
            DepthAvgLimit = XEffect.Parameters["DepthAvgLimit"];
            MinClipY      = XEffect.Parameters["ClipYMin"];

            //Techniques
            DepthAntiDistortTechnique        = XEffect.Techniques["DepthAntiDistort"];
            PerspectiveReprojectionTechnique = XEffect.Techniques["PerspectiveReprojection"];
            DepthVisualizationTechnique      = XEffect.Techniques["DepthVisualization"];
            SumTechnique = XEffect.Techniques["Sum"];
            AvgTechnique = XEffect.Techniques["Avg"];
            SignedDepthVisualizationTechnique = XEffect.Techniques["SignedDepthVisualization"];
            VGaussTechnique = XEffect.Techniques["DepthVGauss"];
            HGaussTechnique = XEffect.Techniques["DepthHGauss"];

            //Constants
            XEffect.Parameters["DepthCorrectionTextureSize"].SetValue(new Vector2(Context.DepthWidth, Context.DepthHeight));
            XEffect.Parameters["DepthInverseIntrinsics"].SetValue(Context.DepthInverseIntrinsics);
            XEffect.Parameters["NaN"].SetValue(float.NaN);
            XEffect.SetGaussCoeffs(Context.DepthWidth, Context.DepthHeight, 9, 1, 1);

            //Models
            MiniPlane.SetDevice(XDevice);
            MaxiPlane.SetDevice(XDevice);

            //Viewports
            MainViewport  = new Viewport(0, 0, XDevice.PresentationParameters.BackBufferWidth, XDevice.PresentationParameters.BackBufferHeight);
            LeftViewport  = new Viewport(0, 0, XDevice.PresentationParameters.BackBufferWidth / 2, XDevice.PresentationParameters.BackBufferHeight);
            RightViewport = new Viewport(XDevice.PresentationParameters.BackBufferWidth / 2, 0, XDevice.PresentationParameters.BackBufferWidth / 2, XDevice.PresentationParameters.BackBufferHeight);
            Viewports     = new Viewport[] { LeftViewport, RightViewport, MainViewport };
        }