Exemplo n.º 1
0
        private static void PushQuadAO(CUBE_FACES face, int x, int y, int z, int c1, int c2, int c3, int c4, Color color, List <VertexPositionColor> CurrentArray)
        {
            // Calculate AO in all corners and decide if inverted or not.

            float a00 = AOLookUp(face, x, y, z, c1);
            float a10 = AOLookUp(face, x, y, z, c2);
            float a11 = AOLookUp(face, x, y, z, c3);
            float a01 = AOLookUp(face, x, y, z, c4);

            if (a00 + a11 < a01 + a10)
            {
                PushTriangleAO(x, y, z, c1, c2, c3, color, a00, a10, a11, CurrentArray);
                PushTriangleAO(x, y, z, c1, c3, c4, color, a00, a11, a01, CurrentArray);
            }
            else
            {
                PushTriangleAO(x, y, z, c1, c2, c4, color, a00, a10, a01, CurrentArray);
                PushTriangleAO(x, y, z, c2, c3, c4, color, a10, a11, a01, CurrentArray);
            }
        }
Exemplo n.º 2
0
        private static float AOLookUp(CUBE_FACES face, int x, int y, int z, int vertex)
        {
            int corner = 0, side1 = 0, side2 = 0;

            if (face != CUBE_FACES.Top && face != CUBE_FACES.Bottom)
            {
                if (vertex == 0)
                {
                    side1 = back ? 0 : 1;
                    side2 = left ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x - 1, y, z - 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 1)
                {
                    side1 = right ? 0 : 1;
                    side2 = back ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x + 1, y, z - 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 2)
                {
                    side1 = front ? 0 : 1;
                    side2 = right ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x + 1, y, z + 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 3)
                {
                    side1 = left ? 0 : 1;
                    side2 = front ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x - 1, y, z + 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 4)
                {
                    side1 = back ? 0 : 1;
                    side2 = left ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x - 1, y, z - 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 5)
                {
                    side1 = right ? 0 : 1;
                    side2 = back ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x + 1, y, z - 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 6)
                {
                    side1 = front ? 0 : 1;
                    side2 = right ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x + 1, y, z + 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 7)
                {
                    side1 = left ? 0 : 1;
                    side2 = front ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x - 1, y, z + 1) == Blocks.Air ? 0 : 1;
                    }
                }
            }
            else
            {
                if (vertex == 4)
                {
                    side1 = ChunkManager.GetBlock(x, y + 1, z - 1) == Blocks.Air ? 0 : 1;
                    side2 = ChunkManager.GetBlock(x - 1, y + 1, z) == Blocks.Air ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x - 1, y + 1, z - 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 5)
                {
                    side1 = ChunkManager.GetBlock(x + 1, y + 1, z) == Blocks.Air ? 0 : 1;
                    side2 = ChunkManager.GetBlock(x, y + 1, z - 1) == Blocks.Air ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x + 1, y + 1, z - 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 6)
                {
                    side1 = ChunkManager.GetBlock(x, y + 1, z + 1) == Blocks.Air ? 0 : 1;
                    side2 = ChunkManager.GetBlock(x + 1, y + 1, z) == Blocks.Air ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x + 1, y + 1, z + 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 7)
                {
                    side1 = ChunkManager.GetBlock(x - 1, y + 1, z) == Blocks.Air ? 0 : 1;
                    side2 = ChunkManager.GetBlock(x, y + 1, z + 1) == Blocks.Air ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x - 1, y + 1, z + 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 0)
                {
                    side1 = ChunkManager.GetBlock(x, y - 1, z - 1) == Blocks.Air ? 0 : 1;
                    side2 = ChunkManager.GetBlock(x - 1, y - 1, z) == Blocks.Air ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x - 1, y - 1, z - 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 1)
                {
                    side1 = ChunkManager.GetBlock(x + 1, y - 1, z) == Blocks.Air ? 0 : 1;
                    side2 = ChunkManager.GetBlock(x, y - 1, z - 1) == Blocks.Air ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x + 1, y - 1, z - 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 2)
                {
                    side1 = ChunkManager.GetBlock(x, y - 1, z + 1) == Blocks.Air ? 0 : 1;
                    side2 = ChunkManager.GetBlock(x + 1, y - 1, z) == Blocks.Air ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x + 1, y - 1, z + 1) == Blocks.Air ? 0 : 1;
                    }
                }
                if (vertex == 3)
                {
                    side1 = ChunkManager.GetBlock(x - 1, y - 1, z) == Blocks.Air ? 0 : 1;
                    side2 = ChunkManager.GetBlock(x, y - 1, z + 1) == Blocks.Air ? 0 : 1;
                    if (side1 == 0 || side2 == 0)
                    {
                        corner = ChunkManager.GetBlock(x - 1, y - 1, z + 1) == Blocks.Air ? 0 : 1;
                    }
                }
            }
            return(VertexAO(side1, side2, corner));;
        }