Esempio n. 1
0
        public static void DrawVrBackground()
        {
            Matrix          hmdMatrix = VrManager.HmdMatrix;
            TexturedBatch3D batch     = m_pr3.TexturedBatch(ContentManager.Get <Texture2D>("Textures/Star"));

            Random.Seed(0);
            for (int i = 0; i < 1500; i++)
            {
                float   f       = MathUtils.Pow(Random.Float(0f, 1f), 6f);
                Color   rGB     = (MathUtils.Lerp(0.05f, 0.4f, f) * Color.White).RGB;
                int     num     = 6;
                Vector3 vector  = Random.Vector3(500f);
                Vector3 vector2 = Vector3.Normalize(Vector3.Cross(vector, Vector3.UnitY)) * num;
                Vector3 up      = Vector3.Normalize(Vector3.Cross(vector2, vector)) * num;
                QueueQuad(batch, vector + hmdMatrix.Translation, vector2, up, rGB);
            }
            TexturedBatch3D batch2 = m_pr3.TexturedBatch(ContentManager.Get <Texture2D>("Textures/Blocks"), useAlphaTest: true, 1, null, null, null, SamplerState.PointClamp);

            for (int j = -8; j <= 8; j++)
            {
                for (int k = -8; k <= 8; k++)
                {
                    float   num2    = 1f;
                    float   num3    = 1f;
                    Vector3 vector3 = new Vector3(((float)j - 0.5f) * num2, 0f, ((float)k - 0.5f) * num2) + new Vector3(MathUtils.Round(hmdMatrix.Translation.X), 0f, MathUtils.Round(hmdMatrix.Translation.Z));
                    float   num4    = Vector3.Distance(vector3, hmdMatrix.Translation);
                    float   num5    = MathUtils.Lerp(1f, 0f, MathUtils.Saturate(num4 / 7f));
                    if (num5 > 0f)
                    {
                        QueueQuad(batch2, vector3, new Vector3(num3, 0f, 0f), new Vector3(0f, 0f, num3), Color.Gray * num5, new Vector2(0.1875f, 0.25f), new Vector2(0.25f, 0.3125f));
                    }
                }
            }
        }
Esempio n. 2
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);
        }