Пример #1
0
    private static ResourceRef <Material> CreateGaussBlurMaterial(RenderingDevice device,
                                                                  RenderTargetTexture texture,
                                                                  bool horizontal)
    {
        var samplerState = new SamplerSpec();

        samplerState.addressU  = TextureAddress.Clamp;
        samplerState.addressV  = TextureAddress.Clamp;
        samplerState.magFilter = TextureFilterType.Linear;
        samplerState.minFilter = TextureFilterType.Linear;
        samplerState.mipFilter = TextureFilterType.Linear;
        var rasterizerState = new RasterizerSpec();

        rasterizerState.cullMode = CullMode.None;
        var depthStencilState = new DepthStencilSpec();

        depthStencilState.depthEnable = false;

        var vs         = device.GetShaders().LoadVertexShader("gaussian_blur_vs");
        var horDefines = new Dictionary <string, string>();

        if (horizontal)
        {
            horDefines["HOR"] = "1";
        }

        var ps = device.GetShaders().LoadPixelShader("gaussian_blur_ps", horDefines);

        var samplers = new MaterialSamplerSpec[]
        {
            new (new ResourceRef <ITexture>(texture), samplerState)
        };

        return(device.CreateMaterial(null, depthStencilState, rasterizerState, samplers, vs, ps).Ref());
    }
Пример #2
0
 /// <summary>
 /// </summary>
 /// <param name="scene">
 /// </param>
 /// <param name="name">
 /// </param>
 /// <param name="size">
 /// </param>
 /// <param name="renderList">
 /// </param>
 /// <param name="beforeRender">
 /// </param>
 /// <param name="afterRender">
 /// </param>
 public PostProcessRenderPass(Scene scene, string name, Size size, Array <AbstractMesh> renderList, System.Action beforeRender, System.Action afterRender)
 {
     this._name          = name;
     this._renderTexture = new RenderTargetTexture(name, size, scene);
     this.setRenderList(renderList);
     this._renderTexture.onBeforeRender = beforeRender;
     this._renderTexture.onAfterRender  = afterRender;
     this._scene = scene;
 }
 public void Shutdown()
 {
     ShaderResourceView?.Dispose();
     ShaderResourceView = null;
     RenderTargetView?.Dispose();
     RenderTargetView = null;
     RenderTargetTexture?.Dispose();
     RenderTargetTexture = null;
 }
Пример #4
0
 public void Shutdown()
 {
     DepthStencilView?.Dispose();
     DepthStencilView = null;
     DepthStencilBuffer?.Dispose();
     DepthStencilBuffer = null;
     ShaderResourceView?.Dispose();
     ShaderResourceView = null;
     RenderTargetView?.Dispose();
     RenderTargetView = null;
     RenderTargetTexture?.Dispose();
     RenderTargetTexture = null;
 }
Пример #5
0
        public void Shutdown()
        {
            if (ShaderResourceView != null)
            {
                ShaderResourceView.Dispose();
                ShaderResourceView = null;
            }

            if (RenderTargetView != null)
            {
                RenderTargetView.Dispose();
                RenderTargetView = null;
            }

            if (RenderTargetTexture != null)
            {
                RenderTargetTexture.Dispose();
                RenderTargetTexture = null;
            }
        }
Пример #6
0
        private void RenderFrame(RenderTargetTexture targetTexture, DepthBuffer depthBuffer, RenderTypes renderType)
        {
            CurrentRenderType = renderType;

            bool offscreenRender = targetTexture != null;

            Tile.deepestLevel = 0;
 
            try
            {
                if (offscreenRender)
                {
                    RenderContext11.SetOffscreenRenderTargets(targetTexture, depthBuffer);
                }
                else
                {
                    RenderContext11.SetDisplayRenderTargets();
                }

                //Clear the backbuffer to a black color 

                RenderContext11.ClearRenderTarget(new SharpDX.Color(SkyColor.R, SkyColor.G, SkyColor.B, SkyColor.A));



                RenderContext11.RenderType = CurrentImageSet.DataSetType;

                RenderContext11.BlendMode = BlendMode.Alpha;
                if (CurrentImageSet.DataSetType == ImageSetType.Sandbox)
                {
                    // Start Sandbox mode
                    RenderContext11.SunPosition = LayerManager.GetPrimarySandboxLight();
                    RenderContext11.SunlightColor = LayerManager.GetPrimarySandboxLightColor();

                    RenderContext11.ReflectedLightColor = Color.Black;
                    RenderContext11.HemisphereLightColor = Color.Black;

                    SkyColor = Color.Black;
                    if ((int)SolarSystemTrack < (int)SolarSystemObjects.Custom)
                    {
                        double radius = Planets.GetAdjustedPlanetRadius((int)SolarSystemTrack);
                        double distance = SolarSystemCameraDistance;
                        double camAngle = fovLocal;
                        double distrad = distance / (radius * Math.Tan(.5 * camAngle));
                        if (distrad < 1)
                        {
                            planetFovWidth = Math.Asin(distrad);
                        }
                        else
                        {
                            planetFovWidth = Math.PI;
                        }
                    }
                    else
                    {
                        planetFovWidth = Math.PI;
                    }


                    SetupMatricesSolarSystem11(false, renderType);

 
                    Matrix3d matLocal = RenderContext11.World;
                    matLocal.Multiply(Matrix3d.Translation(-viewCamera.ViewTarget));
                    RenderContext11.World = matLocal;

                    RenderContext11.WorldBase = RenderContext11.World;
                    RenderContext11.WorldBaseNonRotating = RenderContext11.World;
                    RenderContext11.NominalRadius = 1;

                    Earth3d.MainWindow.MakeFrustum();

                    double zoom = Earth3d.MainWindow.ZoomFactor;

                    LayerManager.Draw(RenderContext11, 1.0f, false, "Sandbox", true, false);

                    if ((SolarSystemMode) && label != null && !TourPlayer.Playing)
                    {
                        label.Draw(RenderContext11, true);
                    }

                    RenderContext11.setRasterizerState(TriangleCullMode.Off);
                    // end Sandbox Mode
                }
                else if (CurrentImageSet.DataSetType == ImageSetType.SolarSystem)
                {



                    {
                        SkyColor = Color.Black;
                        if ((int)SolarSystemTrack < (int)SolarSystemObjects.Custom)
                        {
                            double radius = Planets.GetAdjustedPlanetRadius((int)SolarSystemTrack);
                            double distance = SolarSystemCameraDistance;
                            double camAngle = fovLocal;
                            double distrad = distance / (radius * Math.Tan(.5 * camAngle));
                            if (distrad < 1)
                            {
                                planetFovWidth = Math.Asin(distrad);
                            }
                            else
                            {
                                planetFovWidth = Math.PI;
                            }
                        }
                        else
                        {
                            planetFovWidth = Math.PI;
                        }


                        if (trackingObject == null)
                        {
                            trackingObject = Search.FindCatalogObjectExact("Sun");
                        }

                        SetupMatricesSolarSystem11(true, renderType);



                        float skyOpacity = 1.0f - Planets.CalculateSkyBrightnessFactor(RenderContext11.View, viewCamera.ViewTarget);
                        if (float.IsNaN(skyOpacity))
                        {
                            skyOpacity = 0f;
                        }

                        double zoom = Earth3d.MainWindow.ZoomFactor;
                        float milkyWayBlend = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 8.4)) / 4.2);
                        float milkyWayBlendIn = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 17.9)) / 2.3);


                        if (Properties.Settings.Default.SolarSystemMilkyWay.State)
                        {
                            if (milkyWayBlend < 1) // Solar System mode Milky Way background
                            {
                                if (milkyWayBackground == null)
                                {
                                    milkyWayBackground = GetImagesetByName("Digitized Sky Survey (Color)");
                                }

                                if (milkyWayBackground != null)
                                {
                                    float c = ((1 - milkyWayBlend)) / 4;
                                    Matrix3d matOldMW = RenderContext11.World;
                                    Matrix3d matLocalMW = RenderContext11.World;
                                    matLocalMW.Multiply(Matrix3d.Scaling(100000, 100000, 100000));
                                    matLocalMW.Multiply(Matrix3d.RotationX(-23.5 / 180 * Math.PI));
                                    matLocalMW.Multiply(Matrix3d.RotationY(Math.PI));
                                    matLocalMW.Multiply(Matrix3d.Translation(cameraOffset));
                                    RenderContext11.World = matLocalMW;
                                    RenderContext11.WorldBase = matLocalMW;
                                    Earth3d.MainWindow.MakeFrustum();

                                    RenderContext11.SetupBasicEffect(BasicEffect.TextureColorOpacity, 1, Color.White);
                                    RenderContext11.DepthStencilMode = DepthStencilMode.Off;
                                    DrawTiledSphere(milkyWayBackground, c * Properties.Settings.Default.SolarSystemMilkyWay.Opacity, Color.FromArgb(255, 255, 255, 255));
                                    RenderContext11.World = matOldMW;
                                    RenderContext11.WorldBase = matOldMW;
                                    RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite;
                                }
                            }
                        }

                        // CMB

                        float cmbBlend = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 33)) / 2.3);


                        double cmbLog = Math.Log(zoom);

                        if (Properties.Settings.Default.SolarSystemCMB.State)
                        {
                            if (cmbBlend > 0) // Solar System mode Milky Way background
                            {
                                if (cmbBackground == null)
                                {
                                    cmbBackground = GetImagesetByName("Planck CMB");
                                }

                                if (cmbBackground != null)
                                {
                                    float c = ((cmbBlend)) / 16;
                                    Matrix3d matOldMW = RenderContext11.World;
                                    Matrix3d matLocalMW = RenderContext11.World;
  
                                    matLocalMW.Multiply(Matrix3d.Scaling(2.9090248982E+15, 2.9090248982E+15, 2.9090248982E+15));
                                    matLocalMW.Multiply(Matrix3d.RotationX(-23.5 / 180 * Math.PI));
                                    matLocalMW.Multiply(Matrix3d.RotationY(Math.PI));

                                    RenderContext11.World = matLocalMW;
                                    RenderContext11.WorldBase = matLocalMW;
                                    Earth3d.MainWindow.MakeFrustum();

                                    RenderContext11.SetupBasicEffect(BasicEffect.TextureColorOpacity, 1, Color.White);

                                    RenderContext11.DepthStencilMode = DepthStencilMode.Off;
                                    DrawTiledSphere(cmbBackground, c * Properties.Settings.Default.SolarSystemCMB.Opacity, Color.FromArgb(255, 255, 255, 255));
                                    RenderContext11.World = matOldMW;
                                    RenderContext11.WorldBase = matOldMW;
                                    RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite;
                                }
                            }
                        }




                        {
                            Matrix3d matOld = RenderContext11.World;

                            Matrix3d matLocal = RenderContext11.World;
                            matLocal.Multiply(Matrix3d.Translation(viewCamera.ViewTarget));
                            RenderContext11.World = matLocal;
                            Earth3d.MainWindow.MakeFrustum();

                            if (Properties.Settings.Default.SolarSystemCosmos.State)
                            {
                                RenderContext11.DepthStencilMode = DepthStencilMode.Off;
                                Grids.DrawCosmos3D(RenderContext11, Properties.Settings.Default.SolarSystemCosmos.Opacity * skyOpacity);
                                RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite;
                            }

                            if (true)
                            {
                                RenderContext11.DepthStencilMode = DepthStencilMode.Off;

                                Grids.DrawCustomCosmos3D(RenderContext11, skyOpacity);

                                RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite;
                            }


                            if (Properties.Settings.Default.SolarSystemMilkyWay.State && milkyWayBlendIn > 0)
                            {
                                Grids.DrawGalaxy3D(RenderContext11, Properties.Settings.Default.SolarSystemMilkyWay.Opacity * skyOpacity * milkyWayBlendIn);
                            }


                            if (Properties.Settings.Default.SolarSystemStars.State)
                            {
                                Grids.DrawStars3D(RenderContext11, Properties.Settings.Default.SolarSystemStars.Opacity * skyOpacity);
                            }

                                         
                            LayerManager.Draw(RenderContext11, 1.0f, true, "Sky", true, false);

                            RenderContext11.World = matOld;
                            Earth3d.MainWindow.MakeFrustum();
                        }


                        if (SolarSystemCameraDistance < 15000)
                        {
                            SetupMatricesSolarSystem11(false, renderType);


                            if (Properties.Settings.Default.SolarSystemMinorPlanets.State)
                            {
                                MinorPlanets.DrawMPC3D(RenderContext11, Properties.Settings.Default.SolarSystemMinorPlanets.Opacity, viewCamera.ViewTarget);
                            }

                            Planets.DrawPlanets3D(RenderContext11, Properties.Settings.Default.SolarSystemPlanets.Opacity, viewCamera.ViewTarget);
                        }

                        double p = Math.Log(zoom);
                        double d = (180 / SolarSystemCameraDistance) * 100; 

                        float sunAtDistance = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 7.5)) / 3);

                        if (sunAtDistance > 0 && Settings.Active.SolarSystemPlanets)
                        {
                            Planets.DrawPointPlanet(RenderContext11, new Vector3d(0, 0, 0), (float)d * sunAtDistance, Color.FromArgb(192, 191, 128), false, 1);
                        }

                        if ((SolarSystemMode) && label != null && !TourPlayer.Playing)
                        {
                            label.Draw(RenderContext11, true);
                        }
                    }

                    RenderContext11.setRasterizerState(TriangleCullMode.Off);
                }
                else
                {

                    if (CurrentImageSet.DataSetType == ImageSetType.Panorama || CurrentImageSet.DataSetType == ImageSetType.Sky)
                    {
                        SkyColor = Color.Black;

                        if ((int)renderType < 5)
                        {
                            SetupMatricesSpaceDome(false, renderType);
                        }
                        else
                        {
                            SetupMatricesSpace11(ZoomFactor, renderType);
                        }
                        RenderContext11.DepthStencilMode = DepthStencilMode.Off;
                    }
                    else
                    {

                        if (Settings.DomeView)
                        {
                            SetupMatricesLandDome(renderType);
                        }
                        else
                        {
                            SetupMatricesLand11(renderType);
                        }
                        RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite;
                    }

                    ComputeViewParameters(CurrentImageSet);

                    // Update Context pane
                    CurrentViewCorners = new Coordinates[] 
                    {
                        GetCoordinatesForScreenPoint(0, 0),
                        GetCoordinatesForScreenPoint(ViewWidth, 0),
                        GetCoordinatesForScreenPoint(ViewWidth, renderWindow.ClientRectangle.Height),
                        GetCoordinatesForScreenPoint(0, renderWindow.ClientRectangle.Height) 
                    };

                    Coordinates temp = GetCoordinatesForScreenPoint(ViewWidth / 2, renderWindow.ClientRectangle.Height / 2);

                    if (contextPanel != null && ((int)renderType > 4 || renderType == RenderTypes.DomeFront))
                    {
                        contextPanel.SetViewRect(CurrentViewCorners);
                    }
                    UpdateKmlViewInfo();

                    if (KmlMarkers != null)
                    {
                        KmlMarkers.ClearGroundOverlays();
                    }

                    string referenceFrame = GetCurrentReferenceFrame();


                    if (PlanetLike || Space)
                    {
                        LayerManager.PreDraw(RenderContext11, 1.0f, Space, referenceFrame, true);
                    }

                    if (Properties.Settings.Default.EarthCutawayView.State && !Space && CurrentImageSet.DataSetType == ImageSetType.Earth)
                    {
                        Grids.DrawEarthStructure(RenderContext11, 1f);
                    }

                    RenderContext11.SetupBasicEffect(BasicEffect.TextureColorOpacity, 1, Color.White);

                    if (KmlMarkers != null)
                    {
                        KmlMarkers.SetupGroundOverlays(RenderContext11);
                    }

                    if (PlanetLike)
                    {
                        RenderContext11.setRasterizerState(TriangleCullMode.Off);
                    }

                    // Call DrawTiledSphere instead of PaintLayerFull, because PaintLayerFull
                    // will reset ground layer state
                    DrawTiledSphere(CurrentImageSet, 1.0f, Color.White);


                    if (imageStackVisible)
                    {
                        foreach (ImageSet set in ImageStackList)
                        {
                            PaintLayerFull11(set, StudyOpacity);
                        }
                    }

                    if (studyImageset != null)
                    {
                        if (studyImageset.DataSetType != CurrentImageSet.DataSetType)
                        {
                            StudyImageset = null;
                        }
                        else
                        {
                            PaintLayerFull11(studyImageset, StudyOpacity);
                        }
                    }


                    if (previewImageset != null && PreviewBlend.State)
                    {
                        if (previewImageset.DataSetType != CurrentImageSet.DataSetType)
                        {
                            previewImageset = null;
                        }
                        else
                        {
                            PaintLayerFull11(previewImageset, PreviewBlend.Opacity * 100.0f);
                        }
                    }
                    else
                    {
                        PreviewBlend.State = false;
                        previewImageset = null;
                    }


                    if (Space && (CurrentImageSet.Name == "Plotted Sky"))
                    {

                        Grids.DrawStars(RenderContext11, 1f);
                    }

                    if (Space && Properties.Settings.Default.ShowSolarSystem.State)
                    {
                        Planets.DrawPlanets(RenderContext11, Properties.Settings.Default.ShowSolarSystem.Opacity);
                    }


                    if (PlanetLike || Space)
                    {
                        if (!Space)
                        {
                            //todo fix this for other planets..
                            double angle = Coordinates.MstFromUTC2(SpaceTimeController.Now, 0) / 180.0 * Math.PI;
                            RenderContext11.WorldBaseNonRotating = Matrix3d.RotationY(angle) * RenderContext11.WorldBase;
                            RenderContext11.NominalRadius = CurrentImageSet.MeanRadius;
                        }
                        else
                        {
                            RenderContext11.WorldBaseNonRotating = RenderContext11.World;
                            RenderContext11.NominalRadius = CurrentImageSet.MeanRadius;
                            RenderContext11.DepthStencilMode = DepthStencilMode.Off;
                        }

                        LayerManager.Draw(RenderContext11, 1.0f, Space, referenceFrame, true, Space);
                    }

                    if (Space && !hemisphereView && Settings.Active.LocalHorizonMode && !Settings.DomeView && !ProjectorServer)
                    {
                        Grids.DrawHorizon(RenderContext11, 1f);
                    }

                    if (Settings.Active.ShowClouds && !Space && CurrentImageSet.DataSetType == ImageSetType.Earth)
                    {
                        DrawClouds();
                    }


                    // Draw Field of view indicator

                    if (Settings.Active.ShowFieldOfView)
                    {
                        fovBlend.TargetState = true;
                    }
                    else
                    {
                        fovBlend.TargetState = false;
                    }

                    if (fovBlend.State)
                    {
                        if (fov != null && Space)
                        {
                            fov.Draw3D(RenderContext11, fovBlend.Opacity, RA, Dec);
                        }
                    }

                    if (label != null && !TourPlayer.Playing)
                    {
                        label.Draw(RenderContext11, PlanetLike);
                    }

                    if (ShowKmlMarkers && KmlMarkers != null)
                    {
                        KmlMarkers.DrawLabels(RenderContext11);
                    }



                    // End Planet & space
                }

                if (uiController != null)
                {
                    {
                        uiController.Render(this);
                    }
                }

                if (videoOverlay != null)
                {
                    if ((int)renderType < 5)
                    {
                        SetupMatricesVideoOverlayDome(false, renderType);
                    }
                    else
                    {
                        SetupMatricesVideoOverlay(ZoomFactor);
                    }
                    DepthStencilMode mode = RenderContext11.DepthStencilMode = DepthStencilMode.Off;
                    PaintLayerFull11(videoOverlay, 100f);
                    RenderContext11.DepthStencilMode = mode;
                }

                if (measuringDrag && measureLines != null)
                {
                    measureLines.DrawLines(RenderContext11, 1.0f, Color.Yellow);

                }

                if (Properties.Settings.Default.ShowCrosshairs && !TourPlayer.Playing && renderType == RenderTypes.Normal)
                {
                    float aspect = RenderContext11.ViewPort.Height / RenderContext11.ViewPort.Width;


                    crossHairPoints[0].X = .01f * aspect;
                    crossHairPoints[1].X = -.01f * aspect;
                    crossHairPoints[0].Y = 0;
                    crossHairPoints[1].Y = 0;
                    crossHairPoints[0].Z = .9f;
                    crossHairPoints[1].Z = .9f;
                    crossHairPoints[0].W = 1f;
                    crossHairPoints[1].W = 1f;
                    crossHairPoints[0].Color = Color.White;
                    crossHairPoints[1].Color = Color.White;

                    crossHairPoints[2].X = 0;
                    crossHairPoints[3].X = 0;
                    crossHairPoints[2].Y = -.01f;
                    crossHairPoints[3].Y = .01f;
                    crossHairPoints[2].Z = .9f;
                    crossHairPoints[3].Z = .9f;
                    crossHairPoints[2].W = 1f;
                    crossHairPoints[3].W = 1f;
                    crossHairPoints[2].Color = Color.White;
                    crossHairPoints[3].Color = Color.White;

                    Sprite2d.DrawLines(RenderContext11, crossHairPoints, 4, SharpDX.Matrix.OrthoLH(1f, 1f, 1, -1), false);

                }


                if (Properties.Settings.Default.ShowTouchControls && (!TourPlayer.Playing || mover == null) && ( renderType == RenderTypes.Normal || renderType == RenderTypes.LeftEye || renderType == RenderTypes.RightEye) && !rift )
                {
                    DrawTouchControls();
                }


                DrawKinectUI();

                SetupMatricesAltAz();
                Reticle.DrawAll(RenderContext11);


            }
            catch (Exception e)
            {
                if (Earth3d.Logging) { Earth3d.WriteLogMessage("RenderFrame: Exception"); }
                if (offscreenRender)
                {
                    throw e;
                }
            }
            finally
            {
                if (offscreenRender)
                {

                    RenderContext11.SetDisplayRenderTargets();
                }
            }

            PresentFrame11(offscreenRender);
        }
Пример #7
0
        private void RenderWarpedFisheye()
        {
            if (warpTexture == null)
            {
                warpTexture = new RenderTargetTexture(2048, 2048, 1);
                if (RenderContext11.MultiSampleCount > 1)
                {
                    warpTextureMSAA = new RenderTargetTexture(2048, 2048);
                }
            }

            // If MSAA is enabled, render to an MSAA target and perform a resolve to a non-MSAA texture.
            // Otherwise, render directly to the non-MSAA texture
            RenderTargetTexture warpRenderTarget = warpTextureMSAA != null ? warpTextureMSAA : warpTexture;

            SetupMatricesWarpFisheye(1);
            RenderContext11.SetOffscreenRenderTargets(warpRenderTarget, null);
            RenderContext11.DepthStencilMode = DepthStencilMode.Off;
            RenderFisheye(true);

            if (warpTextureMSAA != null)
            {
                RenderContext11.Device.ImmediateContext.ResolveSubresource(warpTextureMSAA.RenderTexture.Texture, 0, warpTexture.RenderTexture.Texture, 0, RenderContext11.DefaultColorFormat);
            }
            RenderContext11.Device.ImmediateContext.GenerateMips(warpTexture.RenderTexture.ResourceView);

            SetupMatricesWarpFisheye((float)ViewWidth / (float)renderWindow.ClientRectangle.Height);

            if (warpIndexBuffer == null)
            {
                CreateWarpVertexBuffer();
            }


            RenderContext11.SetDisplayRenderTargets();

            RenderContext11.ClearRenderTarget(SharpDX.Color.Black);
            RenderContext11.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            RenderContext11.BlendMode = BlendMode.None;
            RenderContext11.setRasterizerState(TriangleCullMode.Off);
            SharpDX.Matrix mat = (RenderContext11.World * RenderContext11.View * RenderContext11.Projection).Matrix11;

            mat.Transpose();

            WarpOutputShader.MatWVP = mat;
            WarpOutputShader.Use(RenderContext11.devContext, true);

            RenderContext11.SetIndexBuffer(warpIndexBuffer);
            RenderContext11.SetVertexBuffer(warpVertexBuffer);
            RenderContext11.devContext.PixelShader.SetShaderResource(0, warpTexture.RenderTexture.ResourceView);
            RenderContext11.devContext.DrawIndexed(warpIndexBuffer.Count, 0, 0);

            PresentFrame11(false);

        }
Пример #8
0
        private void RenderDomeMaster()
        {

            if (domeMasterTexture == null)
            {
                domeMasterTexture = new RenderTargetTexture(dumpFrameParams.Width, dumpFrameParams.Height, 1);
            }

            RenderContext11.DepthStencilMode = DepthStencilMode.Off;

            RenderContext11.SetOffscreenRenderTargets(domeMasterTexture, null);

            RenderContext11.ClearRenderTarget(SharpDX.Color.Black);

            SetupMatricesWarpFisheye(1f);

            if (domeVertexBuffer == null)
            {
                domeVertexBuffer = new PositionColorTexturedVertexBuffer11[5];
                domeIndexBuffer = new IndexBuffer11[5];

                for (int face = 0; face < 5; face++)
                {
                    CreateDomeFaceVertexBuffer(face);
                }
            }

            RenderContext11.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            RenderContext11.BlendMode = BlendMode.None;
            RenderContext11.setRasterizerState(TriangleCullMode.Off);
            RenderContext11.DepthStencilMode = DepthStencilMode.Off;

            SharpDX.Matrix mat = (RenderContext11.World * RenderContext11.View * RenderContext11.Projection).Matrix11;
            mat.Transpose();

            WarpOutputShader.MatWVP = mat;
            WarpOutputShader.Use(RenderContext11.devContext, true);



            for (int face = 0; face < 5; face++)
            {
                RenderContext11.SetIndexBuffer(domeIndexBuffer[face]);
                RenderContext11.SetVertexBuffer(domeVertexBuffer[face]);
                RenderContext11.devContext.PixelShader.SetShaderResource(0, domeCube[face].RenderTexture.ResourceView);
                RenderContext11.devContext.DrawIndexed(domeIndexBuffer[face].Count, 0, 0);
            }

            SharpDX.Direct3D11.Texture2D.ToFile(RenderContext11.devContext, domeMasterTexture.RenderTexture.Texture, SharpDX.Direct3D11.ImageFileFormat.Png, dumpFrameParams.Name.Replace(".", string.Format("_{0:0000}.", SpaceTimeController.CurrentFrameNumber)));

        }
Пример #9
0
        private void RenderFlatDistort()
        {
            if (warpTexture == null)
            {
                warpTexture = new RenderTargetTexture(2048, 2048);
            }

            SetupMatricesFisheye();

            if (warpIndexBuffer == null)
            {
                CreateWarpVertexBuffer();
            }

            RenderContext11.SetDisplayRenderTargets();

            RenderContext11.ClearRenderTarget(SharpDX.Color.Black);
            RenderContext11.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            RenderContext11.BlendMode = BlendMode.None;
            RenderContext11.setRasterizerState(TriangleCullMode.Off);
            SharpDX.Matrix mat = (RenderContext11.World * RenderContext11.View * RenderContext11.Projection).Matrix11;
            mat.Transpose();

            WarpOutputShader.MatWVP = mat;
            WarpOutputShader.Use(RenderContext11.devContext, true);

            RenderContext11.SetIndexBuffer(warpIndexBuffer);
            RenderContext11.SetVertexBuffer(warpVertexBuffer);

            RenderContext11.devContext.PixelShader.SetShaderResource(0, undistorted.RenderTexture.ResourceView);
            RenderContext11.devContext.DrawIndexed(warpIndexBuffer.Count, 0, 0);

            PresentFrame11(false);

        }
Пример #10
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);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
0
        public ShadowMap(string contentManagerName, int resolution)
            : base()
        {
            mResolutionX = resolution;
            mResolutionY = resolution;


            //MDS_TEMP
            bool hasMikeUpdatedThisCode = false;
            if (hasMikeUpdatedThisCode && IsF32Supported())
            {
                mRenderTargetTexture = new RenderTargetTexture(SurfaceFormat.Single, mResolutionX, mResolutionY);
            }
            else
            {
                mRenderTargetTexture = new RenderTargetTexture(SurfaceFormat.Color, mResolutionX, mResolutionY);
            }

            mShadowDepthBuffer = new DepthStencilBuffer(FlatRedBallServices.GraphicsDevice, mResolutionX, mResolutionY, DepthFormat.Depth24Stencil8);

            mLightSourceCamera = new Camera(contentManagerName, mResolutionX, mResolutionY);
            mLightSourceCamera.AspectRatio = mResolutionX / mResolutionY;

            //Create a default bounding box
            Vector3 bboxMin = new Vector3(-5.0f, -5.0f, -100.0f);
            Vector3 bboxMax = new Vector3(5.0f, 5.0f, 100.0f);
            mBoundingBox = new BoundingBox(bboxMin, bboxMax);
        }
Пример #14
0
        public void SetOffscreenRenderTargets(RenderTargetTexture targetTexture, DepthBuffer depthBuffer)
        {
            currentTargetView = targetTexture.renderView;

            if (depthBuffer != null)
            {
                currentDepthView = depthBuffer.DepthView;
            }
            else
            {
                currentDepthView = null;
            }

            devContext.OutputMerger.ResetTargets();
            ViewPort = new Viewport(0, 0, targetTexture.Width, targetTexture.Height, 0.0f, 1.0f);

            if (depthBuffer != null)
            {
                devContext.OutputMerger.SetTargets(depthBuffer.DepthView, targetTexture.renderView);
            }
            else
            {
                devContext.OutputMerger.SetTargets(targetTexture.renderView);

            }
        }
Пример #15
0
        public void CaptureMegaShot(string filename, int width, int height)
        {

            megaHeight = height;
            megaWidth = width;
            megaFrameDump = true;

            RenderTargetTexture megaTextureAA = new RenderTargetTexture(width, height);
            RenderTargetTexture megaTexture = new RenderTargetTexture(width, height, 1);

            DepthBuffer megaZbuffer = new DepthBuffer(width, height);

            while (true)
            {

                if (RenderContext11.MultiSampleCount > 1)
                {
                    // When MSAA is enabled, we render each face to the same multisampled render target,
                    // then resolve to a different texture for each face. This saves memory and works around
                    // the fact that multisample textures are not permitted to have mipmaps.
                    RenderFrame(megaTextureAA.renderView, megaZbuffer.DepthView, RenderTypes.Normal, width, height);

                    RenderContext11.PrepDevice.ImmediateContext.ResolveSubresource(megaTextureAA.RenderTexture.Texture, 0,
                                                                                  megaTexture.RenderTexture.Texture, 0,
                                                                                  RenderContext11.DefaultColorFormat);
                }
                else
                {
                    RenderFrame(megaTexture.renderView, megaZbuffer.DepthView, RenderTypes.Normal, width, height);
                }

                if (TileCache.QueuePercent == 100)
                {
                    break;
                }

                Application.DoEvents();
            }
            SharpDX.Direct3D11.Texture2D.ToFile(RenderContext11.devContext, megaTexture.RenderTexture.Texture, SharpDX.Direct3D11.ImageFileFormat.Png, filename);
            megaFrameDump = false;
            megaTexture.Dispose();
            megaTextureAA.Dispose();
            megaZbuffer.Dispose();
        }
Пример #16
0
        public void Render()
        {
            if (!readyToRender)
            {
                return;
            }


            if (SyncLayerNeeded)
            {
                NetControl.SyncLayersUiThread();
            }

            if (SyncTourNeeded)
            {
                NetControl.SyncTourUiThread();
            }

            if (Tile.fastLoad)
            {
                Tile.fastLoadAutoReset = true;
            }

            if (!TourPlayer.Playing)
            {
                Earth3d.MainWindow.CrossFadeFrame = false;
            }

            

            Int64 ticks = HiResTimer.TickCount;

            double elapsedSeconds = ((double)(ticks - lastRenderTickCount)) / HiResTimer.Frequency;

            if (Properties.Settings.Default.TargetFrameRate != 0 && !(Properties.Settings.Default.FrameSync && Properties.Settings.Default.TargetFrameRate == 60))
            {
                int frameRate = Properties.Settings.Default.TargetFrameRate;


                if (elapsedSeconds < (1.0 / (double)frameRate))
                {
                    return;
                }
            }

            lastRenderTickCount = ticks;

            lastFrameTime = (Math.Min(.1, elapsedSeconds));

            //Update MetaNow to current realtime for entire frame to render exactly on time
            SpaceTimeController.MetaNow = DateTime.Now;


            LoadTileBudget = 1;

            if (IsPaused() || !Initialized)
            {
                System.Threading.Thread.Sleep(100);
                return;
            }



            if (ProjectorServer)
            {
                UpdateNetworkStatus();
            }


            //oculus rift support
            rift = StereoMode == StereoModes.OculusRift;
            if (rift)
            {
                GetSensorSample();
            }




            TileCache.PurgeLRU();
            TileCache.DecimateQueue();

            Tile.imageQuality = Properties.Settings.Default.ImageQuality;

            Tile.CurrentRenderGeneration++;
            IconCacheEntry.CurrentFrame = Tile.CurrentRenderGeneration;

            Tile.lastDeepestLevel = Tile.deepestLevel;
            Tile.TilesInView = 0;
            Tile.TrianglesRendered = 0;
            Tile.TilesTouched = 0;
 

            if (ZoomFactor == 0 || TargetZoom == 0 || double.IsNaN(ZoomFactor) || double.IsNaN(TargetZoom))
            {
                ZoomFactor = TargetZoom = 360;
            }

            if (contextPanel != null)
            {
                contextPanel.QueueProgress = TileCache.QueuePercent;
            }

            TileCache.InitNextWaitingTile();

            // reset dome matrix Cache
            DomeMatrixFresh = false;


            if (mover != null)
            {
                SpaceTimeController.Now = mover.CurrentDateTime;
            }
            else
            {
                SpaceTimeController.UpdateClock();
                LayerManager.UpdateLayerTime();
            }

            if (uiController != null)
            {
                {
                    uiController.PreRender(this);
                }
            }

            if (Space)
            {
                Planets.UpdatePlanetLocations(false);
            }
            else if (CurrentImageSet.DataSetType == ImageSetType.SolarSystem)
            {
                // todo allow update of focus planet
                Planets.UpdatePlanetLocations(true);
                Planets.UpdateOrbits(0);
            }

            UpdateSpaceNavigator();
            UpdateXInputState();
            UpdateNetControlState();
            if (mover != null)
            {
                UpdateMover(mover);
            }
            else
            {
                if (!SandboxMode)
                {
                    if (SolarSystemTrack == SolarSystemObjects.Undefined | (SolarSystemTrack == SolarSystemObjects.Custom && viewCamera.ViewTarget == Vector3d.Empty))
                    {
                        SolarSystemTrack = SolarSystemObjects.Sun;
                    }
                }
            }

            UpdateViewParameters();

            if (SolarSystemMode)
            {
                if (SolarSystemTrack != SolarSystemObjects.Custom)
                {
                    viewCamera.ViewTarget = Planets.GetPlanet3dLocation(SolarSystemTrack);
                }
            }

            ClampZoomValues();

            if (blink)
            {
                TimeSpan ts = DateTime.Now - lastBlink;
                if (ts.TotalMilliseconds > 500)
                {
                    if (StudyOpacity > 0)
                    {
                        StudyOpacity = 0;
                    }
                    else
                    {
                        StudyOpacity = 100;
                    }
                    lastBlink = DateTime.Now;
                }
            }

            LayerManager.PrepTourLayers();

            if (Settings.MasterController)
            {
                SendMove();
            }



            if (contextPanel != null)
            {

                contextPanel.QueueProgress = TileCache.QueuePercent;

                if (Space)
                {
                    contextPanel.ViewLevel = fovAngle;
                    contextPanel.RA = RA;
                    contextPanel.Dec = Dec;

                    if (constellationCheck != null)
                    {
                        constellation = this.constellationCheck.FindConstellationForPoint(RA, Dec);
                        contextPanel.Constellation = Constellations.FullName(Constellation);
                    }
                }
                else if (SolarSystemMode || SandboxMode)
                {
                    if (SandboxMode)
                    {
                        contextPanel.Sandbox = true;
                        contextPanel.Distance = SolarSystemCameraDistance;
                    }
                    else
                    {
                        contextPanel.Sandbox = false;
                        contextPanel.Distance = SolarSystemCameraDistance;
                    }


                    if (!SandboxMode && (viewCamera.Target != SolarSystemObjects.Custom && viewCamera.Target != SolarSystemObjects.Undefined)) 
                    {
                        Vector3d pnt = Coordinates.GeoTo3dDouble(ViewLat, ViewLong + 90);

                        Matrix3d EarthMat = Planets.EarthMatrixInv;


                        pnt = Vector3d.TransformCoordinate(pnt, EarthMat);
                        pnt.Normalize();


                        Vector2d radec = Coordinates.CartesianToLatLng(pnt);

                        if (viewCamera.Target != SolarSystemObjects.Earth)
                        {
                            if (radec.X < 0)
                            {
                                radec.X += 360;
                            }
                        }

                        contextPanel.RA = radec.X;
                        contextPanel.Dec = radec.Y;
                    }
                    else
                    {
                        contextPanel.RA = ViewLong;
                        contextPanel.Dec = ViewLat;
                    }
                    contextPanel.Constellation = null;
                }
                else if (PlanetLike)
                {
                    contextPanel.Sandbox = false;
                    contextPanel.Distance = SolarSystemCameraDistance / UiTools.KilometersPerAu * 370;
                    contextPanel.RA = ViewLong;
                    contextPanel.Dec = ViewLat;
                    contextPanel.Constellation = null;
                }
                else
                {
                    contextPanel.Sandbox = false;
                    contextPanel.ViewLevel = fovAngle;
                    contextPanel.RA = ViewLong;
                    contextPanel.Dec = ViewLat;
                    contextPanel.Constellation = null;
                }
            }

            if (StereoMode != StereoModes.Off && (!Space || rift))
            {
                RenderContext11.ViewPort = new SharpDX.Direct3D11.Viewport(0, 0, ViewWidth, renderWindow.Height, 0.0f, 1.0f);

                // Ensure that the dome depth/stencil buffer matches our requirements
                if (domeZbuffer != null)
                {
                    if (domeZbuffer.Width != ViewWidth || domeZbuffer.Height != renderWindow.Height)
                    {
                        domeZbuffer.Dispose();
                        GC.SuppressFinalize(domeZbuffer);
                        domeZbuffer = null;
                    }
                }

                if (leftEye != null)
                {
                    if (leftEye.RenderTexture.Height != renderWindow.Height || leftEye.RenderTexture.Width != ViewWidth)
                    {
                        leftEye.Dispose();
                        GC.SuppressFinalize(leftEye);
                        leftEye = null;
                    }
                }

                if (rightEye != null)
                {
                    if (rightEye.RenderTexture.Height != renderWindow.Height || rightEye.RenderTexture.Width != ViewWidth)
                    {
                        rightEye.Dispose();
                        GC.SuppressFinalize(rightEye);
                        rightEye = null;
                    }
                }

                if (stereoRenderTexture != null)
                {
                    if (stereoRenderTexture.RenderTexture.Height != renderWindow.Height || stereoRenderTexture.RenderTexture.Width != ViewWidth)
                    {
                        stereoRenderTexture.Dispose();
                        GC.SuppressFinalize(stereoRenderTexture);
                        stereoRenderTexture = null;
                    }
                }

                if (domeZbuffer == null)
                {
                    domeZbuffer = new DepthBuffer(ViewWidth, renderWindow.Height);
                }

                if (leftEye == null)
                {
                    leftEye = new RenderTargetTexture(ViewWidth, renderWindow.Height, 1);
                }

                if (rightEye == null)
                {
                    rightEye = new RenderTargetTexture(ViewWidth, renderWindow.Height, 1);
                }

                if (RenderContext11.MultiSampleCount > 1)
                {
                    // When multisample anti-aliasing is enabled, render to an offscreen buffer and then
                    // resolve to the left and then the right eye textures. 
                    if (stereoRenderTexture == null)
                    {
                        stereoRenderTexture = new RenderTargetTexture(ViewWidth, renderWindow.Height);
                    }

                    RenderFrame(stereoRenderTexture, domeZbuffer, RenderTypes.LeftEye);
                    RenderContext11.PrepDevice.ImmediateContext.ResolveSubresource(stereoRenderTexture.RenderTexture.Texture, 0,
                                                                                   leftEye.RenderTexture.Texture, 0,
                                                                                   RenderContext11.DefaultColorFormat);
                    RenderFrame(stereoRenderTexture, domeZbuffer, RenderTypes.RightEye);
                    RenderContext11.PrepDevice.ImmediateContext.ResolveSubresource(stereoRenderTexture.RenderTexture.Texture, 0,
                                                                                   rightEye.RenderTexture.Texture, 0,
                                                                                   RenderContext11.DefaultColorFormat);
                }
                else
                {
                    // When anti-aliasing is not enabled, render directly to the left and right eye textures.
                    RenderFrame(leftEye, domeZbuffer, RenderTypes.LeftEye);
                    RenderFrame(rightEye, domeZbuffer, RenderTypes.RightEye);
                }

                if (StereoMode == StereoModes.InterlineEven || StereoMode == StereoModes.InterlineOdd)
                {
                    RenderSteroPairInterline(leftEye, rightEye);
                }
                else if (StereoMode == StereoModes.AnaglyphMagentaGreen || StereoMode == StereoModes.AnaglyphRedCyan || StereoMode == StereoModes.AnaglyphYellowBlue)
                {
                    RenderSteroPairAnaglyph(leftEye, rightEye);
                }
                else if (StereoMode == StereoModes.OculusRift)
                {
                    RenderSteroOculurRift(leftEye, rightEye);
                }
                else
                {
                    if (StereoMode == StereoModes.CrossEyed)
                    {

                        RenderSteroPairSideBySide(rightEye, leftEye);
                    }
                    else
                    {
                        RenderSteroPairSideBySide(leftEye, rightEye);
                    }
                }
            }
            else if (Settings.DomeView)
            {
                int cubeFaceSize = 512;
                if (usingLargeTextures)
                {
                    cubeFaceSize = 1024;
                }

                if (CaptureVideo && dumpFrameParams.Dome)
                {
                    cubeFaceSize = 2048;
                }



                if (usingLargeTextures != Properties.Settings.Default.LargeDomeTextures)
                {
                    refreshDomeTextures = true;
                }

                if (currentCubeFaceSize != cubeFaceSize)
                {
                    refreshDomeTextures = true;
                }

                if (refreshDomeTextures)
                {
                    usingLargeTextures = Properties.Settings.Default.LargeDomeTextures;
                    for (int face = 0; face < 5; face++)
                    {
                        if (domeCube[face] != null)
                        {
                            domeCube[face].Dispose();
                            GC.SuppressFinalize(domeCube[face]);
                            domeCube[face] = null;
                        }
                    }
                    if (domeZbuffer != null)
                    {
                        domeZbuffer.Dispose();
                        GC.SuppressFinalize(domeZbuffer);
                        domeZbuffer = null;
                    }
                    if (domeCubeFaceMultisampled != null)
                    {
                        domeCubeFaceMultisampled.Dispose();
                        GC.SuppressFinalize(domeCubeFaceMultisampled);
                        domeCubeFaceMultisampled = null;
                    }
                }


                // Ensure that the dome depth/stencil buffer matches our requirements
                if (domeZbuffer != null)
                {
                    if (domeZbuffer.Width != cubeFaceSize || domeZbuffer.Height != cubeFaceSize)
                    {
                        domeZbuffer.Dispose();
                        GC.SuppressFinalize(domeZbuffer);
                        domeZbuffer = null;
                    }
                }

                if (domeZbuffer == null)
                {
                    domeZbuffer = new DepthBuffer(cubeFaceSize, cubeFaceSize);
                }

                if (domeCubeFaceMultisampled == null && RenderContext11.MultiSampleCount > 1)
                {
                    domeCubeFaceMultisampled = new RenderTargetTexture(cubeFaceSize, cubeFaceSize);
                }

                for (int face = 0; face < 5; face++)
                {
                    if (domeCube[face] == null)
                    {
                        domeCube[face] = new RenderTargetTexture(cubeFaceSize, cubeFaceSize, 1);
                        currentCubeFaceSize = cubeFaceSize;
                        refreshDomeTextures = false;
                    }

                    if (RenderContext11.MultiSampleCount > 1)
                    {
                        // When MSAA is enabled, we render each face to the same multisampled render target,
                        // then resolve to a different texture for each face. This saves memory and works around
                        // the fact that multisample textures are not permitted to have mipmaps.
                        RenderFrame(domeCubeFaceMultisampled, domeZbuffer, (RenderTypes)face);
                        RenderContext11.PrepDevice.ImmediateContext.ResolveSubresource(domeCubeFaceMultisampled.RenderTexture.Texture, 0,
                                                                                       domeCube[face].RenderTexture.Texture, 0,
                                                                                       RenderContext11.DefaultColorFormat);
                    }
                    else
                    {
                        RenderFrame(domeCube[face], domeZbuffer, (RenderTypes)face);
                    }
                    RenderContext11.PrepDevice.ImmediateContext.GenerateMips(domeCube[face].RenderTexture.ResourceView);
                }

                if (Properties.Settings.Default.DomeTypeIndex > 0)
                {
                    RenderWarpedFisheye();
                }
                else
                {
                    if (CaptureVideo && dumpFrameParams.Dome)
                    {
                        if (!dumpFrameParams.WaitDownload || TileCache.QueuePercent == 100)
                        {
                            RenderDomeMaster();
                        }
                    }
                    RenderFisheye(false);
                }

            }
            else if (config.UseDistrotionAndBlend)
            {
                if (undistorted == null)
                {
                    undistorted = new RenderTargetTexture(config.Width, config.Height);
                }


                // Ensure that the dome depth/stencil buffer matches our requirements
                if (domeZbuffer != null)
                {
                    if (domeZbuffer.Width != config.Width || domeZbuffer.Height != config.Height)
                    {
                        domeZbuffer.Dispose();
                        GC.SuppressFinalize(domeZbuffer);
                        domeZbuffer = null;
                    }
                }

                if (domeZbuffer == null)
                {
                    domeZbuffer = new DepthBuffer(config.Width, config.Height);

                }


                // * If there's no multisampling, draw directly into the undistorted texture
                // * When multisampling is on, draw into an intermediate buffer, then resolve 
                //   it into the undistorted texture
                RenderFrame(undistorted, domeZbuffer, RenderTypes.Normal);

                RenderDistort();
            }
            else if (Properties.Settings.Default.FlatScreenWarp)
            {
                if (undistorted == null)
                {
                    undistorted = new RenderTargetTexture(ViewWidth, renderWindow.ClientRectangle.Height);
                }

                if (domeZbuffer != null)
                {
                    if (domeZbuffer.Width != ViewWidth || domeZbuffer.Height != renderWindow.ClientRectangle.Height)
                    {
                        domeZbuffer.Dispose();
                        GC.SuppressFinalize(domeZbuffer);
                        domeZbuffer = null;
                    }
                }

                if (domeZbuffer == null)
                {
                    domeZbuffer = new DepthBuffer(ViewWidth, renderWindow.ClientRectangle.Height);

                }


                RenderFrame(undistorted, domeZbuffer, RenderTypes.Normal);
                RenderFlatDistort();

            }
            else
            {
                if (renderWindow.ClientSize.Height != RenderContext11.DisplayViewport.Height ||
                            renderWindow.ClientSize.Width != RenderContext11.DisplayViewport.Width)
                {
                    RenderContext11.Resize(renderWindow);
                }
                RenderFrame(null, null, RenderTypes.Normal);
            }

            UpdateStats();

            lastRender = HiResTimer.TickCount;

            if (CaptureVideo)
            {
                if (!dumpFrameParams.WaitDownload || TileCache.QueuePercent == 100)
                {
                    if (!dumpFrameParams.Dome)
                    {
                        Int64 ticksa = HiResTimer.TickCount;
                        SaveFrame();
                    }
                    SpaceTimeController.NextFrame();
                }
                if (SpaceTimeController.DoneDumping())
                {
                    SpaceTimeController.CancelFrameDump = false;
                    DomeFrameDumping();
                }
            }

            if (Tile.fastLoadAutoReset)
            {
                Tile.fastLoad = false;
                Tile.fastLoadAutoReset = false;
            }

        }
Пример #17
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);
        }