예제 #1
0
    float EdgeBorder(int2 cellIndex)
    {
        switch (distance2EdgeBorder)
        {
        case Distance2EdgeBorder.Height:
            return(topologyUtil.CellHeight(cellIndex));

        case Distance2EdgeBorder.Sector:
            return(topologyUtil.CellGrouping(cellIndex));

        default: throw new System.Exception("Unrecognised border type");
        }
    }
예제 #2
0
    void TryAddCell(int2 index)
    {
        if (!cellMatrix.ItemIsSet(index))
        {
            WorleyNoise.CellData cellData = worley.GetCellData(index);
            CellMatrixItem       cell     = new CellMatrixItem
                                            (
                cellData,
                topologyUtil.CellGrouping(index),
                topologyUtil.CellHeight(index)
                                            );

            cellMatrix.AddItem(cell, cellData.index);
        }
    }
예제 #3
0
        float GetOrGenerateCellGrouping(int2 index)
        {
            if (cellMatrix.ItemIsSet(index))
            {
                return(cellMatrix.GetItem(index).grouping);
            }

            var cell = new CellSystem.CellMatrixItem
                       (
                worley.GetCellData(index),
                topologyUtil.CellGrouping(index),
                topologyUtil.CellHeight(index)
                       );

            cellMatrix.AddItem(cell, index);
            return(cell.grouping);
        }
예제 #4
0
        public void Execute()
        {
            Entity waterEntity = commandBuffer.CreateEntity(waterEntityArchetype);

            commandBuffer.SetComponent <Translation>(waterEntity, new Translation {
                Value = new float3(matrix.root.x, 0, matrix.root.z)
            });

            vertices  = commandBuffer.AddBuffer <Vertex>(waterEntity);
            colors    = commandBuffer.AddBuffer <VertColor>(waterEntity);
            triangles = commandBuffer.AddBuffer <Triangle>(waterEntity);

            int indexOffset = 0;

            for (int x = 0; x < matrix.width - 1; x++)
            {
                for (int z = 0; z < matrix.width - 1; z++)
                {
                    int2 bl = new int2(x, z);
                    int2 tl = new int2(x, z + 1);
                    int2 tr = new int2(x + 1, z + 1);
                    int2 br = new int2(x + 1, z);

                    WorleyNoise.PointData blWorley = matrix.GetItem <WorleyNoise.PointData>(bl, worley, arrayUtil);
                    WorleyNoise.PointData tlWorley = matrix.GetItem <WorleyNoise.PointData>(tl, worley, arrayUtil);
                    WorleyNoise.PointData trWorley = matrix.GetItem <WorleyNoise.PointData>(tr, worley, arrayUtil);
                    WorleyNoise.PointData brWorley = matrix.GetItem <WorleyNoise.PointData>(br, worley, arrayUtil);

                    if (!blWorley.isSet ||
                        !tlWorley.isSet ||
                        !trWorley.isSet ||
                        !brWorley.isSet)
                    {
                        continue;
                    }

                    float  waterHeight = topologyUtil.CellHeight(masterCell.index);
                    float4 waterColor  = new float4(0, 0.5f, 1, 0.5f);

                    vertices.Add(new Vertex {
                        vertex = new float3(bl.x, waterHeight - 1, bl.y)
                    });
                    vertices.Add(new Vertex {
                        vertex = new float3(tl.x, waterHeight - 1, tl.y)
                    });
                    vertices.Add(new Vertex {
                        vertex = new float3(tr.x, waterHeight - 1, tr.y)
                    });
                    vertices.Add(new Vertex {
                        vertex = new float3(br.x, waterHeight - 1, br.y)
                    });

                    colors.Add(new VertColor {
                        color = waterColor
                    });
                    colors.Add(new VertColor {
                        color = waterColor
                    });
                    colors.Add(new VertColor {
                        color = waterColor
                    });
                    colors.Add(new VertColor {
                        color = waterColor
                    });

                    GetTriangleIndicesForQuad(indexOffset);

                    indexOffset += 4;
                }
            }
        }