public void AutoPaint(HeightMap heightMap, NormalMap normalMap, Vector3 mousePosition) { if (normalMap.HasChanged) { normalMap.UpdateNormalArray(); } var normals = normalMap.Normals; var textureChanges = new bool[TerrainConfig.Textures.Length]; var pos = ((mousePosition.Xz / Map.MapData.MapSize) + new Vector2(0.5f)) * size; var radius = (int)(State.ToolRadius * size / Map.MapData.MapSize); for (var z = (int)(pos.Y - radius); z < pos.Y + radius; z++) { for (var x = (int)(pos.X - radius); x < pos.X + radius; x++) { if (Vector2.Distance(pos, new Vector2(x, z)) < State.ToolRadius / 2.0f) { autoPaintPixel(ref textureChanges, normals, heightMap, x, z); } } } for (var i = 0; i < TerrainConfig.Textures.Length; i++) { if (textureChanges[i]) { ToTexture(i); } } }
public void AutoPaint(HeightMap heightMap, NormalMap normalMap) { if (normalMap.HasChanged) { normalMap.UpdateNormalArray(); } var normals = normalMap.Normals; var textureChanges = new bool[TerrainConfig.Textures.Length]; for (var z = 0; z < size; z++) { for (var x = 0; x < size; x++) { autoPaintPixel(ref textureChanges, normals, heightMap, x, z); } } for (var i = 0; i < TerrainConfig.Textures.Length; i++) { if (textureChanges[i]) { ToTexture(i); } } }
public HeightMap(NormalMap normalMap) { this.normalMap = normalMap; size = (int)(Map.MapData.MapSize * TerrainConfig.HeightMapDetail); Heights = new float[size, size]; for (var x = 0; x < size; x++) { for (var z = 0; z < size; z++) { Heights[x, z] = 1.0f / TerrainConfig.HeightMapScale; } } Update(); }
public TerrainRenderer(Camera camera) { this.camera = camera; shader = new RenderShader(); shadowShader = new ShadowShader(); quadTree = new TerrainQuadTree(); worldTransform = Matrix4.CreateScale(Map.MapData.MapSize) * Matrix4.CreateTranslation(-Map.MapData.MapSize / 2.0f, 0.0f, -Map.MapData.MapSize / 2.0f); texture = new Texture(); textureNoise = new TextureNoise(12312234); NormalMap = new NormalMap(); HeightMap = new HeightMap(NormalMap); SplatMap = new SplatMap(); picker = new TerrainPicker(camera, HeightMap); loadTextures(); build(); Update(); }