Exemple #1
0
        public void Render()
        {
            var cameraRT = MyRender.GetRenderTarget(MyRenderTargets.SecondaryCamera);

            m_setup.RenderTargets[0] = cameraRT;

            //SetRenderSetup();

            // Adjust render setup
            m_setup.AspectRatio    = cameraRT.GetLevelDescription(0).Width / (float)cameraRT.GetLevelDescription(0).Height;
            m_setup.Viewport       = new SharpDX.Viewport(0, 0, cameraRT.GetLevelDescription(0).Width, cameraRT.GetLevelDescription(0).Height);
            m_setup.ViewMatrix     = ViewMatrix;
            m_setup.CameraPosition = ViewMatrix.Translation;
            m_setup.Fov            = MathHelper.ToRadians(MySecondaryCameraConstants.FIELD_OF_VIEW);

            m_setup.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(m_setup.Fov.Value,
                                                                           m_setup.AspectRatio.Value,
                                                                           MySecondaryCameraConstants.NEAR_PLANE_DISTANCE,
                                                                           //m_setup.LodTransitionBackgroundEnd.Value);
                                                                           MyRenderCamera.FAR_PLANE_DISTANCE);
            ProjectionMatrix        = m_setup.ProjectionMatrix.Value;
            MyRenderCamera.Viewport = m_setup.Viewport.Value;

            // render to fullsize texture
            MyRender.PushRenderSetupAndApply(m_setup, ref m_backup);
            MyRender.Draw3D(false);
            //MyRender.GraphicsDevice.Clear(ClearFlags.All, new ColorBGRA(1.0f, 0, 0.0f, 1), 1, 0);
            MyRender.PopRenderSetupAndRevert(m_backup);


            MyRender.TakeScreenshot("BackCamera", cameraRT, MyEffectScreenshot.ScreenshotTechniqueEnum.Color);

            //Texture.ToFile(cameraRT, "c:\\__cam.dds", ImageFileFormat.Dds);
        }
        public void UpdateFace(Vector3D position, int faceIndex)
        {
            //SetRenderSetup();

            CubeMapFace face = (CubeMapFace)faceIndex;

            // New setup
            m_setup.CameraPosition   = position;
            m_setup.AspectRatio      = 1.0f;
            m_setup.Viewport         = new Viewport(0, 0, (int)m_environmentRT.GetLevelDescription(0).Width, (int)m_environmentRT.GetLevelDescription(0).Width);
            m_setup.ViewMatrix       = CreateViewMatrix(face, position);
            m_setup.Fov              = MathHelper.PiOver2;
            m_setup.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(m_setup.Fov.Value, m_setup.AspectRatio.Value, NearClip, m_setup.LodTransitionBackgroundEnd.Value);
            m_setup.DepthToAlpha     = true;

            MyRender.GetRenderProfiler().StartProfilingBlock("Draw environmental maps");

            MyRender.PushRenderSetupAndApply(m_setup, ref m_backup);
            MyRender.Draw3D(false);

            MyRender.GetRenderProfiler().EndProfilingBlock();

            Surface cubeSurface = m_environmentRT.GetCubeMapSurface(face, 0);

            MyRender.GraphicsDevice.SetRenderTarget(0, cubeSurface);

            var screenEffect = MyRender.GetEffect(MyEffects.Screenshot) as MyEffectScreenshot;

            screenEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
            screenEffect.SetSourceTexture(m_fullSizeRT);
            screenEffect.SetScale(new Vector2(m_environmentRT.GetLevelDescription(0).Width / (float)m_fullSizeRT.GetLevelDescription(0).Width, m_environmentRT.GetLevelDescription(0).Height / (float)m_fullSizeRT.GetLevelDescription(0).Height));
            MyRender.GetFullscreenQuad().Draw(screenEffect);
            screenEffect.SetScale(new Vector2(1, 1));

            //Texture.ToFile(m_fullSizeRT, "C:\\fullSizeRT.dds", ImageFileFormat.Dds);

            cubeSurface.Dispose();

            MyRender.PopRenderSetupAndRevert(m_backup);
        }