Ejemplo n.º 1
0
        public SgtTerrainCube(SgtTerrain newTerrain)
        {
            terrain = newTerrain;

            quads[0] = new SgtTerrainQuad(this, 0, 0.5, SgtTerrainTopology.CubeC[0], SgtTerrainTopology.CubeH[0], SgtTerrainTopology.CubeV[0]);
            quads[1] = new SgtTerrainQuad(this, 1, 0.0, SgtTerrainTopology.CubeC[1], SgtTerrainTopology.CubeH[1], SgtTerrainTopology.CubeV[1]);
            quads[2] = new SgtTerrainQuad(this, 2, 0.0, SgtTerrainTopology.CubeC[2], SgtTerrainTopology.CubeH[2], SgtTerrainTopology.CubeV[2]);
            quads[3] = new SgtTerrainQuad(this, 3, 0.0, SgtTerrainTopology.CubeC[3], SgtTerrainTopology.CubeH[3], SgtTerrainTopology.CubeV[3]);
            quads[4] = new SgtTerrainQuad(this, 4, 0.5, SgtTerrainTopology.CubeC[4], SgtTerrainTopology.CubeH[4], SgtTerrainTopology.CubeV[4]);
            quads[5] = new SgtTerrainQuad(this, 5, 0.0, SgtTerrainTopology.CubeC[5], SgtTerrainTopology.CubeH[5], SgtTerrainTopology.CubeV[5]);
        }
        private void HandleDrawQuad(Camera camera, SgtTerrainQuad quad, Matrix4x4 matrix, int layer)
        {
            if (material != null)
            {
                var properties = quad.Properties;

                properties.SetFloat(SgtShader._BumpScale, bumpScale);

                properties.SetFloat(SgtShader._WaterLevel, waterLevel);

                //if (cameraOffset != 0.0f)
                //{
                //	var direction = Vector3.Normalize(camera.transform.position - transform.position);
                //
                //	matrix = Matrix4x4.Translate(direction * cameraOffset) * matrix;
                //}

                foreach (var mesh in quad.CurrentMeshes)
                {
                    Graphics.DrawMesh(mesh, matrix, material, gameObject.layer, camera, 0, properties);
                }
            }
        }
Ejemplo n.º 3
0
        private void HandleDrawQuad(Camera camera, SgtTerrainQuad quad, Matrix4x4 matrix, int layer)
        {
            var finalSharedMaterial = sharedMaterial;

            if (OnOverrideSharedMaterial != null)
            {
                OnOverrideSharedMaterial.Invoke(ref finalSharedMaterial, camera);
            }

            if (SgtHelper.Enabled(finalSharedMaterial) == true && finalSharedMaterial.Material != null)
            {
                //if (cameraOffset != 0.0f)
                //{
                //	var direction = Vector3.Normalize(camera.transform.position - transform.position);
                //
                //	matrix = Matrix4x4.Translate(direction * cameraOffset) * matrix;
                //}

                foreach (var mesh in quad.CurrentMeshes)
                {
                    Graphics.DrawMesh(mesh, matrix, finalSharedMaterial.Material, gameObject.layer, camera);
                }
            }
        }
Ejemplo n.º 4
0
 protected virtual void Dispose(SgtTerrainQuad quad)
 {
     quad.Dispose();
 }
Ejemplo n.º 5
0
 protected virtual void Allocate(SgtTerrainQuad quad)
 {
     quad.Allocate();
 }
Ejemplo n.º 6
0
 protected abstract void ScheduleJob(SgtTerrainQuad quad);
Ejemplo n.º 7
0
        protected override void ScheduleJob(SgtTerrainQuad newQuad)
        {
            running       = true;
            age           = 0;
            currentQuad   = newQuad;
            currentPoints = currentQuad.Points;

            // Build arrays
            var quadsX   = (int)currentQuad.PendingOuter.SizeX;
            var quadsY   = (int)currentQuad.PendingOuter.SizeY;
            var pointsX  = quadsX + 1;
            var pointsY  = quadsY + 1;
            var samplesX = pointsX + 4;
            var samplesY = pointsY + 4;

            SgtHelper.UpdateNativeArray(ref pendingPoints, samplesX * samplesY);
            SgtHelper.UpdateNativeArray(ref heights, samplesX * samplesY);
            SgtHelper.UpdateNativeArray(ref positions, pointsX * pointsY);
            SgtHelper.UpdateNativeArray(ref normals, pointsX * pointsY);
            SgtHelper.UpdateNativeArray(ref tangents, pointsX * pointsY);
            SgtHelper.UpdateNativeArray(ref coords, pointsX * pointsY);
            SgtHelper.UpdateNativeArray(ref indices, quadsX * quadsY * 6);

            // Build jobs
            var quadJob = new QuadJob();

            quadJob.Radius = radius;
            quadJob.Middle = currentQuad.Cube.Middle;
            quadJob.Step   = currentQuad.Cube.Step;
            quadJob.CubeC  = currentQuad.CubeC;
            quadJob.CubeH  = currentQuad.CubeH;
            quadJob.CubeV  = currentQuad.CubeV;
            quadJob.CubeO  = currentQuad.CubeO;

            quadJob.CurrentPoints = currentPoints;
            quadJob.PendingPoints = pendingPoints;
            quadJob.CurrentOuter  = currentQuad.CurrentOuter.RectXY;
            quadJob.PendingOuter  = currentQuad.PendingOuter.RectXY;
            quadJob.Heights       = heights;

            var verticesJob = new VerticesJob();

            verticesJob.Middle       = currentQuad.Cube.Middle;
            verticesJob.Twist        = currentQuad.Twist;
            verticesJob.Smooth       = (int)(detail * resolution * 0.15);
            verticesJob.PendingOuter = currentQuad.PendingOuter;
            verticesJob.VirtualOuter = currentQuad.VirtualOuter;

            verticesJob.Points    = pendingPoints;
            verticesJob.Positions = positions;
            verticesJob.Normals   = normals;
            verticesJob.Tangents  = tangents;
            verticesJob.Coords    = coords;
            verticesJob.Heights   = heights;

            var indicesJob = new IndicesJob();

            indicesJob.Inner   = currentQuad.PendingInner.RectXY;
            indicesJob.Outer   = currentQuad.PendingOuter.RectXY;
            indicesJob.Indices = indices;

            // Schedule everything
            currentHandle = quadJob.Schedule();

            InvokeScheduleHeights(pendingPoints, heights, ref currentHandle);

            currentHandle = verticesJob.Schedule(currentHandle);
            currentHandle = indicesJob.Schedule(currentHandle);
        }