Beispiel #1
0
        /// <summary>
        /// IMPORTANT: using Lod1Normals here, since this is done in a separate time to normal rendering
        /// </summary>
        public Texture RenderModelPreview(MyModel model, int width, int height, float lightsIntensity = 2f)
        {
            m_fullSizeRT = MyRender.GetRenderTarget(MyRenderTargets.Auxiliary0);

            if (m_fullSizeRT == null || MyGuiScreenGamePlay.Static == null)
            {
                return(null);
            }

            Device device = MyMinerGame.Static.GraphicsDevice;

            Texture renderTarget = new Texture(device, width, height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);

            PrepareRender(width, height);
            MyRender.Sun.Intensity = lightsIntensity;
            foreach (var light in m_setup.LightsToUse)
            {
                light.Intensity = lightsIntensity;
            }

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = false;
            }

            float distance = 2.1f;

            Matrix viewMatrix = Matrix.Identity;

            m_setup.ViewMatrix = viewMatrix;

            m_setup.EnableNear = false;

            //generate world matrix
            Matrix worldMatrix = Matrix.Identity;

            worldMatrix.Translation  = -model.BoundingSphere.Center;
            worldMatrix             *= Matrix.CreateRotationY(-3.0f * MathHelper.PiOver4);
            worldMatrix             *= Matrix.CreateRotationX(0.7f * MathHelper.PiOver4);
            worldMatrix.Translation += new Vector3(0, 0, -model.BoundingSphere.Radius * distance);

            SetupRenderElements(model, worldMatrix);

            SetupLights(model);

            MyRender.PushRenderSetup(m_setup);
            MyRender.Draw();
            MyRender.PopRenderSetup();

            BlitToThumbnail(device, renderTarget);

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = true;
            }

            return(renderTarget);

            return(null);
        }
        public void Render()
        {
            Texture 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 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);
                                                                           MyCamera.FAR_PLANE_DISTANCE);
            ProjectionMatrix  = m_setup.ProjectionMatrix.Value;
            MyCamera.Viewport = m_setup.Viewport.Value;

            // render to fullsize texture
            MyRender.PushRenderSetupAndApply(m_setup, ref m_backup);
            MyRender.Draw(false);
            MyRender.PopRenderSetupAndRevert(m_backup);

            //MySession.PlayerShip.Weapons.Visible = true;
        }
Beispiel #3
0
        public void UpdateFace(Vector3 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.Draw(false);

            MyRender.GetRenderProfiler().EndProfilingBlock();

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

            MyMinerGame.Static.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 * 0.968f, 0.982f * m_environmentRT.GetLevelDescription(0).Width / (float)m_fullSizeRT.GetLevelDescription(0).Height));
            MyGuiManager.GetFullscreenQuad().Draw(screenEffect);
            screenEffect.SetScale(new Vector2(1, 1));

            cubeSurface.Dispose();

            MyRender.PopRenderSetupAndRevert(m_backup);
        }
Beispiel #4
0
        public Texture RenderAsteroidMaterialPreview(MyMwcVoxelMaterialsEnum material, int width, int height, float lightsIntensity = 2f)
        {
            m_fullSizeRT = MyRender.GetRenderTarget(MyRenderTargets.Auxiliary0);

            if (m_fullSizeRT == null || MyGuiScreenGamePlay.Static == null)
            {
                return(null);
            }

            Device device = MyMinerGame.Static.GraphicsDevice;

            Texture renderTarget = new Texture(device, width, height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);

            PrepareRender(width, height);

            MyRender.Sun.Direction = new Vector3(1.5f, -1.5f, -1);
            MyRender.Sun.Direction.Normalize();

            MyRender.Sun.Intensity = lightsIntensity;
            foreach (var light in m_setup.LightsToUse)
            {
                light.Intensity = 3 * lightsIntensity;
            }

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = false;
            }

            float distance = 2.1f;

            Matrix viewMatrix = Matrix.Identity;

            m_setup.ViewMatrix = viewMatrix;

            m_setup.EnableNear = false;


            //var modelEnum = MyStaticAsteroid.GetModelsFromType(MyMwcObjectBuilder_StaticAsteroid_TypesEnum.StaticAsteroid20m_A).LOD0;
            var modelEnum = MyModelsEnum.sphere_smooth;
            var model     = MyModels.GetModelOnlyData(modelEnum);
            var test      = model.BoundingSphere.Radius;

            model.SetDrawTechnique(MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID);


            FakeEntity.VoxelMaterial = material;
            FakeEntity.InitDrawTechniques();


            //generate world matrix
            Matrix worldMatrix = Matrix.Identity;

            worldMatrix.Translation = -model.BoundingSphere.Center;
            //worldMatrix *= Matrix.CreateRotationY(-3.0f * MathHelper.PiOver4);
            //worldMatrix *= Matrix.CreateRotationX(0.7f * MathHelper.PiOver4);
            worldMatrix.Translation += new Vector3(0, 0, -model.BoundingSphere.Radius * distance);

            SetupRenderElements(model, worldMatrix, staticAsteroid: true);

            SetupLights(model);

            MyRender.PushRenderSetup(m_setup);
            MyRender.Draw();
            MyRender.PopRenderSetup();

            BlitToThumbnail(device, renderTarget);

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = true;
            }

            return(renderTarget);

            return(null);
        }
Beispiel #5
0
        /// <summary>
        /// IMPORTANT: using Lod1Normals here, since this is done in a separate time to normal rendering
        /// </summary>
        public Texture RenderPrefabPreview(int prefabId, MyPrefabConfiguration config, MyMwcObjectBuilder_Prefab_AppearanceEnum appearance, int width, int height, float lightsIntensity = 2.5f)
        {
            m_fullSizeRT = MyRender.GetRenderTarget(MyRenderTargets.SSAO);

            if (m_fullSizeRT == null || MyGuiScreenGamePlay.Static == null)
            {
                return(null);
            }

            MyFakes.RENDER_PREVIEWS_WITH_CORRECT_ALPHA = true;

            Texture renderTarget = new Texture(MyMinerGame.Static.GraphicsDevice, width, height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default);

            PrepareRender(width, height);
            MyRender.Sun.Intensity = lightsIntensity;
            foreach (var light in m_setup.LightsToUse)
            {
                light.Intensity = lightsIntensity;
            }

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = false;
            }

            bool weapon = false;

            if (config.BuildType == BuildTypesEnum.MODULES && config.CategoryType == CategoryTypesEnum.WEAPONRY)
            {
                MyModel baseModel    = null;
                MyModel barrelModel  = null;
                Matrix  baseMatrix   = Matrix.Identity;
                Matrix  barrelMatrix = Matrix.Identity;

                weapon = MyLargeShipGunBase.GetVisualPreviewData((MyMwcObjectBuilder_PrefabLargeWeapon_TypesEnum)prefabId, ref baseModel, ref barrelModel, ref baseMatrix, ref barrelMatrix);

                if (weapon)
                {
                    m_setup.ViewMatrix = Matrix.Identity;

                    SetupRenderElements(baseModel, baseMatrix, (int)appearance);
                    SetupRenderElements(barrelModel, barrelMatrix, (int)appearance);

                    SetupLights(baseModel);

                    MyRender.PushRenderSetup(m_setup);
                    MyRender.Draw();
                    MyRender.PopRenderSetup();

                    BlitToThumbnail(MyMinerGame.Static.GraphicsDevice, renderTarget);
                }
            }

            if (!weapon)
            {
                //load new model from prefab config
                MyModel model = MyModels.GetModelForDraw(config.ModelLod0Enum);

                float distanceMultiplier = 2f;

                Matrix viewMatrix = Matrix.Identity;
                m_setup.ViewMatrix = viewMatrix;

                //generate world matrix
                Matrix worldMatrix = Matrix.Identity;
                worldMatrix.Translation = -model.BoundingSphere.Center;

                worldMatrix *= config.PreviewPointOfView.Transform;

                worldMatrix             *= Matrix.CreateRotationY(-.85f * MathHelper.PiOver4);
                worldMatrix             *= Matrix.CreateRotationX(.35f * MathHelper.PiOver4);
                worldMatrix.Translation += new Vector3(0, 0, -model.BoundingSphere.Radius * distanceMultiplier);

                SetupRenderElements(model, worldMatrix, (int)appearance);

                SetupLights(model);

                //MyGuiManager.TakeScreenshot();
                MyRender.PushRenderSetup(m_setup);
                MyRender.EnableShadows = false;
                MyRender.Draw();
                MyRender.EnableShadows = true;
                MyRender.PopRenderSetup();
                //MyGuiManager.StopTakingScreenshot();

                BlitToThumbnail(MyMinerGame.Static.GraphicsDevice, renderTarget);
            }

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = true;
            }

            MyFakes.RENDER_PREVIEWS_WITH_CORRECT_ALPHA = false;

            return(renderTarget);
        }
        /// <summary>
        /// IMPORTANT: using Lod1Normals here, since this is done in a separate time to normal rendering
        /// </summary>
        public RenderTarget2D RenderPreview(MyMwcObjectBuilder_Prefab_TypesEnum enumValue, MyPrefabConfiguration config, int width, int height)
        {
            m_fullSizeRT = MyRender.GetRenderTarget(MyRenderTargets.Lod1Normals);

            if (m_fullSizeRT == null || MyGuiScreenGamePlay.Static == null)
            {
                return(null);
            }

            m_setup.RenderTargets[0] = new RenderTargetBinding(m_fullSizeRT);

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = false;
            }

            GraphicsDevice device = MyMinerGame.Static.GraphicsDevice;

            RenderTarget2D renderTarget = new RenderTarget2D(device, width, height, true, SurfaceFormat.Color, DepthFormat.Depth24, 0, RenderTargetUsage.DiscardContents);

            m_setup.RenderElementsToDraw.Clear();
            m_setup.TransparentRenderElementsToDraw.Clear();

            // make actual viewport one pixel larger in order to remove the deformed border caused by antialiasing
            m_setup.Viewport    = new Viewport(0, 0, 2 * renderTarget.Width, 2 * renderTarget.Height);
            m_setup.AspectRatio = 1;
            m_setup.Fov         = MathHelper.ToRadians(70);

            MyRender.Sun.Direction = new Vector3(.5f, -.3f, -1);
            MyRender.Sun.Direction.Normalize();
            MyRender.Sun.Color = Vector4.One;
            MyRender.EnableSun = true;
            float previousSunIntensityMultiplier = MyRender.SunIntensityMultiplier;

            MyRender.SunIntensityMultiplier = 1.2f;

            if (config.BuildType == BuildTypesEnum.MODULES && config.CategoryType == CategoryTypesEnum.WEAPONRY)
            {
                MyModel baseModel    = null;
                MyModel barrelModel  = null;
                Matrix  baseMatrix   = Matrix.Identity;
                Matrix  barrelMatrix = Matrix.Identity;

                bool result = MyLargeShipGunBase.GetVisualPreviewData(enumValue, ref baseModel, ref barrelModel, ref baseMatrix, ref barrelMatrix);

                if (result)
                {
                    m_setup.ViewMatrix = Matrix.Identity;

                    setupRenderElement(baseModel, baseMatrix);
                    setupRenderElement(barrelModel, barrelMatrix);

                    setupLights(baseModel);

                    MyRender.PushRenderSetup(m_setup);
                    MyRender.Draw();
                    MyRender.PopRenderSetup();

                    BlitToThumbnail(device, renderTarget);
                }
            }
            else
            {
                //load new model from prefab config
                MyModel model = MyModels.GetModelForDraw(config.ModelLod0Enum);

                float distance = 1.85f;

                Matrix viewMatrix = Matrix.Identity;
                m_setup.ViewMatrix = viewMatrix;

                //generate world matrix
                Matrix worldMatrix = Matrix.Identity;
                worldMatrix.Translation  = -model.BoundingSphere.Center;
                worldMatrix             *= Matrix.CreateRotationY(-.85f * MathHelper.PiOver4);
                worldMatrix             *= Matrix.CreateRotationX(.35f * MathHelper.PiOver4);
                worldMatrix.Translation += new Vector3(0, 0, -model.BoundingSphere.Radius * distance);

                setupRenderElement(model, worldMatrix);

                setupLights(model);

                MyRender.PushRenderSetup(m_setup);
                MyRender.Draw();
                MyRender.PopRenderSetup();

                BlitToThumbnail(device, renderTarget);
            }

            MyRender.SunIntensityMultiplier = previousSunIntensityMultiplier;

            if (MySession.PlayerShip != null)
            {
                MySession.PlayerShip.Visible = true;
            }

            return(renderTarget);
        }