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);
                }
            }
예제 #2
0
        public override bool Draw(MyRenderObject renderObject)
        {
            if (Render.MyRender.GetCurrentLodDrawPass() == MyLodTypeEnum.LOD0)
            {
                if (IsDummyVisible())
                {
                    base.Draw(renderObject);

                    Vector4 color;
                    switch (DummyFlags)
                    {
                    case MyDummyPointFlags.NONE: color = new Vector4(0.5f, 0.7f, 0.1f, 0.3f); break;

                    case MyDummyPointFlags.SAFE_AREA: color = new Vector4(0.2f, 0.3f, 0.22f, 0.1f); break;

                    case MyDummyPointFlags.DETECTOR: color = new Vector4(0.12f, 0.1f, 0.7f, 0.3f); break;

                    case MyDummyPointFlags.PARTICLE: color = new Vector4(0.6f, 0.05f, 0.1f, 0.3f); break;

                    default: color = new Vector4(0.6f, 0.6f, 0.7f, 0.3f); break;
                    }
                    if ((DummyFlags & MyDummyPointFlags.COLOR_AREA) != 0)
                    {
                        color = Color;  // color Color areas with their area color (overriding the default color). I like to write "color".
                    }
                    Matrix worldMatrix = WorldMatrix;

                    if ((int)(DummyFlags & MyDummyPointFlags.TEXTURE_QUAD) > 0)
                    {
                        BoundingBox localAABB = LocalAABB;
                        MySimpleObjectDraw.DrawWireFramedBox(ref worldMatrix, ref localAABB, ref color, 0.01f, 1, LineMaterial);

                        if (!string.IsNullOrEmpty(Name))
                        {
                            //var tex = MinerWars.AppCode.Game.Textures.MyTextureManager.GetTexture<MinerWars.AppCode.Game.Textures.MyTexture2D>(Name);
                            int i = 0;
                            foreach (MyTransparentMaterialEnum trEnum in Enum.GetValues(typeof(MyTransparentMaterialEnum)))
                            {
                                if (MyTransparentMaterialConstants.MyTransparentMaterialStrings[i] == Name)
                                {
                                    Vector4 quadColor = Vector4.One;
                                    MyQuad  quad;
                                    Vector3 position     = GetPosition();
                                    Vector3 zeroPosition = Vector3.Zero;

                                    var   texture = MyTransparentGeometry.GetTexture(trEnum);
                                    float ratio   = texture.Height / (float)texture.Width;

                                    MyUtils.GenerateQuad(out quad, ref position, WorldAABB.Size().X *ratio, WorldAABB.Size().X, ref worldMatrix);
                                    MyTransparentGeometry.AddQuad(trEnum, ref quad, ref quadColor, ref position);
                                }
                                i++;
                            }
                        }
                    }
                    else
                    {
                        if (Type == MyDummyPointType.Box)
                        {
                            BoundingBox localAABB = LocalAABB;
                            MySimpleObjectDraw.DrawTransparentBox(ref worldMatrix, ref localAABB, ref color, true, 1, FaceMaterial, LineMaterial);
                        }
                        else
                        {
                            BoundingSphere localSphere = new BoundingSphere(worldMatrix.Translation, Radius);
                            MySimpleObjectDraw.DrawTransparentSphere(ref worldMatrix, localSphere.Radius, ref color, true, 12, FaceMaterial, LineMaterial);
                        }
                    }
                }

                if (ParticleEffect != null && IsVisible() && Enabled)
                {
                    Vector4 particleColor = Color == Vector4.Zero ? Vector4.One : Color;
                    ParticleEffect.UserColorMultiplier = particleColor;
                    ParticleEffect.UserScale           = UserScale;

                    UpdateWorldVolume();

                    MyParticlesManager.CustomDraw(ParticleEffect);
                }
            }

            return(false);
        }