예제 #1
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);
            }
        }
예제 #2
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));
        }