public HeightmapRenderer(WorldRenderer In, HeightMap For) { _in = In; _for = For; _p2d = new Perlin2D(100); _renchunks = new RenderChunk[NUM_RENDER_CHUNKS] []; for (int i = 0; i < _renchunks.Length; ++i) { _renchunks [i] = new RenderChunk[NUM_RENDER_CHUNKS]; } }
public RenderChunk(HeightMap In, Perlin2D PColor, int CX, int CY, int Level) { _lod = Level; _cx = CX; _cy = CY; List<Vertex> verts = new List<Vertex>(); List<Vertex> wverts = new List<Vertex>(); List<ushort> indicies = new List<ushort>(); List<ushort> windicies = new List<ushort>(); BuildGround(In, verts, indicies); if (_water) BuildWater(In, wverts, windicies); uint[] tmp = new uint[2]; GL.GenBuffers(2, tmp); _buffer = tmp [0]; _wbuffer = tmp [1]; //Vertex Data GL.BindBuffer(BufferTarget.ArrayBuffer, _buffer); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(verts.Count * Vertex.Size), verts.ToArray(), BufferUsageHint.StaticDraw); //Water vertex data GL.BindBuffer(BufferTarget.ArrayBuffer, _wbuffer); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(wverts.Count * Vertex.Size), wverts.ToArray(), BufferUsageHint.StaticDraw); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); #region Texture generation _tex = GLUtil.CreateTexture(GenGroundTexture(PColor)); if (_water) _wtex = GLUtil.CreateTexture(GenWaterTexture(PColor)); #endregion _indicies = indicies.ToArray(); if (_water) _windicies = windicies.ToArray(); }
public IslandGenerator(Perlin2D Perlin) { _p2d = Perlin; }
public HeightMap(string FName) { Perlin2D p2d = new Perlin2D(100); this._cache = new ChunkCache(new IslandGenerator(p2d)); }
float Octaves(Perlin2D P, float X, float Y, int Num) { double total = 0; for (int i = 0; i < Num; ++i) { double freq = Math.Pow(2, i); double ampl = Math.Pow(0.5, i); double per = P [X * freq, Y * freq]; per = (per - 0.5) * 2; total += per * ampl; } return (float)Math.Abs(total); }
Bitmap GenWaterTexture(Perlin2D C) { return GenTexture(C, Color.Blue, Color.BlueViolet, 0.5f); }
Bitmap GenTexture(Perlin2D C, Color C1, Color C2, float Scale) { Bitmap bm = new Bitmap(_lod * 2, _lod * 2); for (int x = 0; x < bm.Width; ++x) { int xp = _cx * CHUNK_SIZE + x; for (int y = 0; y < bm.Height; ++y) { int yp = _cy * CHUNK_SIZE + y; float f = Octaves(C, xp * Scale, yp * Scale, 4); if (f > 1) f = 1; Color c = Mix(C1, C2, f); bm.SetPixel(x, y, c); } } return bm; }
Bitmap GenGroundTexture(Perlin2D C) { return GenTexture(C, Color.Green, Color.Yellow, 0.1f); }