public void Init(Device device, DeviceContext dc, Terrain terrain) { _device = device; NumPatchVertRows = ((terrain.Info.HeightMapHeight - 1) / Terrain.CellsPerPatch) + 1; NumPatchVertCols = ((terrain.Info.HeightMapWidth - 1) / Terrain.CellsPerPatch) + 1; _numPatchVertices = NumPatchVertRows * NumPatchVertCols; _numPatchQuadFaces = (NumPatchVertRows - 1) * (NumPatchVertCols - 1); if (device.FeatureLevel == FeatureLevel.Level_11_0) { _useTessellation = true; } if (terrain.Info.Material.HasValue) { _material = terrain.Info.Material.Value; } D3DApp.GD3DApp.ProgressUpdate.Draw(0.60f, "Building terrain patches"); if (_useTessellation) { CalcAllPatchBoundsY(); BuildQuadPatchVB(device); BuildQuadPatchIB(device); } else { BuildPatches(device); } D3DApp.GD3DApp.ProgressUpdate.Draw(0.65f, "Loading textures"); _heightMapSRV = terrain.HeightMap.BuildHeightmapSRV(device); var layerFilenames = new List <string> { terrain.Info.LayerMapFilename0 ?? "textures/null.bmp", terrain.Info.LayerMapFilename1 ?? "textures/null.bmp", terrain.Info.LayerMapFilename2 ?? "textures/null.bmp", terrain.Info.LayerMapFilename3 ?? "textures/null.bmp", terrain.Info.LayerMapFilename4 ?? "textures/null.bmp" }; _layerMapArraySRV = Util.CreateTexture2DArraySRV(device, dc, layerFilenames.ToArray(), Format.R8G8B8A8_UNorm); if (!string.IsNullOrEmpty(terrain.Info.BlendMapFilename)) { D3DApp.GD3DApp.ProgressUpdate.Draw(0.70f, "Loading blendmap from file"); _blendMapSRV = ShaderResourceView.FromFile(device, terrain.Info.BlendMapFilename); _blendMapSRV.Resource.DebugName = terrain.Info.BlendMapFilename; } else { _blendMapSRV = CreateBlendMap(terrain.HeightMap, device, terrain); } if (DebugQuadTree) { D3DApp.GD3DApp.ProgressUpdate.Draw(0.95f, "Building quadtree debug vertex buffers"); BuildQuadTreeDebugBuffers(device); } D3DApp.GD3DApp.ProgressUpdate.Draw(1.0f, "Terrain initialized"); _walkMap = new WalkMap(this); }
public void Init(Device device, DeviceContext dc, Terrain terrain) { _device = device; NumPatchVertRows = ((terrain.Info.HeightMapHeight - 1) / Terrain.CellsPerPatch) + 1; NumPatchVertCols = ((terrain.Info.HeightMapWidth - 1) / Terrain.CellsPerPatch) + 1; _numPatchVertices = NumPatchVertRows * NumPatchVertCols; _numPatchQuadFaces = (NumPatchVertRows - 1) * (NumPatchVertCols - 1); if (device.FeatureLevel == FeatureLevel.Level_11_0) { _useTessellation = true; } if (terrain.Info.Material.HasValue) { _material = terrain.Info.Material.Value; } D3DApp.GD3DApp.ProgressUpdate.Draw(0.60f, "Building terrain patches"); if (_useTessellation) { CalcAllPatchBoundsY(); BuildQuadPatchVB(device); BuildQuadPatchIB(device); } else { BuildPatches(device); } D3DApp.GD3DApp.ProgressUpdate.Draw(0.65f, "Loading textures"); _heightMapSRV = terrain.HeightMap.BuildHeightmapSRV(device); var layerFilenames = new List<string> { terrain.Info.LayerMapFilename0 ?? "textures/null.bmp", terrain.Info.LayerMapFilename1 ?? "textures/null.bmp", terrain.Info.LayerMapFilename2 ?? "textures/null.bmp", terrain.Info.LayerMapFilename3 ?? "textures/null.bmp", terrain.Info.LayerMapFilename4 ?? "textures/null.bmp" }; _layerMapArraySRV = Util.CreateTexture2DArraySRV(device, dc, layerFilenames.ToArray(), Format.R8G8B8A8_UNorm); if (!string.IsNullOrEmpty(terrain.Info.BlendMapFilename)) { D3DApp.GD3DApp.ProgressUpdate.Draw(0.70f, "Loading blendmap from file"); _blendMapSRV = ShaderResourceView.FromFile(device, terrain.Info.BlendMapFilename); _blendMapSRV.Resource.DebugName = terrain.Info.BlendMapFilename; } else { _blendMapSRV = CreateBlendMap(terrain.HeightMap, device, terrain); } if (DebugQuadTree) { D3DApp.GD3DApp.ProgressUpdate.Draw(0.95f, "Building quadtree debug vertex buffers"); BuildQuadTreeDebugBuffers(device); } D3DApp.GD3DApp.ProgressUpdate.Draw(1.0f, "Terrain initialized"); _walkMap = new WalkMap(this); }