Exemplo n.º 1
0
        public void Execute(int index)
        {
            // ReSharper disable once RedundantCast
            int z = Mathf.FloorToInt((float)index / XSamples);
            int x = index - (z * XSamples);

            Vector3 samplePosition = new Vector3(CellCorner.x + x * CalculatedSampleDistance, CellCorner.y + 10,
                                                 CellCorner.z + z * CalculatedSampleDistance);
            VegetationSpawnLocationInstance vegetationSpawnLocationInstance =
                new VegetationSpawnLocationInstance
            {
                Position      = samplePosition,
                SpawnChance   = DefaultSpawnChance,
                BiomeDistance = 1000000f
            };

            int randomNumberIndex = x + z * ZSamples + CellIndex + Seed;

            while (randomNumberIndex > 9999)
            {
                randomNumberIndex = randomNumberIndex - 10000;
            }
            vegetationSpawnLocationInstance.RandomNumberIndex = randomNumberIndex;

            if (RandomizePosition)
            {
                float3 offset = GetRandomOffset(CalculatedSampleDistance / 2f,
                                                vegetationSpawnLocationInstance.RandomNumberIndex);
                vegetationSpawnLocationInstance.RandomNumberIndex =
                    vegetationSpawnLocationInstance.RandomNumberIndex + 2;
                vegetationSpawnLocationInstance.Position += offset;
            }

            if (UseSamplePointOffset)
            {
                float randomOffset = RandomRange(vegetationSpawnLocationInstance.RandomNumberIndex,
                                                 SamplePointMinOffset, SamplePointMaxOffset);
                vegetationSpawnLocationInstance.RandomNumberIndex += 1;
                float randomRotation =
                    math.frac(SamplePointMinOffset) *
                    365;
                UnityEngine.Quaternion samplePointOffsetRotation = UnityEngine.Quaternion.Euler(0, randomRotation, 0);
                float3 samplePointOffset = samplePointOffsetRotation * new Vector3(randomOffset, 0, 0);
                vegetationSpawnLocationInstance.Position += samplePointOffset;
            }

            if (!CellRect.Contains(new Vector2(vegetationSpawnLocationInstance.Position.x,
                                               vegetationSpawnLocationInstance.Position.z)))
            {
                vegetationSpawnLocationInstance.SpawnChance = 0;
            }

            SpawnLocations[index] = vegetationSpawnLocationInstance;
        }
Exemplo n.º 2
0
        public void Execute(int index)
        {
            if (HeightmapSampled[index] == 1)
            {
                return;
            }

            VegetationSpawnLocationInstance spawnLocation = SpawnLocationList[index];

            if (spawnLocation.SpawnChance < 0)
            {
                Excluded[index]         = 1;
                HeightmapSampled[index] = 1;
                return;
            }

            Vector3 worldPosition        = spawnLocation.Position;
            Vector3 terrainSpacePositon  = worldPosition - TerrainPosition;
            float2  interpolatedPosition = new float2(terrainSpacePositon.x / Size.x, terrainSpacePositon.z / Size.z);

            if (interpolatedPosition.x < 0 || interpolatedPosition.x > 1 || interpolatedPosition.y < 0 ||
                interpolatedPosition.y > 1)
            {
                {
                    Excluded[index] = 1;
                    return;
                }
            }

            float height = GetTriangleInterpolatedHeight(interpolatedPosition.x, interpolatedPosition.y);


            Position[index]           = new float3(spawnLocation.Position.x, height + TerrainPosition.y, spawnLocation.Position.z);
            TerrainNormal[index]      = GetInterpolatedNormal(interpolatedPosition.x, interpolatedPosition.y);
            Scales[index]             = new float3(1, 1, 1);
            Rotation[index]           = Quaternion.Euler(0, 0, 0);
            RandomNumberIndex[index]  = spawnLocation.RandomNumberIndex;
            BiomeDistance[index]      = spawnLocation.BiomeDistance;
            DistanceFalloff[index]    = 1;
            TerrainSourceIDs[index]   = TerrainSourceID;
            Excluded[index]           = 0;
            HeightmapSampled[index]   = 1;
            TerrainTextureData[index] = 0;
            //TODO make sure we do not need to init these 2 here
            VegetationMaskDensity[index] = 0;
            VegetationMaskScale[index]   = 0;
            TextureMaskData[index]       = 0;
        }
Exemplo n.º 3
0
        public void Execute(int index)
        {
            VegetationSpawnLocationInstance vegetationSpawnLocationInstance = SpawnLocationList[index];

            if (RandomCutoff(vegetationSpawnLocationInstance.SpawnChance * Density,
                             vegetationSpawnLocationInstance.RandomNumberIndex))
            {
                vegetationSpawnLocationInstance.RandomNumberIndex++;
                vegetationSpawnLocationInstance.SpawnChance = -1;
                SpawnLocationList[index] = vegetationSpawnLocationInstance;
            }
            else
            {
                vegetationSpawnLocationInstance.RandomNumberIndex++;
                SpawnLocationList[index] = vegetationSpawnLocationInstance;
            }
        }
Exemplo n.º 4
0
        public void Execute(int index)
        {
            VegetationSpawnLocationInstance vegetationSpawnLocationInstance = SpawnLocationList[index];

            if (vegetationSpawnLocationInstance.SpawnChance > float.Epsilon)
            {
                float perlin = noise.cnoise(new float2(
                                                (vegetationSpawnLocationInstance.Position.x + Offset.x) / PerlinScale,
                                                (vegetationSpawnLocationInstance.Position.z + Offset.y) / PerlinScale));
                perlin += 1f;
                perlin /= 2f;
                perlin  = math.clamp(perlin, 0, 1);
                perlin  = math.@select(perlin, 1 - perlin, InversePerlinMask);
                vegetationSpawnLocationInstance.SpawnChance *= perlin;
                SpawnLocationList[index] = vegetationSpawnLocationInstance;
            }
        }