コード例 #1
0
    //
    // Rest of marching cubes algorithm (on CPU)
    //
    //更新三角形面片的顶点位置
    private void updateVertices2(GPUEdgeVertices vert)
    {
        int cubeIndex = vert.index;

        for (int k = 0; triTable[cubeIndex][k] != -1; k += 3)
        {
            this.vertices.Add(this.findVertex(vert, this.triTable[cubeIndex][k]));
            this.vertices.Add(this.findVertex(vert, this.triTable[cubeIndex][k + 2]));
            this.vertices.Add(this.findVertex(vert, this.triTable[cubeIndex][k + 1]));
        }
    }
コード例 #2
0
 private Vector3 findVertex(GPUEdgeVertices vert, int i)
 {
     if (i == 0)
     {
         return(vert.edge0);
     }
     else if (i == 1)
     {
         return(vert.edge1);
     }
     else if (i == 2)
     {
         return(vert.edge2);
     }
     else if (i == 3)
     {
         return(vert.edge3);
     }
     else if (i == 4)
     {
         return(vert.edge4);
     }
     else if (i == 5)
     {
         return(vert.edge5);
     }
     else if (i == 6)
     {
         return(vert.edge6);
     }
     else if (i == 7)
     {
         return(vert.edge7);
     }
     else if (i == 8)
     {
         return(vert.edge8);
     }
     else if (i == 9)
     {
         return(vert.edge9);
     }
     else if (i == 10)
     {
         return(vert.edge10);
     }
     else
     {
         return(vert.edge11);
     }
 }
コード例 #3
0
    //
    // GPU metaball falloff function summator & part of marching cubes algorithm
    //

    private GPUEdgeVertices[] runComputeShader(GPUBall[] gpuBalls)
    {
        // pass data to the compute shader
        this.metaballsBuffer.SetData(gpuBalls);
        this.shader.SetInt("numMetaballs", gpuBalls.Length);
        this.shader.SetInt("width", this.width);
        this.shader.SetInt("height", this.height);
        this.shader.SetFloat("threshold", this.container.threshold);

        // Run, Forrest, run!
        this.shader.Dispatch(this.shaderKernel, this.width / 8, this.height / 8, this.depth / 8);

        // parse returned vertex data and return it
        GPUEdgeVertices[] output = new GPUEdgeVertices[this.verticesBuffer.count];
        this.verticesBuffer.GetData(output);
        return(output);
    }