public static noise ( float xin, float yin ) : float | ||
xin | float | |
yin | float | |
Результат | float |
// Update is called once per frame private void Update() { Debug.Log(m_ParticleEmitter.particleCount); int count = 0; Particle[] particles = m_ParticleEmitter.particles; for (int x = 0; x < 1024; x++) { for (int z = 0; z < 1024; z++) { for (int y = 0; y < 128; y++) { float groundHeight = PerlinSimplexNoise.noise(x * 0.001f, z * 0.001f, y * 0.001f) * 64.0f; groundHeight += PerlinSimplexNoise.noise(x * 0.01f, z * 0.01f, y * 0.01f) * 32.0f; groundHeight += PerlinSimplexNoise.noise(x * 0.1f, z * 0.1f, y * 0.1f) * 4.0f; //groundHeight = Mathf.Clamp(groundHeight, 0, 127); particles[count].position = new Vector3(x + y, groundHeight, z); if (count < particles.Length - 1) { count++; } else { UpdateDisplay(particles); return; } } } } }
private static void GenerateTerrain(Chunk chunk, int blockXInChunk, int blockYInChunk, int blockX, int blockY, int worldDepthInBlocks) { // The lower ground level is at least this high. int minimumGroundheight = worldDepthInBlocks / 4; int minimumGroundDepth = (int)(worldDepthInBlocks * 0.75f); float octave1 = PerlinSimplexNoise.noise(blockX * 0.0001f, blockY * 0.0001f) * 0.5f; float octave2 = PerlinSimplexNoise.noise(blockX * 0.0005f, blockY * 0.0005f) * 0.25f; float octave3 = PerlinSimplexNoise.noise(blockX * 0.005f, blockY * 0.005f) * 0.12f; float octave4 = PerlinSimplexNoise.noise(blockX * 0.01f, blockY * 0.01f) * 0.12f; float octave5 = PerlinSimplexNoise.noise(blockX * 0.03f, blockY * 0.03f) * octave4; float lowerGroundHeight = octave1 + octave2 + octave3 + octave4 + octave5; lowerGroundHeight = lowerGroundHeight * minimumGroundDepth + minimumGroundheight; bool sunlit = true; BlockType blockType = BlockType.Air; for (int z = worldDepthInBlocks - 1; z >= 0; z--) { if (z <= lowerGroundHeight) { if (sunlit) { blockType = BlockType.TopSoil; sunlit = false; } else { blockType = BlockType.Dirt; } } chunk.Blocks[blockXInChunk, blockYInChunk, z].Type = blockType; } }
/// <summary> /// Generates the decor vertices for the specified tile. /// </summary> /// <param name="x">The tile x coordinate.</param> /// <param name="y">The tile y coordinate.</param> /// <param name="color">The color tint to apply.</param> private void GenerateDecorVertices(int x, int y, Color color) { var dri = decorRenderInfo.decor; int n = dri.Length; Bits connected = TileRendererUtils.GetDecorConnectionBits(x, y, queryLayer); for (int i = 0; i < n; i++) { var decor = dri[i]; var variants = decor.variants; Bits required = decor.requiredConnections; if (variants != null && variants.Length > 0 && (connected & required) == required && (connected & decor.forbiddenConnections) == 0) { // Use a seeded random noise to determine if the tops spawn here float score = PerlinSimplexNoise.noise((float)(i + x + connected) * SIMPLEX_SCALE.x, (float)(i + y + connected) * SIMPLEX_SCALE.y); if (score >= decor.probabilityCutoff) { TileRendererUtils.AddDecorVertexInfo(ref decor, x, y, score, color, decorTriangles); } } } }
private static int GetUpperGroundHeight(WorldData worldData, int blockX, int blockY, float lowerGroundHeight) { float octave1 = PerlinSimplexNoise.noise((blockX + 100) * 0.001f, blockY * 0.001f) * 0.5f; float octave2 = PerlinSimplexNoise.noise((blockX + 100) * 0.002f, blockY * 0.002f) * 0.25f; float octave3 = PerlinSimplexNoise.noise((blockX + 100) * 0.01f, blockY * 0.01f) * 0.25f; float octaveSum = octave1 + octave2 + octave3; return((int)(octaveSum * (worldData.DepthInBlocks / 2f)) + (int)(lowerGroundHeight)); }
private float GetBlockNoise(int blockX, int blockY) { float mediumDetail = PerlinSimplexNoise.noise(blockX / 300.0f, blockY / 300.0f, 20); float fineDetail = PerlinSimplexNoise.noise(blockX / 80.0f, blockY / 80.0f, 30); float bigDetails = PerlinSimplexNoise.noise(blockX / 800.0f, blockY / 800.0f); float noise = bigDetails * 64.0f + mediumDetail * 32.0f + fineDetail * 16.0f; // *(bigDetails * 64.0f); return(noise + 16); }
private static int GetUpperGroundHeight(Chunk chunk, uint blockX, uint blockY, float lowerGroundHeight) { float octave1 = PerlinSimplexNoise.noise((blockX + 50) * 0.0002f, blockY * 0.0002f) * 0.05f; float octave2 = PerlinSimplexNoise.noise((blockX + 50) * 0.0005f, blockY * 0.0005f) * 0.135f; float octave3 = PerlinSimplexNoise.noise((blockX + 50) * 0.0025f, blockY * 0.0025f) * 0.15f; float octave4 = PerlinSimplexNoise.noise((blockX + 50) * 0.0125f, blockY * 0.0125f) * 0.05f; float octave5 = PerlinSimplexNoise.noise((blockX + 50) * 0.025f, blockY * 0.025f) * 0.015f; float octave6 = PerlinSimplexNoise.noise((blockX + 50) * 0.0125f, blockY * 0.0125f) * 0.04f; float octaveSum = octave1 + octave2 + octave3 + octave4 + octave5 + octave6; return((int)(octaveSum * (Chunk.SIZE.Y / 2f)) + (int)(lowerGroundHeight)); }
private static float GetLowerGroundHeight(Chunk chunk, uint blockX, uint blockY) { int minimumGroundheight = Chunk.SIZE.Y / 4; int minimumGroundDepth = (int)(Chunk.SIZE.Y * 0.5f); float octave1 = PerlinSimplexNoise.noise(blockX * 0.0001f, blockY * 0.0001f) * 0.5f; float octave2 = PerlinSimplexNoise.noise(blockX * 0.0005f, blockY * 0.0005f) * 0.35f; //float octave3 = PerlinSimplexNoise.noise(blockX * 0.02f, blockY * 0.02f) * 0.15f; float lowerGroundHeight = octave1 + octave2; //float lowerGroundHeight = octave1 + octave2 + octave3; lowerGroundHeight = lowerGroundHeight * minimumGroundDepth + minimumGroundheight; return(lowerGroundHeight); }
public static Color GetRadiationColour(SimDebugView instance, int cell) { Color result = new Color(0.2f, 0.9f, 0.3f, Mathf.Clamp(Mathf.Sqrt((float)(Grid.RadiationCount[cell] + RadiationGridManager.previewLux[cell])) / Mathf.Sqrt(80000f), 0f, 1f)); if (Grid.RadiationCount[cell] > 71999) { float num = ((float)Grid.RadiationCount[cell] + (float)LightGridManager.previewLux[cell] - 71999f) / 8001f; num /= 10f; float r = result.r; Vector3 vector = Grid.CellToPos2D(cell); float xin = vector.x / 8f; Vector3 vector2 = Grid.CellToPos2D(cell); result.r = r + Mathf.Min(0.1f, PerlinSimplexNoise.noise(xin, vector2.y / 8f + (float)instance.currentFrame / 32f) * num); } return(result); }
private void GenerateTerrain(Chunk chunk, int blockXInChunk, int blockZInChunk, int blockX, int blockZ, int worldHeightInBlocks) { int groundHeightInChunk = Mathf.FloorToInt(m_HeightField[blockX, blockZ]) - chunk.WorldPos.y; for (int y = 0; y < chunk.World.ChunkSizeBlocks.y; y++) { bool bUnderground = y < groundHeightInChunk; float density = bUnderground ? 1.0f : 0.0f; byte blockType = bUnderground ? m_SolidBlock : m_AirBlock; if (bUnderground) // are we underground - check for caves { if (m_BuildCaves) { int worldY = y + chunk.WorldPos.y; float octave1 = PerlinSimplexNoise.noise(blockX * 0.009f, blockZ * 0.009f, worldY * 0.009f) * 0.25f; float initialNoise = octave1 + PerlinSimplexNoise.noise(blockX * 0.04f, blockZ * 0.04f, worldY * 0.04f) * 0.15f; initialNoise += PerlinSimplexNoise.noise(blockX * 0.08f, blockZ * 0.08f, worldY * 0.08f) * 0.05f; if (initialNoise > m_CaveThreshold) { blockType = m_AirBlock; // cave density = 0; } else { // TODO: work out cave density //density = 1.0f - initialNoise; } } } else { // Work out above ground density if (y == groundHeightInChunk) { density = m_HeightField[blockX, blockZ] - Mathf.Floor(m_HeightField[blockX, blockZ]); } } chunk.Blocks[blockXInChunk, y, blockZInChunk].m_Type = blockType; chunk.Blocks[blockXInChunk, y, blockZInChunk].m_Density = density; } }
private static float GetLowerGroundHeight(Chunk chunk, int blockX, int blockY, int blockXInChunk, int blockYInChunk, int worldDepthInBlocks) { int minimumGroundheight = worldDepthInBlocks / 4; int minimumGroundDepth = (int)(worldDepthInBlocks * 0.5f); float octave1 = PerlinSimplexNoise.noise(blockX * 0.0001f, blockY * 0.0001f) * 0.5f; float octave2 = PerlinSimplexNoise.noise(blockX * 0.0005f, blockY * 0.0005f) * 0.35f; float octave3 = PerlinSimplexNoise.noise(blockX * 0.02f, blockY * 0.02f) * 0.15f; float lowerGroundHeight = octave1 + octave2 + octave3; lowerGroundHeight = lowerGroundHeight * minimumGroundDepth + minimumGroundheight; for (int z = (int)lowerGroundHeight; z >= 0; z--) { chunk.Blocks[blockXInChunk, blockYInChunk, z].Type = BlockType.Dirt; } return(lowerGroundHeight); }
public override void SetBrushSize(int radius) { brushRadius = radius; brushOffsets.Clear(); for (int i = 0; i < brushRadius * 2; i++) { for (int j = 0; j < brushRadius * 2; j++) { float num = Vector2.Distance(new Vector2((float)i, (float)j), new Vector2((float)brushRadius, (float)brushRadius)); if (num < (float)brushRadius - 0.8f) { Vector2 vector = Grid.CellToXY(Grid.OffsetCell(currentCell, i, j)); float num2 = PerlinSimplexNoise.noise(vector.x / settings.NoiseDensity, vector.y / settings.NoiseDensity, Time.realtimeSinceStartup); if (settings.NoiseScale <= num2) { brushOffsets.Add(new Vector2((float)(i - brushRadius), (float)(j - brushRadius))); } } } } }
private void AddDecor(int x, int y, float z_offset, Bits connection_bits, Color colour, List <Vector3> vertices, List <Vector2> uvs, List <TriangleInfo> triangles, List <Color> colours) { for (int i = 0; i < decorInfo.decor.Length; i++) { BlockTileDecorInfo.Decor decor = decorInfo.decor[i]; if (decor.variants != null && decor.variants.Length != 0) { bool flag = (connection_bits & decor.requiredConnections) == decor.requiredConnections; bool flag2 = (connection_bits & decor.forbiddenConnections) != (Bits)0; if (flag && !flag2) { float num = PerlinSimplexNoise.noise((float)(i + x + connection_bits) * simplex_scale.x, (float)(i + y + connection_bits) * simplex_scale.y); if (!(num < decor.probabilityCutoff)) { int num2 = (int)((float)(decor.variants.Length - 1) * num); int count = vertices.Count; Vector3 b = new Vector3((float)x, (float)y, z_offset) + decor.variants[num2].offset; Vector3[] vertices2 = decor.variants[num2].atlasItem.vertices; foreach (Vector3 a in vertices2) { vertices.Add(a + b); colours.Add(colour); } uvs.AddRange(decor.variants[num2].atlasItem.uvs); int[] indices = decor.variants[num2].atlasItem.indices; for (int k = 0; k < indices.Length; k += 3) { triangles.Add(new TriangleInfo { sortOrder = decor.sortOrder, i0 = indices[k] + count, i1 = indices[k + 1] + count, i2 = indices[k + 2] + count }); } } } } } }
private float[,] m_HeightField; // heightfield for landscape // Initialise the worldbuilder by creating a heightfield public override void Init(WorldData world) { m_HeightField = new float[world.WorldSizeBlocks.x, world.WorldSizeBlocks.z]; int worldHeightInBlocks = world.WorldSizeBlocks.y; int minimumGroundheight = worldHeightInBlocks / 4; int groundheightRange = (int)(worldHeightInBlocks * 0.75f); for (int blockX = 0; blockX < world.WorldSizeBlocks.x; blockX++) { for (int blockZ = 0; blockZ < world.WorldSizeBlocks.z; blockZ++) { float octave1 = PerlinSimplexNoise.noise(blockX * 0.0001f, blockZ * 0.0001f) * 0.5f; float octave2 = PerlinSimplexNoise.noise(blockX * 0.0005f, blockZ * 0.0005f) * 0.25f; float octave3 = PerlinSimplexNoise.noise(blockX * 0.005f, blockZ * 0.005f) * 0.12f; float octave4 = PerlinSimplexNoise.noise(blockX * 0.01f, blockZ * 0.01f) * 0.12f; float octave5 = PerlinSimplexNoise.noise(blockX * 0.03f, blockZ * 0.03f) * octave4; float lowerGroundHeight = octave1 + octave2 + octave3 + octave4 + octave5; lowerGroundHeight = (lowerGroundHeight * groundheightRange) + minimumGroundheight; m_HeightField[blockX, blockZ] = lowerGroundHeight; } } }
private void GenerateStandardTerrain(Chunk chunk, int x, int y, int blockX, int blockY, int worldDepthInBlocks, int noiseBlockOffset) { int groundHeight = (int)GetBlockNoise(blockX, blockY); if (groundHeight < 1) { groundHeight = 1; } else if (groundHeight > 128) { groundHeight = 96; } // Default to sunlit.. for caves bool sunlit = true; BlockType blockType = BlockType.Air; chunk.Blocks[x, y, groundHeight].Type = BlockType.TopSoil; chunk.Blocks[x, y, 0].Type = BlockType.Stone; for (int z = worldDepthInBlocks - 1; z > 0; z--) { if (z > groundHeight) { blockType = BlockType.Air; } // Or we at or below ground height? else if (z < groundHeight) { // Since we are at or below ground height, let's see if we need to make // a cave int noiseX = (blockX + noiseBlockOffset); float octave1 = PerlinSimplexNoise.noise(noiseX * 0.009f, blockY * 0.009f, z * 0.009f) * 0.25f; float initialNoise = octave1 + PerlinSimplexNoise.noise(noiseX * 0.04f, blockY * 0.04f, z * 0.04f) * 0.15f; initialNoise += PerlinSimplexNoise.noise(noiseX * 0.08f, blockY * 0.08f, z * 0.08f) * 0.05f; if (initialNoise > 0.2f) { blockType = BlockType.Air; } else { // We've placed a block of dirt instead...nothing below us will be sunlit if (sunlit) { sunlit = false; blockType = BlockType.TopSoil; chunk.TopSoilBlocks.Add(new IntVect(blockX, blockY, z)); } else { blockType = BlockType.Dirt; if (octave1 < 0.2f) { blockType = BlockType.Stone; } } } } chunk.Blocks[x, y, z].Type = blockType; } }
private void render() { { var color1 = new Vector3(0.8f, 0.8f, 0.8f); var color2 = new Vector3(0.7f, 0.7f, 0.7f); var screenAABB = Camera.mainCamera.worldBounds; var wx0 = Math.Floor(screenAABB.X0 / tileSize); var wx1 = Math.Ceiling(screenAABB.X1 / tileSize); var wy0 = Math.Floor(screenAABB.Y0 / tileSize); var wy1 = Math.Ceiling(screenAABB.Y1 / tileSize); var minX = (int)Math.Max(0, wx0); var maxX = (int)Math.Min(_width.Number, wx1); var minY = (int)Math.Max(0, wy0); var maxY = (int)Math.Min(_height.Number, wy1); for (var y = minY; y < maxY; y++) { for (var x = minX; x < maxX; x++) { //var map = getTile(x, y); var r = getTileRect(x, y); //var p = r.Minimum; //var c = color1.Lerp(color2, z / 10f); //if (shadowmap[x, y]) // c *= 0.9f; var texture = _open; var color = Color.Black; switch (tiles[x, y].tileType) { case MapTileType.Blocked: texture = _blocked; break; case MapTileType.Room: texture = _room; color = new Color(color1.Lerp(color2, (1 + PerlinSimplexNoise.noise(x * 0.5f, y * 0.5f)) / 2)); break; case MapTileType.Wall: texture = _wall; color = new Color(0.2f, 0.2f, 0.2f); break; } Root.instance.graphics.Draw(0, texture, r, color, 0); //if (z == heights[x, y] - 1) //{ // if (((x + 1 < size && heights[x + 1, y] > heights[x, y]))) // Root.instance.graphics.Draw(0, _shadow_hort, _material, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, z + 0.1f); // if (((y - 1 >= 0 && heights[x, y - 1] > heights[x, y]))) // Root.instance.graphics.Draw(0, _shadow_vert, _material, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, z + 0.1f); // if (((x - 1 >= 0 && heights[x - 1, y] > heights[x, y]))) // Root.instance.graphics.Draw(0, _shadow_hort, _material, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, SpriteEffects.FlipHorizontally, z + 0.1f); // if (((y + 1 < size && heights[x, y + 1] > heights[x, y]))) // Root.instance.graphics.Draw(0, _shadow_vert, _material, AxisAlignedBox.FromRect(p, tileSize, tileSize), Color.White, SpriteEffects.FlipVertically, z + 0.1f); //} //if ((x - 1 < 0 || heights[x - 1, y] < heights[x, y]) && z == heights[x, y] - 1) //{ // Root.instance.graphics.DrawLine(0, null, null, new Vector2(x * tileSize, y * tileSize - z * tileHeight), new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight), Color.Black, z + 0.1f); //} //if ((x + 1 >= size || heights[x + 1, y] < heights[x, y]) && z == heights[x, y] - 1) //{ // Root.instance.graphics.DrawLine(0, null, null, new Vector2((x + 1) * tileSize, y * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight), Color.Black, z + 0.1f); //} //if ((y - 1 < 0 || heights[x, y - 1] < heights[x, y]) && z == heights[x, y] - 1) //{ // Root.instance.graphics.DrawLine(0, null, null, new Vector2(x * tileSize, y * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, y * tileSize - z * tileHeight), Color.Black, z + 0.1f); //} //if ((y + 1 >= size || heights[x, y + 1] < heights[x, y]) && z == heights[x, y] - 1) //{ // Root.instance.graphics.DrawLine(0, null, null, new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight), Color.Black, z + 0.1f); //} //if ((x - 1 < 0 || heights[x - 1, y] < z + 1) && (y + 1 >= size || heights[x, y + 1] < z + 1)) // Root.instance.graphics.DrawLine(0, null, null, new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight), new Vector2(x * tileSize, (y + 1) * tileSize - z * tileHeight + tileHeight), Color.Black, z + 0.1f); //if ((x + 1 >= size || heights[x + 1, y] < z + 1) && (y + 1 >= size || heights[x, y + 1] < z + 1)) // Root.instance.graphics.DrawLine(0, null, null, new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight), new Vector2((x + 1) * tileSize, (y + 1) * tileSize - z * tileHeight + tileHeight), Color.Black, z + 0.1f); } } //Root.instance.graphics.DrawRect(1, null, null, AxisAlignedBox.FromDimensions(Vector2.One * 250, Vector2.One * 25), Color.Pink); } //{ // var go = Root.instance.RootObject.find("player"); // var physics = go.getScript<Physics>(); // var screenAABB = physics.shape; // var wx0 = Math.Floor(screenAABB.X0 / tileSize); // var wx1 = Math.Ceiling(screenAABB.X1 / tileSize); // var wy0 = Math.Floor(screenAABB.Y0 / tileSize); // var wy1 = Math.Ceiling(screenAABB.Y1 / tileSize); // var minX = (int)Math.Max(0, wx0); // var maxX = (int)Math.Min(_width.Number, wx1); // var minY = (int)Math.Max(0, wy0); // var maxY = (int)Math.Min(_height.Number, wy1 ); // var hs = tileSize * Game.WORLD_SCALE * Vector2.One; // var aabb = AxisAlignedBox.FromRect(Vector2.Zero, hs); // var mtv = MinimumTranslationVector.Zero; // for (var y = minY; y < maxY; y++) // { // for (var x = minX; x < maxX; x++) // { // if (tiles[x, y].tileType != MapTileType.Room) // { // aabb.Center = new Vector2(x, y) * tileSize * Game.WORLD_SCALE + hs / 2; // Root.instance.graphics.DrawRect(1, null, null, aabb, Color.Green); // } // } // } //} }
public void GenerateTerrain(WorldData worldData, Chunk chunk, int noiseBlockOffset) { int chunkBlockX = chunk.X * worldData.ChunkBlockWidth; int chunkBlockY = chunk.Y * worldData.ChunkBlockHeight; for (int x = 0; x < worldData.ChunkBlockWidth; x++) { int blockX = chunkBlockX + x; for (int y = 0; y < worldData.ChunkBlockHeight; y++) { int blockY = chunkBlockY + y; float lowerGroundHeight = GetLowerGroundHeight(chunk, blockX, blockY, x, y, worldData.DepthInBlocks, noiseBlockOffset); int groundHeight = GetUpperGroundHeight(worldData, blockX, blockY, lowerGroundHeight, noiseBlockOffset); bool sunlit = true; for (int z = worldData.DepthInBlocks - 1; z >= 0; z--) { // Everything above ground height...is air. BlockType blockType; if (z > groundHeight) { blockType = BlockType.Air; } // Are we above the lower ground height? else if (z > lowerGroundHeight) { // Let's see about some caves er valleys! float octave1 = PerlinSimplexNoise.noise(blockX * 0.01f, blockY * 0.01f, z * 0.01f) * (0.015f * z) + 0.1f; float caveNoise = octave1 + PerlinSimplexNoise.noise(blockX * 0.01f, blockY * 0.01f, z * 0.1f) * 0.06f + 0.1f; caveNoise += PerlinSimplexNoise.noise(blockX * 0.2f, blockY * 0.2f, z * 0.2f) * 0.03f + 0.01f; // We have a cave, draw air here. if (caveNoise > 0.2f) { blockType = BlockType.Air; } else { if (sunlit) { blockType = BlockType.TopSoil; chunk.TopSoilBlocks.Add(new IntVect(blockX, blockY, z)); sunlit = false; } else { blockType = BlockType.Dirt; if (caveNoise < 0.2f) { blockType = BlockType.Stone; } } } } else { // We are at the lower ground level if (sunlit) { blockType = BlockType.TopSoil; chunk.TopSoilBlocks.Add(new IntVect(blockX, blockY, z)); sunlit = false; } else { blockType = BlockType.Dirt; } } chunk.Blocks[x, y, z].Type = blockType; } } } }
private static float GetStaticRandom(int x, int y) { return(PerlinSimplexNoise.noise((float)x * NoiseScale.x, (float)y * NoiseScale.y)); }