public static void Draw(MyEffectCockpitGlass effect) { for (int i = 0; i < m_buffers.Length; i++) { if (m_buffers[i].GetTrianglesCount() <= 0) { continue; } int trianglesToDraw = m_buffers[i].CopyDecalsToVertices(m_vertices); if (trianglesToDraw <= 0) { continue; } effect.SetCockpitGlassTexture(m_texturesDiffuse[i]); effect.SetGlassDirtLevelAlpha(Vector4.UnitW); effect.Begin(); MyMinerGame.Static.GraphicsDevice.DrawUserPrimitives(SharpDX.Direct3D9.PrimitiveType.TriangleList, 0, trianglesToDraw, m_vertices); effect.End(); MyPerformanceCounter.PerCameraDraw.DecalsForCockipGlassInFrustum += trianglesToDraw; } }
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); }
public static void Draw() { if (!Visible) { return; } MyRenderModel model = MyRenderModels.GetModel(Model);//MySession.Static.PlayerShip.CockpitGlassModelEnum); RasterizerState.CullNone.Apply(); MyStateObjects.DepthStencil_StencilReadOnly.Apply(); BlendState.NonPremultiplied.Apply(); MyEffectCockpitGlass effect = (MyEffectCockpitGlass)MyRender.GetEffect(MyEffects.CockpitGlass); effect.SetGlassDirtLevelAlpha(new Vector4(GlassDirtAlpha, 0, 0, 0)); var inMatrix = PlayerHeadForCockpitInteriorWorldMatrix; MatrixD drawMatrix; MatrixD.Multiply(ref inMatrix, ref MyRenderCamera.InversePositionTranslationMatrix, out drawMatrix); effect.SetWorldMatrix((Matrix)drawMatrix); effect.SetViewMatrix((Matrix)MyRenderCamera.ViewMatrix); Matrix projection = MyRenderCamera.ProjectionMatrixForNearObjects; effect.SetWorldViewProjectionMatrix((Matrix)(drawMatrix * MyRenderCamera.ViewMatrixAtZero * projection)); MyRenderMeshMaterial cockpitMaterial = model.GetMeshList()[0].Material; cockpitMaterial.PreloadTexture(); effect.SetCockpitGlassTexture(cockpitMaterial.DiffuseTexture); Texture depthRT = MyRender.GetRenderTarget(MyRenderTargets.Depth); effect.SetDepthTexture(depthRT); effect.SetHalfPixel(MyUtilsRender9.GetHalfPixel(depthRT.GetLevelDescription(0).Width, depthRT.GetLevelDescription(0).Height)); Vector4 sunColor = MyRender.Sun.Color; effect.SetSunColor(new Vector3(sunColor.X, sunColor.Y, sunColor.Z)); effect.SetDirectionToSun(-MyRender.Sun.Direction); effect.SetAmbientColor(Vector3.Zero); effect.SetReflectorPosition((Vector3)((Vector3)MyRenderCamera.Position - 4 * MyRenderCamera.ForwardVector)); if (MyRender.RenderLightsForDraw.Count > 0) { effect.SetNearLightColor(MyRender.RenderLightsForDraw[0].Color); effect.SetNearLightRange(MyRender.RenderLightsForDraw[0].Range); } MyRender.GetShadowRenderer().SetupShadowBaseEffect(effect); effect.SetShadowBias(0.001f); MyLights.UpdateEffect(effect, true); effect.Begin(); model.Render(); effect.End(); //MyDebugDraw.DrawSphereWireframe(PlayerHeadForCockpitInteriorWorldMatrix, Vector3.One, 1); }