Example #1
0
        internal Terrain(MapFile mapFile, AssetLoadContext loadContext)
        {
            Map = mapFile;

            HeightMap = new HeightMap(mapFile.HeightMapData);

            _graphicsDevice = loadContext.GraphicsDevice;

            _indexBufferCache = AddDisposable(new TerrainPatchIndexBufferCache(loadContext.GraphicsDevice));

            var tileDataTexture = AddDisposable(CreateTileDataTexture(
                                                    loadContext.GraphicsDevice,
                                                    mapFile,
                                                    HeightMap));

            var cliffDetailsBuffer = AddDisposable(CreateCliffDetails(
                                                       loadContext.GraphicsDevice,
                                                       mapFile));

            CreateTextures(
                loadContext,
                mapFile.BlendTileData,
                out var textureArray,
                out var textureDetails);

            var textureDetailsBuffer = AddDisposable(loadContext.GraphicsDevice.CreateStaticStructuredBuffer(textureDetails));

            var terrainPipeline = loadContext.ShaderResources.Terrain.Pipeline;

            _materialConstantsBuffer = AddDisposable(
                new ConstantBuffer <TerrainShaderResources.TerrainMaterialConstants>(
                    loadContext.GraphicsDevice, "TerrainMaterialConstants"));
            _materialConstantsBuffer.Value = new TerrainShaderResources.TerrainMaterialConstants
            {
                MapBorderWidth          = new Vector2(mapFile.HeightMapData.BorderWidth, mapFile.HeightMapData.BorderWidth) * HeightMap.HorizontalScale,
                MapSize                 = new Vector2(mapFile.HeightMapData.Width, mapFile.HeightMapData.Height) * HeightMap.HorizontalScale,
                IsMacroTextureStretched = mapFile.EnvironmentData?.IsMacroTextureStretched ?? false
            };
            _materialConstantsBuffer.Update(loadContext.GraphicsDevice);

            var macroTexture = loadContext.AssetStore.Textures.GetByName(mapFile.EnvironmentData?.MacroTexture ?? "tsnoiseurb.dds");

            RadiusCursorDecals = AddDisposable(new RadiusCursorDecals(loadContext.AssetStore, loadContext.GraphicsDevice));

            var casuticsTextures = BuildCausticsTextureArray(loadContext.AssetStore);

            _materialResourceSet = AddDisposable(loadContext.ShaderResources.Terrain.CreateMaterialResourceSet(
                                                     _materialConstantsBuffer.Buffer,
                                                     tileDataTexture,
                                                     cliffDetailsBuffer ?? loadContext.StandardGraphicsResources.GetNullStructuredBuffer(TerrainShaderResources.CliffInfo.Size),
                                                     textureDetailsBuffer,
                                                     textureArray,
                                                     macroTexture,
                                                     casuticsTextures));

            RadiusCursorDecalsResourceSet = AddDisposable(loadContext.ShaderResources.RadiusCursor.CreateRadiusCursorDecalsResourceSet(
                                                              RadiusCursorDecals.TextureArray,
                                                              RadiusCursorDecals.DecalConstants,
                                                              RadiusCursorDecals.DecalsBuffer));

            var cloudTexture = loadContext.AssetStore.Textures.GetByName(mapFile.EnvironmentData?.CloudTexture ?? "tscloudmed.dds");

            var cloudResourceLayout = AddDisposable(loadContext.GraphicsDevice.ResourceFactory.CreateResourceLayout(
                                                        new ResourceLayoutDescription(
                                                            new ResourceLayoutElementDescription("Global_CloudTexture", ResourceKind.TextureReadOnly, ShaderStages.Fragment))));

            CloudResourceSet = AddDisposable(loadContext.GraphicsDevice.ResourceFactory.CreateResourceSet(
                                                 new ResourceSetDescription(
                                                     cloudResourceLayout,
                                                     cloudTexture.Texture)));
            CloudResourceSet.Name = "Cloud resource set";

            _shaderSet = loadContext.ShaderResources.Terrain.ShaderSet;
            _pipeline  = terrainPipeline;

            OnHeightMapChanged();
        }
Example #2
0
 internal Bridge(
     AssetLoadContext loadContext,
     HeightMap heightMap,
     MapObject mapObject,
     in Vector3 startPosition,