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); } }
public void Draw(MyEffectDistantImpostors effect) { int trianglesCount = m_impostors.Count * MyDistantObjectsImpostorsConstants.TRIANGLES_PER_IMPOSTOR; if (trianglesCount <= 0) return; CopyToVertexBuffer(); Device device = MyMinerGame.Static.GraphicsDevice; RasterizerState.CullNone.Apply(); BlendState.NonPremultiplied.Apply(); DepthStencilState.None.Apply(); Matrix projection = Matrix.CreatePerspectiveFieldOfView(MyCamera.Zoom.GetFOV(), MyCamera.ForwardAspectRatio, 1000, 10000000); effect.SetWorldMatrix(Matrix.CreateTranslation(-MyCamera.Position)); effect.SetViewProjectionMatrix(MyCamera.ViewMatrix * projection); effect.SetSunDirection(-MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized()); for (int i = 0; i < m_impostorProperties.Length; i++) { effect.SetImpostorTexture(m_impostorProperties[i].Texture); effect.SetTechnique(m_impostorProperties[i].LitBySun ? MyEffectDistantImpostors.Technique.ColoredLit : MyEffectDistantImpostors.Technique.Colored); device.DrawUserPrimitives(PrimitiveType.TriangleList, m_impostorProperties[i].IndexStart, MyVoxelMapImpostorsConstants.TRIANGLES_PER_IMPOSTOR * m_impostorProperties[i].Count, m_vertices); } }
public void PrepareForDraw(MyEffectDistantImpostors effect) { if (!ImpostorProperties.Enabled) return; if (ImpostorProperties.ImpostorType == MyImpostorType.Nebula) { Matrix mat = Matrix.CreateScale(ImpostorProperties.MinDistance) * Matrix.CreateTranslation(MyCamera.Position * 0.5f); Matrix projection = Matrix.CreatePerspectiveFieldOfView(MyCamera.Zoom.GetFOV(), MyCamera.ForwardAspectRatio, 1000, 10000000); effect.SetWorldMatrix(mat); effect.SetViewProjectionMatrix(MyCamera.ViewMatrix * projection); effect.SetScale(ImpostorProperties.Radius * 0.00018f); effect.SetColor(ImpostorProperties.Color); effect.SetContrastAndIntensity(new Vector2(ImpostorProperties.Contrast, ImpostorProperties.Intensity)); effect.SetAnimation(m_animationTime); effect.SetCameraPos(MyCamera.Position); effect.SetSunDirection(-MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized()); effect.SetTechnique(MyEffectDistantImpostors.Technique.Textured3D); effect.Begin(); MySimpleObjectDraw.ModelSphere.Render(); effect.End(); } }