예제 #1
0
    public void BuildGPU_DataBuffer(bool full_generate)
    {
        System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
        watch.Start();
        Vector3Int start = VoxelConversions.LocalToGlobalCoord(chunkPosition, new Vector3Int(0, 0, 0));

        start = new Vector3Int(start.x - 1, start.y - 1, start.z - 1);

        //Debug.Log(chunkPosition + ": " + start.ToString());

        if (full_generate)
        {
            buffer = new uint[(builderInstance.ChunkSizeX + 2) * (builderInstance.ChunkSizeY + 2) * (builderInstance.ChunkSizeZ + 2)];
            for (int g_x = start.x, x = 0; x < builderInstance.ChunkSizeX + 2; x++, g_x++)
            {
                for (int g_y = start.y, y = 0; y < builderInstance.ChunkSizeY + 2; y++, g_y++)
                {
                    for (int g_z = start.z, z = 0; z < builderInstance.ChunkSizeZ + 2; z++, g_z++)
                    {
                        Block block = pageController.GetBlock(g_x, g_y, g_z);

                        if (!block.set)
                        {
                            if (x == 0)
                            {
                                block = pageController.GetBlock(g_x + 1, g_y, g_z);
                            }
                            else if (x == builderInstance.ChunkSizeX + 1)
                            {
                                block = pageController.GetBlock(g_x - 1, g_y, g_z);
                            }

                            if (y == 0)
                            {
                                block = pageController.GetBlock(g_x, g_y + 1, g_z);
                            }
                            else if (y == builderInstance.ChunkSizeY + 1)
                            {
                                block = pageController.GetBlock(g_x, g_y - 1, g_z);
                            }

                            if (z == 0)
                            {
                                block = pageController.GetBlock(g_x, g_y, g_z + 1);
                            }
                            else if (z == builderInstance.ChunkSizeZ + 1)
                            {
                                block = pageController.GetBlock(g_x, g_y, g_z - 1);
                            }
                        }

                        buffer[x + (builderInstance.ChunkSizeX + 2) * (y + (builderInstance.ChunkSizeY + 2) * z)] = block.type;
                    }
                }
            }
        }

        watch.Stop();

        //Debug.Log("BuildGPU_DataBuffer set buffer: " + watch.Elapsed);

        watch.Restart();

        Loom.QueueOnMainThread(() =>
        {
            //data_buffer = new ComputeBuffer(buffer.Length, sizeof(uint), ComputeBufferType.Default);
            //data_buffer.SetData(buffer);
            //_renderer.material.SetBuffer("_Data", data_buffer);
            //_renderer.material.SetInt("_DataPadding", 2);
        });

        watch.Stop();

        //Debug.Log("BuildGPU_DataBuffer set material: " + watch.Elapsed);
    }