Пример #1
0
            public void Execute(int index)
            {
                int3  gridPosition = VoxelUtil.To3DIndex(index, chunkSize);
                Voxel voxel        = voxels[index];

                if (voxel.data == Voxel.VoxelType.Air)
                {
                    return;
                }

                for (int direction = 0; direction < 6; direction++)
                {
                    int3 neighborPosition = gridPosition + VoxelDirectionOffsets[direction];

                    if (TransparencyCheck(voxels, neighborPosition, chunkSize))
                    {
                        continue;
                    }

                    AddQuadByDirection(direction, voxel.data, lightData[index], 1.0f, 1.0f, gridPosition, counter, vertices, normals, uvs, colors, indices);
                }
            }
            public unsafe void Execute(int index)
            {
                int3 gridPosition = VoxelUtil.To3DIndex(index, chunkSize);

                NativeSlice <Voxel> voxels = voxelsWithNeighbor.Slice(neighborHashMap[chunkPosition] * chunkSize.x * chunkSize.y * chunkSize.z, chunkSize.x * chunkSize.y * chunkSize.z);

                Voxel voxel = voxels[index];

                VoxelLight voxelLight = new VoxelLight();

                if (voxel.data == Voxel.VoxelType.Air)
                {
                    lightDatas[index] = voxelLight;
                    return;
                }

                for (int direction = 0; direction < 6; direction++)
                {
                    // Todo : Code Cleanup!!

                    int3 down            = gridPosition;
                    int3 left            = gridPosition;
                    int3 top             = gridPosition;
                    int3 right           = gridPosition;
                    int3 leftDownCorner  = gridPosition;
                    int3 topLeftCorner   = gridPosition;
                    int3 topRightCorner  = gridPosition;
                    int3 rightDownCorner = gridPosition;

                    down[VoxelUtil.DirectionAlignedY[direction]]  -= 1;
                    left[VoxelUtil.DirectionAlignedX[direction]]  -= 1;
                    top[VoxelUtil.DirectionAlignedY[direction]]   += 1;
                    right[VoxelUtil.DirectionAlignedX[direction]] += 1;

                    leftDownCorner[VoxelUtil.DirectionAlignedX[direction]] -= 1;
                    leftDownCorner[VoxelUtil.DirectionAlignedY[direction]] -= 1;

                    topLeftCorner[VoxelUtil.DirectionAlignedX[direction]] -= 1;
                    topLeftCorner[VoxelUtil.DirectionAlignedY[direction]] += 1;

                    topRightCorner[VoxelUtil.DirectionAlignedX[direction]] += 1;
                    topRightCorner[VoxelUtil.DirectionAlignedY[direction]] += 1;

                    rightDownCorner[VoxelUtil.DirectionAlignedX[direction]] += 1;
                    rightDownCorner[VoxelUtil.DirectionAlignedY[direction]] -= 1;

                    int3 *neighbors = stackalloc int3[] { down, leftDownCorner, left, topLeftCorner, top, topRightCorner, right, rightDownCorner };

                    for (int i = 0; i < 8; i++)
                    {
                        neighbors[i][VoxelUtil.DirectionAlignedZ[direction]] += VoxelUtil.DirectionAlignedSign[direction];
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        bool side1  = TransparencyCheck(voxels, neighbors[VoxelUtil.AONeighborOffsets[i * 3]]);
                        bool corner = TransparencyCheck(voxels, neighbors[VoxelUtil.AONeighborOffsets[i * 3 + 1]]);
                        bool side2  = TransparencyCheck(voxels, neighbors[VoxelUtil.AONeighborOffsets[i * 3 + 2]]);

                        if (side1 && side2)
                        {
                            voxelLight.ambient[i + direction * 4] = 0f;
                        }
                        else
                        {
                            voxelLight.ambient[i + direction * 4] = ((side1 ? 0f : 1f) + (side2 ? 0f : 1f) + (corner ? 0f : 1f)) / 3.0f;
                        }
                    }
                }

                lightDatas[index] = voxelLight;
            }
            public unsafe void Execute(int index)
            {
                int3 gridPosition = VoxelUtil.To3DIndex(index, chunkSize);

                Voxel voxel = voxels[index];

                VoxelLight voxelLight = new VoxelLight();

                if (voxel.data == Voxel.VoxelType.Air)
                {
                    lightDatas[index] = voxelLight;
                    return;
                }

                for (int direction = 0; direction < 6; direction++)
                {
                    int3 neighborPosition = gridPosition + VoxelMeshBuilder.VoxelDirectionOffsets[direction];
                    if (VoxelMeshBuilder.TransparencyCheck(voxels, neighborPosition, chunkSize))
                    {
                        continue;
                    }

                    // Todo : Code Cleanup!!

                    int3 down            = gridPosition;
                    int3 left            = gridPosition;
                    int3 top             = gridPosition;
                    int3 right           = gridPosition;
                    int3 leftDownCorner  = gridPosition;
                    int3 topLeftCorner   = gridPosition;
                    int3 topRightCorner  = gridPosition;
                    int3 rightDownCorner = gridPosition;

                    down[VoxelMeshBuilder.DirectionAlignedY[direction]]  -= 1;
                    left[VoxelMeshBuilder.DirectionAlignedX[direction]]  -= 1;
                    top[VoxelMeshBuilder.DirectionAlignedY[direction]]   += 1;
                    right[VoxelMeshBuilder.DirectionAlignedX[direction]] += 1;

                    leftDownCorner[VoxelMeshBuilder.DirectionAlignedX[direction]] -= 1;
                    leftDownCorner[VoxelMeshBuilder.DirectionAlignedY[direction]] -= 1;

                    topLeftCorner[VoxelMeshBuilder.DirectionAlignedX[direction]] -= 1;
                    topLeftCorner[VoxelMeshBuilder.DirectionAlignedY[direction]] += 1;

                    topRightCorner[VoxelMeshBuilder.DirectionAlignedX[direction]] += 1;
                    topRightCorner[VoxelMeshBuilder.DirectionAlignedY[direction]] += 1;

                    rightDownCorner[VoxelMeshBuilder.DirectionAlignedX[direction]] += 1;
                    rightDownCorner[VoxelMeshBuilder.DirectionAlignedY[direction]] -= 1;

                    int3 *neighbors = stackalloc int3[] { down, leftDownCorner, left, topLeftCorner, top, topRightCorner, right, rightDownCorner };

                    for (int i = 0; i < 8; i++)
                    {
                        neighbors[i][VoxelMeshBuilder.DirectionAlignedZ[direction]] += (direction % 2 == 0) ? 1 : -1;
                    }

                    for (int i = 0; i < 4; i++)
                    {
                        bool side1  = VoxelMeshBuilder.TransparencyCheck(voxels, neighbors[AONeighborOffsets[i * 3]], chunkSize);
                        bool corner = VoxelMeshBuilder.TransparencyCheck(voxels, neighbors[AONeighborOffsets[i * 3 + 1]], chunkSize);
                        bool side2  = VoxelMeshBuilder.TransparencyCheck(voxels, neighbors[AONeighborOffsets[i * 3 + 2]], chunkSize);

                        if (side1 && side2)
                        {
                            voxelLight.ambient[i + direction * 4] = 0f;
                        }
                        else
                        {
                            voxelLight.ambient[i + direction * 4] = ((side1 ? 0 : 1) + (side2 ? 0 : 1) + (corner ? 0 : 1)) / 3.0f;
                        }
                    }
                }

                lightDatas[index] = voxelLight;
            }