Exemple #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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }