Ejemplo n.º 1
0
        public void ComputeGrassFor(IEnvironmentSurface chunk)
        {
            MeshData meshData = chunk.MeshData;
            int      numTris  = meshData.vertices.Length / 3;

            vertexBuffer.SetData(meshData.vertices);

            int numThreadPerAxis = Mathf.Max(1, Mathf.CeilToInt(numTris / THREAD_SIZE_GROUP));

            grassProperties = new ComputeBuffer(GRASS_PER_COMPUTE, MeshInstancedProperties.Size(), ComputeBufferType.Append);
            grassProperties.SetCounterValue(0);
            Material       mat     = new Material(this.mat);
            Maybe <Bounds> mBounds = chunk.MeshBounds;
            Vector3        offset  = mBounds.Value.center;

            grassShader.SetInt(NAME_OF_TRIANGLE_LENGTH, numTris);
            grassShader.SetVector(NAME_OF_OFFSET, offset);
            grassShader.SetFloat(NAME_OF_BOUNDS, grassMesh.bounds.extents.y);
            grassShader.SetBuffer(0, NAME_OF_TRIANGLE_BUFFER, vertexBuffer);
            grassShader.SetBuffer(0, NAME_OF_GRASS_BUFFER, grassProperties);

            grassShader.Dispatch(0, numThreadPerAxis, 1, 1);

            new InstantiatableData(grassMesh, grassProperties, mat, mBounds);
            grassProperties = null;
        }
Ejemplo n.º 2
0
        protected void PrepareEnvironmentForChunk(IEnvironmentSurface chunk)
        {
            environmentEntities.SetCounterValue(0);
            environmentSpawner.SetBuffer(0, "minAngleAtCubeIndex", chunk.MinDegreeBuffer);
            Vector4 v4 = VectorExtension.ToVector4(chunk.AnchorPos);

            environmentSpawner.SetVector("anchorPosition", v4);
            environmentPlacer.SetVector("anchorPosition", v4);
            environmentPlacer.SetVector(BOUNDS_CENTER_NAME, chunk.MeshBounds.Value.center);
            if (chunk.BuildDetailedEnvironment)
            {
            }
        }
Ejemplo n.º 3
0
        //TODO: Use prepare tri buffer to place environment. also do this async
        public void AddEnvironmentForOriginalChunk(IEnvironmentSurface chunk)
        {
            //float[] mindegs = ReadBuffer<float>(chunk.MinDegreeBuffer);

            //float[] nonNullDegs = mindegs.Where(f => f > 0).ToArray();

            PrepareEnvironmentForChunk(chunk);
            environmentSpawner.Dispatch(0, THREADS_PER_AXIS, THREADS_PER_AXIS, THREADS_PER_AXIS);
            int entityCount = ComputeBufferExtension.GetLengthOfAppendBuffer(environmentEntities, bufferCount);

            if (entityCount <= 0)
            {
                return;
            }

            entityTransforms = new ComputeBuffer(entityCount, sizeof(float) * 16);
            environmentPlacer.SetBuffer(0, "entityTransform", entityTransforms);
            environmentPlacer.SetInt("length", entityCount);
            int threadsOnXAxis = Mathf.CeilToInt(entityCount / ENVIRONMENT_THREAD_SIZE);

            environmentPlacer.Dispatch(0, threadsOnXAxis, 1, 1);
            MeshInstantiator.meshInstantiator.AddData(new InstantiatableData(mesh, entityTransforms, mat, chunk.MeshBounds, entityCount));

            //Debug test data
            Matrix4x4[] test = new Matrix4x4[entityCount];
            entityTransforms.GetData(test);
            int[] results = ComputeBufferExtension.ReadAppendBuffer <int>(environmentEntities, bufferCount);
            int   i       = 0;


            //AsyncGPUReadback.Request(environmentEntities, OnTreePositionsRecieved);

            //recieve tree positions
            //recieve tree rotations -> place colliders from pool
            //add grass to unused cubes
            //when editing chunk store tree positions and rotations and original cubes
        }
Ejemplo n.º 4
0
 public void StartEnvironmentPipelineForChunk(IEnvironmentSurface environmentChunk)
 {
     //grass.ComputeGrassFor(environmentChunk);
     //environmentSpawner.AddEnvironmentForOriginalChunk(environmentChunk);
 }
Ejemplo n.º 5
0
        //TODO: Dont store when chunk knows he stored before

        public void ComputeGrassFor(IEnvironmentSurface environmentChunk)
        {
            grass.ComputeGrassFor(environmentChunk);
        }