Example #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;
        }
Example #3
0
        public override MyEffectBase PrepareAndBeginShader(MyRender.MyRenderSetup setup, MyLodTypeEnum lodType)
        {
            var shader = (MyEffectModelsDNS)MyRender.GetEffect(MyEffects.ModelDNS);

            SetupBaseEffect(shader, setup, lodType);

            MyEffectModelsDNS dnsShader = shader as MyEffectModelsDNS;

            dnsShader.SetHalfPixel(MyRenderCamera.Viewport.Width, MyRenderCamera.Viewport.Height);
            dnsShader.SetScale(MyRender.GetScaleForViewport(MyRender.GetRenderTarget(MyRenderTargets.Depth)));

            bool useDepth = lodType != MyLodTypeEnum.LOD_NEAR;

            if (useDepth)
            {
                // DepthStencilState.DepthRead;
                MyStateObjects.DepthStencil_TestFarObject_DepthReadOnly.Apply();
            }
            else
            {
                DepthStencilState.DepthRead.Apply();
            }
            MyStateObjects.Holo_BlendState.Apply();

            shader.ApplyHolo(!useDepth);
            shader.Begin(0, SharpDX.Direct3D9.FX.None);
            return(shader);
        }
Example #4
0
        public void SetupShadowBaseEffect(MyEffectShadowBase effect)
        {
            effect.SetLightViewProjMatrices(m_lightViewProjectionMatrices);
            effect.SetClipPlanes(m_lightClipPlanes);

            effect.SetShadowMapSize(new Vector4(ShadowMapCascadeSize * NumSplits, ShadowMapCascadeSize, m_shadowMapCascadeSizeInv.X, m_shadowMapCascadeSizeInv.Y));
            effect.SetShadowMap(MyRender.GetRenderTarget(m_shadowRenderTarget));
        }
        public void PrepareForDraw(MyEffectDistantImpostors effect)
        {
            RasterizerState.CullClockwise.Apply();
            BlendState.Opaque.Apply();
            MyMinerGame.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf0), null);

            foreach (MyVoxelMapImpostorGroup group in m_voxelMapImpostorGroups)
            {
                group.PrepareForDraw(effect);
            }
        }
        /// <summary>
        /// Only to be called with FastOcclusionBoundingBoxDraw
        /// </summary>
        public static void PrepareFastOcclusionBoundingBoxDraw()
        {
            MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw;

            effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabled);

            effectOQ.SetViewMatrix(MyCamera.ViewMatrixAtZero);
            effectOQ.SetProjectionMatrix(MyCamera.ProjectionMatrix);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effectOQ.SetDepthRT(depthRenderTarget);
                effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget));
            }
        }
        /// <summary>
        /// Draw occlusion bounding box method with our premade effect and box.
        /// </summary>
        /// <param name="bbox"></param>
        /// <param name="scale"></param>
        /// <param name="enableDepthTesting"></param>
        /// <param name="billboardLike">Indicates whether the occlusion object (box) is rotated to face the camera or not.</param>
        public static void DrawOcclusionBoundingBox(BoundingBox bbox, float scale, bool enableDepthTesting, bool billboardLike = false, bool useDepthTarget = true)
        {
            useDepthTarget &= !MyRenderConstants.RenderQualityProfile.ForwardRender;

            var    cameraToBBox = bbox.GetCenter() - MyCamera.Position;
            Matrix worldMatrix  = billboardLike ? Matrix.CreateWorld(Vector3.Zero, MyMwcUtils.Normalize(cameraToBBox), MyMwcUtils.Normalize(MyCamera.UpVector + MyCamera.LeftVector)) : Matrix.Identity;

            Vector3 scaleV = (bbox.Max - bbox.Min) * scale;

            worldMatrix            *= Matrix.CreateScale(scaleV);
            worldMatrix.Translation = cameraToBBox;



            MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw;

            if (enableDepthTesting && !MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabled);
            }
            else
            {
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestDisabled);
            }


            effectOQ.SetWorldMatrix(worldMatrix);
            effectOQ.SetViewMatrix(MyCamera.ViewMatrixAtZero);
            effectOQ.SetProjectionMatrix(MyCamera.ProjectionMatrix);

            if (useDepthTarget)
            {
                var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effectOQ.SetDepthRT(depthRenderTarget);
                effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget));
            }

            effectOQ.Begin();

            //draw
            m_modelBoxLowRes.Render();

            effectOQ.End();
        }
        // Vertices must be in triangle strip order
        // 0--1
        // | /|
        // |/ |
        // 2--3
        public static void OcclusionPlaneDraw(Vector3[] quad)
        {
            Matrix worldMatrix = Matrix.Identity;

            worldMatrix.Translation = -MyCamera.Position;

            MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw;

            effectOQ.SetWorldMatrix(worldMatrix);
            effectOQ.SetViewMatrix(MyCamera.ViewMatrixAtZero);
            effectOQ.SetProjectionMatrix(MyCamera.ProjectionMatrix);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effectOQ.SetDepthRT(depthRenderTarget);
                effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget));
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabledNonMRT);
            }
            else
            {
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestDisabledNonMRT);
            }
        }
            public void Draw(MyEffectDistantImpostors effect, MyImpostorType impostorType)
            {
                if (!ImpostorProperties.Enabled)
                {
                    return;
                }

                if (impostorType != ImpostorProperties.ImpostorType)
                {
                    return;
                }

                if (ImpostorProperties.ImpostorType == MyImpostorType.Billboards)
                {
                    if (m_trianglesCount <= 0)
                    {
                        return;
                    }

                    m_animationTime += ImpostorProperties.AnimationSpeed;

                    Device device = MyMinerGame.Static.GraphicsDevice;

                    if (MyRenderConstants.RenderQualityProfile.ForwardRender)
                    {
                        DepthStencilState.DepthRead.Apply();
                    }

                    Matrix worldMatrix = Matrix.Identity;

                    if (ImpostorProperties.AnimationSpeed.X > 0)
                    {
                        worldMatrix *= Matrix.CreateRotationX(m_animationTime.X);
                    }
                    if (ImpostorProperties.AnimationSpeed.Y > 0)
                    {
                        worldMatrix *= Matrix.CreateRotationX(m_animationTime.Y);
                    }
                    if (ImpostorProperties.AnimationSpeed.Z > 0)
                    {
                        worldMatrix *= Matrix.CreateRotationX(m_animationTime.Z);
                    }

                    worldMatrix.Translation = MyCamera.Position * 0.5f;
                    effect.SetWorldMatrix(worldMatrix);

                    MyTexture2D texture = null;
                    if (ImpostorProperties.Material.HasValue)
                    {
                        texture = MyTransparentGeometry.GetTexture(ImpostorProperties.Material.Value);
                    }
                    effect.SetImpostorTexture(texture);
                    device.SetStreamSource(0, m_vertexBuffer, 0, MyVertexFormatPositionTextureColor.Stride);
                    device.VertexDeclaration = MyVertexFormatPositionTextureColor.VertexDeclaration;

                    effect.SetTechnique(MyEffectDistantImpostors.Technique.ColoredLit);

                    effect.Begin();
                    device.DrawPrimitives(PrimitiveType.TriangleList, 0, m_trianglesCount);
                    effect.End();
                    MyPerformanceCounter.PerCameraDraw.TotalDrawCalls++;
                }
                else if (ImpostorProperties.ImpostorType == MyImpostorType.Nebula && !MyRenderConstants.RenderQualityProfile.ForwardRender)
                {
                    m_animationTime += ImpostorProperties.AnimationSpeed * (MyFpsManager.FrameTime / 100.0f);

                    BlendState.NonPremultiplied.Apply();
                    RasterizerState.CullCounterClockwise.Apply();
                    DepthStencilState.None.Apply();

                    MyRender.Blit(MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf0), true);
                }
            }
Example #10
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);
        }
Example #11
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);
        }
 public Texture GetRenderedTexture()
 {
     return(MyRender.GetRenderTarget(MyRenderTargets.SecondaryCamera));
 }
Example #14
0
        /// <summary>
        /// Renders a list of models to the shadow map, and returns a surface
        /// containing the shadow occlusion factor
        /// </summary>
        public void Render()
        {
            if (MyRender.Sun.Direction == Vector3.Zero)
            {
                return;
            }

            MyRender.GetRenderProfiler().StartProfilingBlock("MyShadowRenderer::Render");

            if (MultiThreaded)
            {
                WaitUntilPrepareForDrawCompleted();
            }
            else
            {
                //PrepareFrame();
                PrepareCascadesForDraw();
            }

            IssueQueriesForCascades();

            MyRender.GetRenderProfiler().StartProfilingBlock("Set & Clear RT");

            // Set our targets
            MyRender.SetRenderTarget(MyRender.GetRenderTarget(m_shadowRenderTarget), MyRender.GetRenderTarget(m_shadowDepthTarget));
            MyRender.GraphicsDevice.Clear(ClearFlags.ZBuffer, new ColorBGRA(0.0f), 1.0f, 0);

            DepthStencilState.Default.Apply();
            RasterizerState.CullNone.Apply();
            //RasterizerState.CullCounterClockwise.Apply();
            BlendState.Opaque.Apply();

            MyRender.GetRenderProfiler().EndProfilingBlock();

            MyRender.GetRenderProfiler().StartProfilingBlock("Render 4 ShadowMaps");

            // Render our scene geometry to each split of the cascade
            for (int i = 0; i < NumSplits; i++)
            {
                if (m_skip[i])
                {
                    continue;
                }
                if (!m_visibility[i])
                {
                    continue;
                }

                RenderShadowMap(i);
                //IssueQueriesForShadowMap(i);
            }

            //Restore viewport
            MyRenderCamera.UpdateCamera();
            MyRender.SetDeviceViewport(MyRenderCamera.Viewport);

            MyRender.GetRenderProfiler().EndProfilingBlock();

            //   MyGuiManager.TakeScreenshot();
            MyRender.TakeScreenshot("ShadowMap", MyRender.GetRenderTarget(m_shadowRenderTarget), MyEffectScreenshot.ScreenshotTechniqueEnum.Color);

            // Texture.ToFile(MyRender.GetRenderTarget(m_shadowRenderTarget), "c:\\test.dds", ImageFileFormat.Dds);

            MyRender.GetRenderProfiler().EndProfilingBlock();
        }
Example #15
0
        public static void Draw()
        {
            if (!CanDrawCockpit())
            {
                return;
            }

            MyModel model = MyModels.GetModelForDraw(MySession.PlayerShip.CockpitGlassModelEnum);

            RasterizerState.CullNone.Apply();

            if (MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                DepthStencilState.DepthRead.Apply();
            }
            else
            {
                MyStateObjects.DepthStencil_StencilReadOnly.Apply();
            }

            BlendState.NonPremultiplied.Apply();

            MyEffectCockpitGlass effect = (MyEffectCockpitGlass)MyRender.GetEffect(MyEffects.CockpitGlass);

            float glassDirtAlpha = MathHelper.Lerp(MyCockpitGlassConstants.GLASS_DIRT_MIN, MyCockpitGlassConstants.GLASS_DIRT_MAX,
                                                   MySession.PlayerShip.GlassDirtLevel);

            effect.SetGlassDirtLevelAlpha(new Vector4(glassDirtAlpha, 0, 0, 0));

            effect.SetWorldMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix);
            effect.SetViewMatrix(MyCamera.ViewMatrix);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                Matrix projection = MyCamera.ProjectionMatrixForNearObjects;

                effect.SetWorldViewProjectionMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix * MyCamera.ViewMatrixAtZero * projection);
            }
            else
            {
                effect.SetWorldViewProjectionMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix * MyCamera.ViewProjectionMatrixAtZero);
            }

            MyMeshMaterial cockpitMaterial = model.GetMeshList()[0].Materials[0];

            cockpitMaterial.PreloadTexture();
            effect.SetCockpitGlassTexture(cockpitMaterial.DiffuseTexture);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                Texture depthRT = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effect.SetDepthTexture(depthRT);

                effect.SetHalfPixel(MyUtils.GetHalfPixel(depthRT.GetLevelDescription(0).Width, depthRT.GetLevelDescription(0).Height));
            }

            Vector4 sunColor = MySunWind.GetSunColor();

            effect.SetSunColor(new Vector3(sunColor.X, sunColor.Y, sunColor.Z));

            effect.SetDirectionToSun(MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized());

            effect.SetAmbientColor(Vector3.Zero);
            effect.SetReflectorPosition(MyCamera.Position - 4 * MySession.PlayerShip.WorldMatrix.Forward);

            if (MySession.PlayerShip.Light != null)
            {
                effect.SetNearLightColor(MySession.PlayerShip.Light.Color);
                effect.SetNearLightRange(MySession.PlayerShip.Light.Range);
            }

            MyRender.GetShadowRenderer().SetupShadowBaseEffect(effect);
            effect.SetShadowBias(0.001f);

            m_boundingSphereForLights.Center = MySession.PlayerShip.GetPosition();
            MyLights.UpdateEffect(effect, ref m_boundingSphereForLights, true);

            effect.Begin();
            model.Render();
            effect.End();

            MyCockpitGlassDecals.Draw(effect);
        }