Ejemplo n.º 1
0
            public Mesh ComputeColliderMesh(float[] densityMap, BorderDensities maps)
            {
                m_densityBuffer.SetData(densityMap);
                m_ChunkXdensityBuffer.SetData(maps.borderMapx);
                m_ChunkYdensityBuffer.SetData(maps.borderMapy);
                m_ChunkZdensityBuffer.SetData(maps.borderMapz);
                m_ChunkXYdensityBuffer.SetData(maps.borderMapxy);
                m_ChunkYZdensityBuffer.SetData(maps.borderMapyz);
                m_ChunkXZdensityBuffer.SetData(maps.borderMapxz);
                m_ChunkXYZdensityBuffer.SetData(maps.borderMapxyz);

                //Clear vertices
                m_clearVerticesShader.SetBuffer(0, "_Vertices", m_meshBuffer);
                m_clearVerticesShader.Dispatch(0, m_x_dim / 8, m_y_dim / 8, m_z_dim / 8);

                //Initalize MC
                m_MCColliderShader.SetFloat("_DensityOffset", m_offset);
                m_MCColliderShader.SetBuffer(0, "_Vertices", m_meshBuffer);
                m_MCColliderShader.SetBuffer(0, "_DensityMap", m_densityBuffer);
                m_MCColliderShader.SetBuffer(0, "_BorderMapx", m_ChunkXdensityBuffer);
                m_MCColliderShader.SetBuffer(0, "_BorderMapy", m_ChunkYdensityBuffer);
                m_MCColliderShader.SetBuffer(0, "_BorderMapz", m_ChunkZdensityBuffer);
                m_MCColliderShader.SetBuffer(0, "_BorderMapxy", m_ChunkXYdensityBuffer);
                m_MCColliderShader.SetBuffer(0, "_BorderMapyz", m_ChunkYZdensityBuffer);
                m_MCColliderShader.SetBuffer(0, "_BorderMapxz", m_ChunkXZdensityBuffer);
                m_MCColliderShader.SetFloat("_BorderMapxyz", maps.borderMapxyz[0]);
                m_MCColliderShader.Dispatch(0, m_x_dim / 8, m_y_dim / 8, m_z_dim / 8);                 //start the magic

                //receive the verts
                Vertex[]       receivedData = new Vertex[m_maxVertices];
                List <Vector3> vertices     = new List <Vector3>();
                List <int>     triangles    = new List <int>();
                Mesh           mesh         = new Mesh();

                m_meshBuffer.GetData(receivedData);
                for (int i = 0, idx = 0; i < receivedData.Length; i++)
                {
                    if (receivedData[i].position.w != -1.0f)
                    {
                        vertices.Add(new Vector3(receivedData[i].position.x, receivedData[i].position.y, receivedData[i].position.z) - new Vector3(m_x_dim / 2, m_y_dim / 2, m_z_dim / 2) * m_scale);
                        triangles.Add(idx++);
                    }
                }

                mesh.SetVertices(vertices);
                mesh.SetTriangles(triangles, 0);

                return(mesh);
            }
Ejemplo n.º 2
0
            public void ComputeRenderMesh(float[] densityMap, BorderDensities maps)
            {
                m_densityBuffer.SetData(densityMap);
                m_ChunkXdensityBuffer.SetData(maps.borderMapx);
                m_ChunkYdensityBuffer.SetData(maps.borderMapy);
                m_ChunkZdensityBuffer.SetData(maps.borderMapz);
                m_ChunkXYdensityBuffer.SetData(maps.borderMapxy);
                m_ChunkYZdensityBuffer.SetData(maps.borderMapyz);
                m_ChunkXZdensityBuffer.SetData(maps.borderMapxz);
                m_ChunkXYZdensityBuffer.SetData(maps.borderMapxyz);

                //Clear vertices
                m_clearVerticesShader.SetBuffer(0, "_Vertices", m_meshBuffer);
                m_clearVerticesShader.Dispatch(0, m_x_lod_dim / (8 / m_lod), m_y_lod_dim / (8 / m_lod), m_z_lod_dim / (8 / m_lod));

                //Calculate normals
                m_calculateNormalsShader.SetBuffer(0, "_DensityMap", m_densityBuffer);
                m_calculateNormalsShader.SetBuffer(0, "_BorderMapx", m_ChunkXdensityBuffer);
                m_calculateNormalsShader.SetBuffer(0, "_BorderMapy", m_ChunkYdensityBuffer);
                m_calculateNormalsShader.SetBuffer(0, "_BorderMapz", m_ChunkZdensityBuffer);
                m_calculateNormalsShader.SetBuffer(0, "_BorderMapxy", m_ChunkXYdensityBuffer);
                m_calculateNormalsShader.SetBuffer(0, "_BorderMapyz", m_ChunkYZdensityBuffer);
                m_calculateNormalsShader.SetBuffer(0, "_BorderMapxz", m_ChunkXZdensityBuffer);
                m_calculateNormalsShader.SetBuffer(0, "_BorderMapxyz", m_ChunkXYZdensityBuffer);
                m_calculateNormalsShader.SetTexture(0, "_Normals", m_normalsTexture);
                m_calculateNormalsShader.Dispatch(0, m_x_dim / 8, m_y_dim / 8, m_z_dim / 8);

                //Initalize MC
                //m_MCRenderShader.SetFloats("_ChunkPosition", new float[] { chunkPosition.x, chunkPosition.y, chunkPosition.z });
                m_MCRenderShader.SetFloat("_DensityOffset", m_offset);
                m_MCRenderShader.SetTexture(0, "_Normals", m_normalsTexture);
                m_MCRenderShader.SetBuffer(0, "_Vertices", m_meshBuffer);
                m_MCRenderShader.SetBuffer(0, "_DensityMap", m_densityBuffer);
                m_MCRenderShader.SetBuffer(0, "_BorderMapx", m_ChunkXdensityBuffer);
                m_MCRenderShader.SetBuffer(0, "_BorderMapy", m_ChunkYdensityBuffer);
                m_MCRenderShader.SetBuffer(0, "_BorderMapz", m_ChunkZdensityBuffer);
                m_MCRenderShader.SetBuffer(0, "_BorderMapxy", m_ChunkXYdensityBuffer);
                m_MCRenderShader.SetBuffer(0, "_BorderMapyz", m_ChunkYZdensityBuffer);
                m_MCRenderShader.SetBuffer(0, "_BorderMapxz", m_ChunkXZdensityBuffer);
                m_MCRenderShader.SetFloat("_BorderMapxyz", maps.borderMapxyz[0]);
                m_MCRenderShader.Dispatch(0, m_x_lod_dim / (8 / m_lod), m_y_lod_dim / (8 / m_lod), m_z_lod_dim / (8 / m_lod)); //start the magic
            }