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 = MyRender.GraphicsDevice; 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 = (Vector3)MyRenderCamera.Position * 0.5f; effect.SetWorldMatrix(worldMatrix); MyTexture2D texture = null; if (ImpostorProperties.Material != null) { texture = MyTransparentGeometry.GetTexture(ImpostorProperties.Material); } 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.PerCameraDrawWrite.TotalDrawCalls++; } else if (ImpostorProperties.ImpostorType == MyImpostorType.Nebula) { m_animationTime += ImpostorProperties.AnimationSpeed * MyRenderConstants.RENDER_STEP_IN_MILLISECONDS / 20.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 = MyRender.GraphicsDevice; RasterizerState.CullNone.Apply(); BlendState.NonPremultiplied.Apply(); DepthStencilState.None.Apply(); Matrix projection = Matrix.CreatePerspectiveFieldOfView(MyRenderCamera.FieldOfView, MyRenderCamera.AspectRatio, 1000, 10000000); effect.SetWorldMatrix((Matrix)MatrixD.CreateTranslation(-MyRenderCamera.Position)); effect.SetViewProjectionMatrix((Matrix)MyRenderCamera.ViewMatrix * projection); effect.SetSunDirection(MyRender.Sun.Direction); device.VertexDeclaration = MyVertexFormatPositionTextureColor.VertexDeclaration; 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); effect.Begin(); device.DrawUserPrimitives(PrimitiveType.TriangleList, m_impostorProperties[i].IndexStart, MyVoxelMapImpostorsConstants.TRIANGLES_PER_IMPOSTOR * m_impostorProperties[i].Count, m_vertices); effect.End(); } }