Ejemplo n.º 1
0
        public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer, int value, Color color, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
        {
            if (environmentData.SubsystemTerrain == null)
            {
                return;
            }
            int             designIndex = GetDesignIndex(Terrain.ExtractData(value));
            FurnitureDesign design      = environmentData.SubsystemTerrain.SubsystemFurnitureBlockBehavior.GetDesign(designIndex);

            if (design == null)
            {
                return;
            }
            Vector3 v = default(Vector3);

            v.X = -0.5f * (float)(design.Box.Left + design.Box.Right) / (float)design.Resolution;
            v.Y = -0.5f * (float)(design.Box.Top + design.Box.Bottom) / (float)design.Resolution;
            v.Z = -0.5f * (float)(design.Box.Near + design.Box.Far) / (float)design.Resolution;
            Matrix            matrix2  = Matrix.CreateTranslation(v * size) * matrix;
            FurnitureGeometry geometry = design.Geometry;

            for (int i = 0; i < 6; i++)
            {
                float s      = LightingManager.LightIntensityByLightValueAndFace[environmentData.Light + 16 * CellFace.OppositeFace(i)];
                Color color2 = Color.MultiplyColorOnly(color, s);
                if (geometry.SubsetOpaqueByFace[i] != null)
                {
                    BlocksManager.DrawMeshBlock(primitivesRenderer, geometry.SubsetOpaqueByFace[i], color2, size, ref matrix2, environmentData);
                }
                if (geometry.SubsetAlphaTestByFace[i] != null)
                {
                    BlocksManager.DrawMeshBlock(primitivesRenderer, geometry.SubsetAlphaTestByFace[i], color2, size, ref matrix2, environmentData);
                }
            }
        }
Ejemplo n.º 2
0
        public static void DrawFlatBlock(PrimitivesRenderer3D primitivesRenderer, int value, float size, ref Matrix matrix, Texture2D texture, Color color, bool isEmissive, DrawBlockEnvironmentData environmentData)
        {
            environmentData = (environmentData ?? m_defaultEnvironmentData);
            if (!isEmissive)
            {
                float s = LightingManager.LightIntensityByLightValue[environmentData.Light];
                color = Color.MultiplyColorOnly(color, s);
            }
            Vector3 translation = matrix.Translation;
            Vector3 vector;
            Vector3 v;

            if (environmentData.BillboardDirection.HasValue)
            {
                vector = Vector3.Normalize(Vector3.Cross(environmentData.BillboardDirection.Value, Vector3.UnitY));
                v      = -Vector3.Normalize(Vector3.Cross(environmentData.BillboardDirection.Value, vector));
            }
            else
            {
                vector = matrix.Right;
                v      = matrix.Up;
            }
            Vector3 v2 = translation + 0.85f * size * (-vector - v);
            Vector3 v3 = translation + 0.85f * size * (vector - v);
            Vector3 v4 = translation + 0.85f * size * (-vector + v);
            Vector3 v5 = translation + 0.85f * size * (vector + v);

            if (environmentData.ViewProjectionMatrix.HasValue)
            {
                Matrix m = environmentData.ViewProjectionMatrix.Value;
                Vector3.Transform(ref v2, ref m, out v2);
                Vector3.Transform(ref v3, ref m, out v3);
                Vector3.Transform(ref v4, ref m, out v4);
                Vector3.Transform(ref v5, ref m, out v5);
            }
            int     num   = Terrain.ExtractContents(value);
            Block   block = Blocks[num];
            Vector4 vector2;

            if (texture != null)
            {
                vector2 = new Vector4(0f, 0f, 1f, 1f);
            }
            else
            {
                texture = ((environmentData.SubsystemTerrain != null) ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture : BlocksTexturesManager.DefaultBlocksTexture);
                vector2 = m_slotTexCoords[block.GetFaceTextureSlot(-1, value)];
            }
            TexturedBatch3D texturedBatch3D = primitivesRenderer.TexturedBatch(texture, useAlphaTest: true, 0, null, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp);

            texturedBatch3D.QueueQuad(v2, v4, v5, v3, new Vector2(vector2.X, vector2.W), new Vector2(vector2.X, vector2.Y), new Vector2(vector2.Z, vector2.Y), new Vector2(vector2.Z, vector2.W), color);
            if (!environmentData.BillboardDirection.HasValue)
            {
                texturedBatch3D.QueueQuad(v2, v3, v5, v4, new Vector2(vector2.X, vector2.W), new Vector2(vector2.Z, vector2.W), new Vector2(vector2.Z, vector2.Y), new Vector2(vector2.X, vector2.Y), color);
            }
        }
Ejemplo n.º 3
0
        public static void DrawCubeBlock(PrimitivesRenderer3D primitivesRenderer, int value, Vector3 size, ref Matrix matrix, Color color, Color topColor, DrawBlockEnvironmentData environmentData)
        {
            environmentData = (environmentData ?? m_defaultEnvironmentData);
            Texture2D       texture         = (environmentData.SubsystemTerrain != null) ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture : BlocksTexturesManager.DefaultBlocksTexture;
            TexturedBatch3D texturedBatch3D = primitivesRenderer.TexturedBatch(texture, useAlphaTest: true, 0, null, RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp);
            float           s = LightingManager.LightIntensityByLightValue[environmentData.Light];

            color    = Color.MultiplyColorOnly(color, s);
            topColor = Color.MultiplyColorOnly(topColor, s);
            Vector3 translation = matrix.Translation;
            Vector3 vector      = matrix.Right * size.X;
            Vector3 v           = matrix.Up * size.Y;
            Vector3 v2          = matrix.Forward * size.Z;
            Vector3 v3          = translation + 0.5f * (-vector - v - v2);
            Vector3 v4          = translation + 0.5f * (vector - v - v2);
            Vector3 v5          = translation + 0.5f * (-vector + v - v2);
            Vector3 v6          = translation + 0.5f * (vector + v - v2);
            Vector3 v7          = translation + 0.5f * (-vector - v + v2);
            Vector3 v8          = translation + 0.5f * (vector - v + v2);
            Vector3 v9          = translation + 0.5f * (-vector + v + v2);
            Vector3 v10         = translation + 0.5f * (vector + v + v2);

            if (environmentData.ViewProjectionMatrix.HasValue)
            {
                Matrix m = environmentData.ViewProjectionMatrix.Value;
                Vector3.Transform(ref v3, ref m, out v3);
                Vector3.Transform(ref v4, ref m, out v4);
                Vector3.Transform(ref v5, ref m, out v5);
                Vector3.Transform(ref v6, ref m, out v6);
                Vector3.Transform(ref v7, ref m, out v7);
                Vector3.Transform(ref v8, ref m, out v8);
                Vector3.Transform(ref v9, ref m, out v9);
                Vector3.Transform(ref v10, ref m, out v10);
            }
            int     num     = Terrain.ExtractContents(value);
            Block   block   = Blocks[num];
            Vector4 vector2 = m_slotTexCoords[block.GetFaceTextureSlot(0, value)];

            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Forward)), p1: v3, p2: v5, p3: v6, p4: v4, texCoord1: new Vector2(vector2.X, vector2.W), texCoord2: new Vector2(vector2.X, vector2.Y), texCoord3: new Vector2(vector2.Z, vector2.Y), texCoord4: new Vector2(vector2.Z, vector2.W));
            vector2 = m_slotTexCoords[block.GetFaceTextureSlot(2, value)];
            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Forward)), p1: v7, p2: v8, p3: v10, p4: v9, texCoord1: new Vector2(vector2.Z, vector2.W), texCoord2: new Vector2(vector2.X, vector2.W), texCoord3: new Vector2(vector2.X, vector2.Y), texCoord4: new Vector2(vector2.Z, vector2.Y));
            vector2 = m_slotTexCoords[block.GetFaceTextureSlot(5, value)];
            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Up)), p1: v3, p2: v4, p3: v8, p4: v7, texCoord1: new Vector2(vector2.X, vector2.Y), texCoord2: new Vector2(vector2.Z, vector2.Y), texCoord3: new Vector2(vector2.Z, vector2.W), texCoord4: new Vector2(vector2.X, vector2.W));
            vector2 = m_slotTexCoords[block.GetFaceTextureSlot(4, value)];
            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(topColor, LightingManager.CalculateLighting(matrix.Up)), p1: v5, p2: v9, p3: v10, p4: v6, texCoord1: new Vector2(vector2.X, vector2.W), texCoord2: new Vector2(vector2.X, vector2.Y), texCoord3: new Vector2(vector2.Z, vector2.Y), texCoord4: new Vector2(vector2.Z, vector2.W));
            vector2 = m_slotTexCoords[block.GetFaceTextureSlot(1, value)];
            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Right)), p1: v3, p2: v7, p3: v9, p4: v5, texCoord1: new Vector2(vector2.Z, vector2.W), texCoord2: new Vector2(vector2.X, vector2.W), texCoord3: new Vector2(vector2.X, vector2.Y), texCoord4: new Vector2(vector2.Z, vector2.Y));
            vector2 = m_slotTexCoords[block.GetFaceTextureSlot(3, value)];
            texturedBatch3D.QueueQuad(color: Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Right)), p1: v4, p2: v6, p3: v10, p4: v8, texCoord1: new Vector2(vector2.X, vector2.W), texCoord2: new Vector2(vector2.X, vector2.Y), texCoord3: new Vector2(vector2.Z, vector2.Y), texCoord4: new Vector2(vector2.Z, vector2.W));
        }
Ejemplo n.º 4
0
        public BlockDebrisParticleSystem(SubsystemTerrain terrain, Vector3 position, float strength, float scale, Color color, int textureSlot)
            : base((int)(50f * strength))
        {
            m_subsystemTerrain = terrain;
            base.Texture       = terrain.Project.FindSubsystem <SubsystemBlocksTexture>(throwOnError: true).BlocksTexture;
            int num  = Terrain.ToCell(position.X);
            int num2 = Terrain.ToCell(position.Y);
            int num3 = Terrain.ToCell(position.Z);
            int x    = 0;

            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num + 1, num2, num3));
            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num - 1, num2, num3));
            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2 + 1, num3));
            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2 - 1, num3));
            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2, num3 + 1));
            x = MathUtils.Max(x, terrain.Terrain.GetCellLight(num, num2, num3 - 1));
            base.TextureSlotsCount = 32;
            float num4 = LightingManager.LightIntensityByLightValue[x];

            color  *= num4;
            color.A = byte.MaxValue;
            float num5 = MathUtils.Sqrt(strength);

            for (int i = 0; i < base.Particles.Length; i++)
            {
                Particle obj = base.Particles[i];
                obj.IsActive = true;
                Vector3 vector = new Vector3(m_random.Float(-1f, 1f), m_random.Float(-1f, 1f), m_random.Float(-1f, 1f));
                obj.Position    = position + strength * 0.45f * vector;
                obj.Color       = Color.MultiplyColorOnly(color, m_random.Float(0.7f, 1f));
                obj.Size        = num5 * scale * new Vector2(m_random.Float(0.05f, 0.06f));
                obj.TimeToLive  = num5 * m_random.Float(1f, 3f);
                obj.Velocity    = num5 * 2f * (vector + new Vector3(m_random.Float(-0.2f, 0.2f), 0.6f, m_random.Float(-0.2f, 0.2f)));
                obj.TextureSlot = textureSlot % 16 * 2 + m_random.Int(0, 1) + 32 * (textureSlot / 16 * 2 + m_random.Int(0, 1));
            }
        }
Ejemplo n.º 5
0
        public override bool Simulate(float dt)
        {
            int num  = Terrain.ToCell(Position.X);
            int num2 = Terrain.ToCell(Position.Y);
            int num3 = Terrain.ToCell(Position.Z);
            int x    = 0;

            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num + 1, num2, num3));
            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num - 1, num2, num3));
            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2 + 1, num3));
            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2 - 1, num3));
            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2, num3 + 1));
            x = MathUtils.Max(x, m_subsystemTerrain.Terrain.GetCellLight(num, num2, num3 - 1));
            Color white = Color.White;
            float num4  = LightingManager.LightIntensityByLightValue[x];

            white  *= num4;
            white.A = byte.MaxValue;
            dt      = MathUtils.Clamp(dt, 0f, 0.1f);
            float num5 = MathUtils.Pow(0.03f, dt);

            m_duration += dt;
            if (m_duration > 3.5f)
            {
                IsStopped = true;
            }
            float num6 = MathUtils.Saturate(1.3f * SimplexNoise.Noise(3f * m_duration + (float)(GetHashCode() % 100)) - 0.3f);
            float num7 = 30f * num6;

            m_toGenerate += num7 * dt;
            bool flag = false;

            for (int i = 0; i < base.Particles.Length; i++)
            {
                Particle particle = base.Particles[i];
                if (particle.IsActive)
                {
                    flag = true;
                    particle.TimeToLive -= dt;
                    if (particle.TimeToLive > 0f)
                    {
                        Vector3 position = particle.Position;
                        Vector3 vector   = position + particle.Velocity * dt;
                        TerrainRaycastResult?terrainRaycastResult = m_subsystemTerrain.Raycast(position, vector, useInteractionBoxes: false, skipAirBlocks: true, (int value, float distance) => BlocksManager.Blocks[Terrain.ExtractContents(value)].IsCollidable);
                        if (terrainRaycastResult.HasValue)
                        {
                            Plane plane = terrainRaycastResult.Value.CellFace.CalculatePlane();
                            vector = position;
                            if (plane.Normal.X != 0f)
                            {
                                particle.Velocity *= new Vector3(-0.05f, 0.05f, 0.05f);
                            }
                            if (plane.Normal.Y != 0f)
                            {
                                particle.Velocity *= new Vector3(0.05f, -0.05f, 0.05f);
                            }
                            if (plane.Normal.Z != 0f)
                            {
                                particle.Velocity *= new Vector3(0.05f, 0.05f, -0.05f);
                            }
                        }
                        particle.Position    = vector;
                        particle.Velocity.Y += -9.81f * dt;
                        particle.Velocity   *= num5;
                        particle.Color      *= MathUtils.Saturate(particle.TimeToLive);
                        particle.TextureSlot = (int)(8.99f * MathUtils.Saturate(3f - particle.TimeToLive));
                    }
                    else
                    {
                        particle.IsActive = false;
                    }
                }
                else if (!IsStopped && m_toGenerate >= 1f)
                {
                    Vector3 v = m_random.Vector3(0f, 1f);
                    particle.IsActive   = true;
                    particle.Position   = Position + 0.05f * v;
                    particle.Color      = Color.MultiplyColorOnly(white, m_random.Float(0.7f, 1f));
                    particle.Velocity   = MathUtils.Lerp(1f, 2.5f, num6) * Vector3.Normalize(Direction + 0.25f * v);
                    particle.TimeToLive = 3f;
                    particle.Size       = new Vector2(0.1f);
                    particle.FlipX      = m_random.Bool();
                    particle.FlipY      = m_random.Bool();
                    m_toGenerate       -= 1f;
                }
            }
            if (IsStopped)
            {
                return(!flag);
            }
            return(false);
        }
Ejemplo n.º 6
0
 public void Draw(Camera camera, int drawOrder)
 {
     if (drawOrder == m_drawOrders[0])
     {
         ViewUnderWaterDepth = 0f;
         ViewUnderMagmaDepth = 0f;
         Vector3    viewPosition = camera.ViewPosition;
         int        x            = Terrain.ToCell(viewPosition.X);
         int        y            = Terrain.ToCell(viewPosition.Y);
         int        z            = Terrain.ToCell(viewPosition.Z);
         FluidBlock surfaceFluidBlock;
         float?     surfaceHeight = m_subsystemFluidBlockBehavior.GetSurfaceHeight(x, y, z, out surfaceFluidBlock);
         if (surfaceHeight.HasValue)
         {
             if (surfaceFluidBlock is WaterBlock)
             {
                 ViewUnderWaterDepth = surfaceHeight.Value + 0.1f - viewPosition.Y;
             }
             else if (surfaceFluidBlock is MagmaBlock)
             {
                 ViewUnderMagmaDepth = surfaceHeight.Value + 1f - viewPosition.Y;
             }
         }
         if (ViewUnderWaterDepth > 0f)
         {
             int   seasonalHumidity = m_subsystemTerrain.Terrain.GetSeasonalHumidity(x, z);
             int   temperature      = m_subsystemTerrain.Terrain.GetSeasonalTemperature(x, z) + SubsystemWeather.GetTemperatureAdjustmentAtHeight(y);
             Color c    = BlockColorsMap.WaterColorsMap.Lookup(temperature, seasonalHumidity);
             float num  = MathUtils.Lerp(1f, 0.5f, (float)seasonalHumidity / 15f);
             float num2 = MathUtils.Lerp(1f, 0.2f, MathUtils.Saturate(0.075f * (ViewUnderWaterDepth - 2f)));
             float num3 = MathUtils.Lerp(0.33f, 1f, SkyLightIntensity);
             m_viewFogRange.X           = 0f;
             m_viewFogRange.Y           = MathUtils.Lerp(4f, 10f, num * num2 * num3);
             m_viewFogColor             = Color.MultiplyColorOnly(c, 0.66f * num2 * num3);
             VisibilityRangeYMultiplier = 1f;
             m_viewIsSkyVisible         = false;
         }
         else if (ViewUnderMagmaDepth > 0f)
         {
             m_viewFogRange.X           = 0f;
             m_viewFogRange.Y           = 0.1f;
             m_viewFogColor             = new Color(255, 80, 0);
             VisibilityRangeYMultiplier = 1f;
             m_viewIsSkyVisible         = false;
         }
         else
         {
             float num4 = 1024f;
             float num5 = 128f;
             int   seasonalTemperature = m_subsystemTerrain.Terrain.GetSeasonalTemperature(Terrain.ToCell(viewPosition.X), Terrain.ToCell(viewPosition.Z));
             float num6 = MathUtils.Lerp(0.5f, 0f, m_subsystemWeather.GlobalPrecipitationIntensity);
             float num7 = MathUtils.Lerp(1f, 0.8f, m_subsystemWeather.GlobalPrecipitationIntensity);
             m_viewFogRange.X           = VisibilityRange * num6;
             m_viewFogRange.Y           = VisibilityRange * num7;
             m_viewFogColor             = CalculateSkyColor(new Vector3(camera.ViewDirection.X, 0f, camera.ViewDirection.Z), m_subsystemTimeOfDay.TimeOfDay, m_subsystemWeather.GlobalPrecipitationIntensity, seasonalTemperature);
             VisibilityRangeYMultiplier = MathUtils.Lerp(VisibilityRange / num4, VisibilityRange / num5, MathUtils.Pow(m_subsystemWeather.GlobalPrecipitationIntensity, 4f));
             m_viewIsSkyVisible         = true;
         }
         if (!FogEnabled)
         {
             m_viewFogRange = new Vector2(100000f, 100000f);
         }
         if (!DrawSkyEnabled || !m_viewIsSkyVisible || SettingsManager.SkyRenderingMode == SkyRenderingMode.Disabled)
         {
             FlatBatch2D flatBatch2D = m_primitivesRenderer2d.FlatBatch(-1, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.Opaque);
             int         count       = flatBatch2D.TriangleVertices.Count;
             flatBatch2D.QueueQuad(Vector2.Zero, camera.ViewportSize, 0f, m_viewFogColor);
             flatBatch2D.TransformTriangles(camera.ViewportMatrix, count);
             m_primitivesRenderer2d.Flush();
         }
     }
     else if (drawOrder == m_drawOrders[1])
     {
         if (DrawSkyEnabled && m_viewIsSkyVisible && SettingsManager.SkyRenderingMode != SkyRenderingMode.Disabled)
         {
             DrawSkydome(camera);
             DrawStars(camera);
             DrawSunAndMoon(camera);
             DrawClouds(camera);
             m_primitivesRenderer3d.Flush(camera.ViewProjectionMatrix);
         }
     }
     else
     {
         DrawLightning(camera);
         m_primitivesRenderer3d.Flush(camera.ViewProjectionMatrix);
     }
 }
Ejemplo n.º 7
0
        public override void Draw(DrawContext dc)
        {
            BaseBatch baseBatch = (BarSubtexture == null) ? ((BaseBatch)dc.PrimitivesRenderer2D.FlatBatch(0, DepthStencilState.None)) : ((BaseBatch)dc.PrimitivesRenderer2D.TexturedBatch(BarSubtexture.Texture, useAlphaTest: false, 0, DepthStencilState.None, null, null, TextureLinearFilter ? SamplerState.LinearClamp : SamplerState.PointClamp));
            int       num       = 0;
            int       start     = 0;

            if (baseBatch is TexturedBatch2D)
            {
                num = ((TexturedBatch2D)baseBatch).TriangleVertices.Count;
            }
            else
            {
                start = ((FlatBatch2D)baseBatch).LineVertices.Count;
                num   = ((FlatBatch2D)baseBatch).TriangleVertices.Count;
            }
            Vector2 zero = Vector2.Zero;

            if (m_layoutDirection == LayoutDirection.Horizontal)
            {
                zero.X += Spacing / 2f;
            }
            else
            {
                zero.Y += Spacing / 2f;
            }
            int num2 = HalfBars ? 1 : 2;

            for (int i = 0; i < 2 * BarsCount; i += num2)
            {
                bool  flag = i % 2 == 0;
                float num3 = 0.5f * (float)i;
                float num4 = 0f;
                num4 = ((!FlipDirection) ? MathUtils.Clamp((Value - num3 / (float)BarsCount) * (float)BarsCount, 0f, 1f) : MathUtils.Clamp((Value - ((float)BarsCount - num3 - 1f) / (float)BarsCount) * (float)BarsCount, 0f, 1f));
                if (!BarBlending)
                {
                    num4 = MathUtils.Ceiling(num4);
                }
                float s = (m_flashCount > 0f) ? (1f - MathUtils.Abs(MathUtils.Sin(m_flashCount * (float)Math.PI))) : 1f;
                Color c = LitBarColor;
                if (LitBarColor2 != Color.Transparent && BarsCount > 1)
                {
                    c = Color.Lerp(LitBarColor, LitBarColor2, num3 / (float)(BarsCount - 1));
                }
                Color color = Color.Lerp(UnlitBarColor, c, num4) * s * base.GlobalColorTransform;
                if (HalfBars)
                {
                    if (flag)
                    {
                        Vector2 zero2 = Vector2.Zero;
                        Vector2 v     = (m_layoutDirection == LayoutDirection.Horizontal) ? new Vector2(0.5f, 1f) : new Vector2(1f, 0.5f);
                        if (baseBatch is TexturedBatch2D)
                        {
                            Vector2 topLeft  = BarSubtexture.TopLeft;
                            Vector2 texCoord = new Vector2(MathUtils.Lerp(BarSubtexture.TopLeft.X, BarSubtexture.BottomRight.X, v.X), MathUtils.Lerp(BarSubtexture.TopLeft.Y, BarSubtexture.BottomRight.Y, v.Y));
                            ((TexturedBatch2D)baseBatch).QueueQuad(zero + zero2 * BarSize, zero + v * BarSize, 0f, topLeft, texCoord, color);
                        }
                        else
                        {
                            ((FlatBatch2D)baseBatch).QueueQuad(zero + zero2 * BarSize, zero + v * BarSize, 0f, color);
                        }
                    }
                    else
                    {
                        Vector2 v2  = (m_layoutDirection == LayoutDirection.Horizontal) ? new Vector2(0.5f, 0f) : new Vector2(0f, 0.5f);
                        Vector2 one = Vector2.One;
                        if (baseBatch is TexturedBatch2D)
                        {
                            Vector2 texCoord2   = new Vector2(MathUtils.Lerp(BarSubtexture.TopLeft.X, BarSubtexture.BottomRight.X, v2.X), MathUtils.Lerp(BarSubtexture.TopLeft.Y, BarSubtexture.BottomRight.Y, v2.Y));
                            Vector2 bottomRight = BarSubtexture.BottomRight;
                            ((TexturedBatch2D)baseBatch).QueueQuad(zero + v2 * BarSize, zero + one * BarSize, 0f, texCoord2, bottomRight, color);
                        }
                        else
                        {
                            ((FlatBatch2D)baseBatch).QueueQuad(zero + v2 * BarSize, zero + one * BarSize, 0f, color);
                        }
                    }
                }
                else
                {
                    Vector2 zero3 = Vector2.Zero;
                    Vector2 one2  = Vector2.One;
                    if (baseBatch is TexturedBatch2D)
                    {
                        Vector2 topLeft2     = BarSubtexture.TopLeft;
                        Vector2 bottomRight2 = BarSubtexture.BottomRight;
                        ((TexturedBatch2D)baseBatch).QueueQuad(zero + zero3 * BarSize, zero + one2 * BarSize, 0f, topLeft2, bottomRight2, color);
                    }
                    else
                    {
                        ((FlatBatch2D)baseBatch).QueueQuad(zero + zero3 * BarSize, zero + one2 * BarSize, 0f, color);
                        ((FlatBatch2D)baseBatch).QueueRectangle(zero + zero3 * BarSize, zero + one2 * BarSize, 0f, Color.MultiplyColorOnly(color, 0.75f));
                    }
                }
                if (!flag || !HalfBars)
                {
                    if (m_layoutDirection == LayoutDirection.Horizontal)
                    {
                        zero.X += BarSize.X + Spacing;
                    }
                    else
                    {
                        zero.Y += BarSize.Y + Spacing;
                    }
                }
            }
            if (baseBatch is TexturedBatch2D)
            {
                ((TexturedBatch2D)baseBatch).TransformTriangles(base.GlobalTransform, num);
            }
            else
            {
                ((FlatBatch2D)baseBatch).TransformLines(base.GlobalTransform, start);
                ((FlatBatch2D)baseBatch).TransformTriangles(base.GlobalTransform, num);
            }
            m_flashCount = MathUtils.Max(m_flashCount - 4f * Time.FrameDuration, 0f);
        }
Ejemplo n.º 8
0
        public static void DrawFlatBlock(PrimitivesRenderer3D primitivesRenderer, int value, float size,
                                         ref Matrix matrix, Texture2D texture, Color color, bool isEmissive,
                                         DrawBlockEnvironmentData environmentData)
        {
            environmentData = environmentData ?? m_defaultEnvironmentData;
            if (!isEmissive)
            {
                color = Color.MultiplyColorOnly(color, LightingManager.LightIntensityByLightValue[environmentData.Light]);
            }

            var     translation = matrix.Translation;
            Vector3 v2;
            Vector3 vector3;

            if (environmentData.BillboardDirection.HasValue)
            {
                v2      = Vector3.Normalize(Vector3.Cross(environmentData.BillboardDirection.Value, Vector3.UnitY));
                vector3 = -Vector3.Normalize(Vector3.Cross(environmentData.BillboardDirection.Value, v2));
            }
            else
            {
                v2      = matrix.Right;
                vector3 = matrix.Up;
            }

            var result1 = translation + 0.85f * size * (-v2 - vector3);
            var result2 = translation + 0.85f * size * (v2 - vector3);
            var result3 = translation + 0.85f * size * (-v2 + vector3);
            var result4 = translation + 0.85f * size * (v2 + vector3);

            if (environmentData.ViewProjectionMatrix.HasValue)
            {
                var m = environmentData.ViewProjectionMatrix.Value;
                Vector3.Transform(ref result1, ref m, out result1);
                Vector3.Transform(ref result2, ref m, out result2);
                Vector3.Transform(ref result3, ref m, out result3);
                Vector3.Transform(ref result4, ref m, out result4);
            }

            var     block = Blocks[Terrain.ExtractContents(value)];
            Vector4 vector4;

            if (texture == null)
            {
                texture = environmentData.SubsystemTerrain != null
                                        ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture
                                        : BlocksTexturesManager.DefaultBlocksTexture;
                vector4 = m_slotTexCoords[block.GetFaceTextureSlot(-1, value)];
            }
            else
            {
                vector4 = new Vector4(0.0f, 0.0f, 1f, 1f);
            }

            var texturedBatch3D = primitivesRenderer.TexturedBatch(texture, true, 0, null,
                                                                   RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp);

            texturedBatch3D.QueueQuad(result1, result3, result4, result2, new Vector2(vector4.X, vector4.W),
                                      new Vector2(vector4.X, vector4.Y), new Vector2(vector4.Z, vector4.Y), new Vector2(vector4.Z, vector4.W),
                                      color);
            if (environmentData.BillboardDirection.HasValue)
            {
                return;
            }
            texturedBatch3D.QueueQuad(result1, result2, result4, result3, new Vector2(vector4.X, vector4.W),
                                      new Vector2(vector4.Z, vector4.W), new Vector2(vector4.Z, vector4.Y), new Vector2(vector4.X, vector4.Y),
                                      color);
        }
Ejemplo n.º 9
0
        public static void DrawCubeBlock(PrimitivesRenderer3D primitivesRenderer, int value, Vector3 size,
                                         ref Matrix matrix, Color color, Color topColor, DrawBlockEnvironmentData environmentData)
        {
            environmentData = environmentData ?? m_defaultEnvironmentData;
            var texture = environmentData.SubsystemTerrain != null
                                ? environmentData.SubsystemTerrain.SubsystemAnimatedTextures.AnimatedBlocksTexture
                                : BlocksTexturesManager.DefaultBlocksTexture;
            var texturedBatch3D = primitivesRenderer.TexturedBatch(texture, true, 0, null,
                                                                   RasterizerState.CullCounterClockwiseScissor, null, SamplerState.PointClamp);
            var s = LightingManager.LightIntensityByLightValue[environmentData.Light];

            color    = Color.MultiplyColorOnly(color, s);
            topColor = Color.MultiplyColorOnly(topColor, s);
            var translation = matrix.Translation;
            var vector3_1   = matrix.Right * size.X;
            var vector3_2   = matrix.Up * size.Y;
            var vector3_3   = matrix.Forward * size.Z;
            var result1     = translation + 0.5f * (-vector3_1 - vector3_2 - vector3_3);
            var result2     = translation + 0.5f * (vector3_1 - vector3_2 - vector3_3);
            var result3     = translation + 0.5f * (-vector3_1 + vector3_2 - vector3_3);
            var result4     = translation + 0.5f * (vector3_1 + vector3_2 - vector3_3);
            var result5     = translation + 0.5f * (-vector3_1 - vector3_2 + vector3_3);
            var result6     = translation + 0.5f * (vector3_1 - vector3_2 + vector3_3);
            var result7     = translation + 0.5f * (-vector3_1 + vector3_2 + vector3_3);
            var result8     = translation + 0.5f * (vector3_1 + vector3_2 + vector3_3);

            if (environmentData.ViewProjectionMatrix.HasValue)
            {
                var m = environmentData.ViewProjectionMatrix.Value;
                Vector3.Transform(ref result1, ref m, out result1);
                Vector3.Transform(ref result2, ref m, out result2);
                Vector3.Transform(ref result3, ref m, out result3);
                Vector3.Transform(ref result4, ref m, out result4);
                Vector3.Transform(ref result5, ref m, out result5);
                Vector3.Transform(ref result6, ref m, out result6);
                Vector3.Transform(ref result7, ref m, out result7);
                Vector3.Transform(ref result8, ref m, out result8);
            }

            var block         = Blocks[Terrain.ExtractContents(value)];
            var slotTexCoord1 = m_slotTexCoords[block.GetFaceTextureSlot(0, value)];
            var color1        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Forward));

            texturedBatch3D.QueueQuad(result1, result3, result4, result2, new Vector2(slotTexCoord1.X, slotTexCoord1.W),
                                      new Vector2(slotTexCoord1.X, slotTexCoord1.Y), new Vector2(slotTexCoord1.Z, slotTexCoord1.Y),
                                      new Vector2(slotTexCoord1.Z, slotTexCoord1.W), color1);
            var slotTexCoord2 = m_slotTexCoords[block.GetFaceTextureSlot(2, value)];
            var color2        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Forward));

            texturedBatch3D.QueueQuad(result5, result6, result8, result7, new Vector2(slotTexCoord2.Z, slotTexCoord2.W),
                                      new Vector2(slotTexCoord2.X, slotTexCoord2.W), new Vector2(slotTexCoord2.X, slotTexCoord2.Y),
                                      new Vector2(slotTexCoord2.Z, slotTexCoord2.Y), color2);
            var slotTexCoord3 = m_slotTexCoords[block.GetFaceTextureSlot(5, value)];
            var color3        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Up));

            texturedBatch3D.QueueQuad(result1, result2, result6, result5, new Vector2(slotTexCoord3.X, slotTexCoord3.Y),
                                      new Vector2(slotTexCoord3.Z, slotTexCoord3.Y), new Vector2(slotTexCoord3.Z, slotTexCoord3.W),
                                      new Vector2(slotTexCoord3.X, slotTexCoord3.W), color3);
            var slotTexCoord4 = m_slotTexCoords[block.GetFaceTextureSlot(4, value)];
            var color4        = Color.MultiplyColorOnly(topColor, LightingManager.CalculateLighting(matrix.Up));

            texturedBatch3D.QueueQuad(result3, result7, result8, result4, new Vector2(slotTexCoord4.X, slotTexCoord4.W),
                                      new Vector2(slotTexCoord4.X, slotTexCoord4.Y), new Vector2(slotTexCoord4.Z, slotTexCoord4.Y),
                                      new Vector2(slotTexCoord4.Z, slotTexCoord4.W), color4);
            var slotTexCoord5 = m_slotTexCoords[block.GetFaceTextureSlot(1, value)];
            var color5        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(-matrix.Right));

            texturedBatch3D.QueueQuad(result1, result5, result7, result3, new Vector2(slotTexCoord5.Z, slotTexCoord5.W),
                                      new Vector2(slotTexCoord5.X, slotTexCoord5.W), new Vector2(slotTexCoord5.X, slotTexCoord5.Y),
                                      new Vector2(slotTexCoord5.Z, slotTexCoord5.Y), color5);
            var slotTexCoord6 = m_slotTexCoords[block.GetFaceTextureSlot(3, value)];
            var color6        = Color.MultiplyColorOnly(color, LightingManager.CalculateLighting(matrix.Right));

            texturedBatch3D.QueueQuad(result2, result4, result8, result6, new Vector2(slotTexCoord6.X, slotTexCoord6.W),
                                      new Vector2(slotTexCoord6.X, slotTexCoord6.Y), new Vector2(slotTexCoord6.Z, slotTexCoord6.Y),
                                      new Vector2(slotTexCoord6.Z, slotTexCoord6.W), color6);
        }
Ejemplo n.º 10
0
        public void DrawIceOverlay(Camera camera, float factor)
        {
            Vector2 viewportSize = camera.ViewportSize;
            float   s            = camera.Eye.HasValue ? 1.3f : 1f;
            float   num          = camera.Eye.HasValue ? MathUtils.Pow(factor, 0.4f) : factor;
            Vector2 v            = camera.Eye.HasValue ? viewportSize : new Vector2(1f);
            float   num2         = v.Length();
            Point2  point        = new Point2((int)MathUtils.Round(12f * viewportSize.X / viewportSize.Y), (int)MathUtils.Round(12f));

            if (m_iceVertices == null || m_cellsCount != point)
            {
                m_cellsCount = point;
                m_random.Seed(0);
                m_iceVertices = new Vector2[(point.X + 1) * (point.Y + 1)];
                for (int i = 0; i <= point.X; i++)
                {
                    for (int j = 0; j <= point.Y; j++)
                    {
                        float num3 = i;
                        float num4 = j;
                        if (i != 0 && i != point.X)
                        {
                            num3 += m_random.Float(-0.4f, 0.4f);
                        }
                        if (j != 0 && j != point.Y)
                        {
                            num4 += m_random.Float(-0.4f, 0.4f);
                        }
                        float x = num3 / (float)point.X;
                        float y = num4 / (float)point.Y;
                        m_iceVertices[i + j * (point.X + 1)] = new Vector2(x, y);
                    }
                }
            }
            Vector3 vector  = Vector3.UnitX / camera.ProjectionMatrix.M11 * 2f * 0.2f * s;
            Vector3 vector2 = Vector3.UnitY / camera.ProjectionMatrix.M22 * 2f * 0.2f * s;
            Vector3 v2      = -0.2f * Vector3.UnitZ - 0.5f * (vector + vector2);

            if (!m_light.HasValue || Time.PeriodicEvent(0.05000000074505806, 0.0))
            {
                m_light = (LightingManager.CalculateSmoothLight(m_subsystemTerrain, camera.ViewPosition) ?? m_light ?? 1f);
            }
            Color color = Color.MultiplyColorOnly(Color.White, m_light.Value);

            m_random.Seed(0);
            Texture2D       texture         = ContentManager.Get <Texture2D>("Textures/IceOverlay");
            TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(texture, useAlphaTest: false, 0, DepthStencilState.None, RasterizerState.CullNoneScissor, BlendState.AlphaBlend, SamplerState.PointWrap);
            Vector2         v3      = new Vector2(viewportSize.X / viewportSize.Y, 1f);
            Vector2         vector3 = new Vector2(point.X - 1, point.Y - 1);

            for (int k = 0; k < point.X; k++)
            {
                for (int l = 0; l < point.Y; l++)
                {
                    float num5 = (new Vector2((float)(2 * k) / vector3.X - 1f, (float)(2 * l) / vector3.Y - 1f) * v).Length() / num2;
                    if (1f - num5 + m_random.Float(0f, 0.05f) < num)
                    {
                        Vector2 v4        = m_iceVertices[k + l * (point.X + 1)];
                        Vector2 v5        = m_iceVertices[k + 1 + l * (point.X + 1)];
                        Vector2 v6        = m_iceVertices[k + 1 + (l + 1) * (point.X + 1)];
                        Vector2 v7        = m_iceVertices[k + (l + 1) * (point.X + 1)];
                        Vector3 vector4   = v2 + v4.X * vector + v4.Y * vector2;
                        Vector3 p         = v2 + v5.X * vector + v5.Y * vector2;
                        Vector3 vector5   = v2 + v6.X * vector + v6.Y * vector2;
                        Vector3 p2        = v2 + v7.X * vector + v7.Y * vector2;
                        Vector2 vector6   = v4 * v3;
                        Vector2 texCoord  = v5 * v3;
                        Vector2 vector7   = v6 * v3;
                        Vector2 texCoord2 = v7 * v3;
                        texturedBatch3D.QueueTriangle(vector4, p, vector5, vector6, texCoord, vector7, color);
                        texturedBatch3D.QueueTriangle(vector5, p2, vector4, vector7, texCoord2, vector6, color);
                    }
                }
            }
            texturedBatch3D.Flush(camera.ProjectionMatrix);
        }