Nebula
Loading...
Searching...
No Matches
terraincontext.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
9//------------------------------------------------------------------------------
12#include "math/bbox.h"
16#include "coregraphics/window.h"
17
18#include "jobs/jobs.h"
19
20#include "io/ioserver.h"
22
23namespace Terrain
24{
25
27
29{
33 float quadsPerTileX, quadsPerTileY; // vertex density is vertices per meter
34};
35
44
46{
47 Resources::ResourceName albedo = "tex:system/white.dds";
48 Resources::ResourceName normal = "tex:system/nobump.dds";
49 Resources::ResourceName material = "tex:system/default_material.dds";
50};
51
53{
56 {
57 this->material.albedo = name.IsValid() ? name : "tex:system/white.dds";
58 return *this;
59 }
60
63 {
64 this->material.normal = name.IsValid() ? name : "tex:system/nobump.dds";
65 return *this;
66 }
67
70 {
71 this->material.material = name.IsValid() ? name : "tex:system/default_material.dds";
72 return *this;
73 }
74
77 {
78 return this->material;
79 }
80private:
82};
83
85{
87 {
88 Flat, // Material to use on flat surfaces
89 Slope, // Material to use on slanted surfaces
90 Height, // Material to use for surfaces high up
91 HeightSlope, // Material to sue for high up on slanted surface
92
94 };
98};
99
101{
102private:
115
118
119public:
120
123 {
124 this->bits |= BuilderBits::SettingsBit;
125 this->settings.biomeParameters = settings;
126 return *this;
127 }
128
131 {
132 this->bits |= BuilderBits::FlatMaterialBit;
133 this->settings.materials[BiomeSettings::BiomeMaterialLayer::Flat] = material;
134 return *this;
135 }
136
139 {
140 this->bits |= BuilderBits::SlopeMaterialBit;
141 this->settings.materials[BiomeSettings::BiomeMaterialLayer::Slope] = material;
142 return *this;
143 }
144
147 {
148 this->bits |= BuilderBits::HeightMaterialBit;
149 this->settings.materials[BiomeSettings::BiomeMaterialLayer::Height] = material;
150 return *this;
151 }
152
155 {
158 return *this;
159 }
160
163 {
164 this->bits |= BuilderBits::BiomeMask;
165 this->settings.biomeMask = mask.IsValid() ? mask : "tex:system/white.dds";
166 return *this;
167 }
168
171 {
172 n_assert_msg(this->bits & AllBits, "BiomeSettinsBuilder: All fields must be set before calling finish");
173 return this->settings;
174 }
175};
176
183
185{
186 NoChange, // subtexture remains the same
187 Deleted, // subtexture went to 0 tiles
188 Created, // subtexture was 0 tiles but grew
189 Grew, // subtexture grew to more tiles
190 Shrank // subtexture shrank
191};
192
202
204{
206public:
207
211 virtual ~TerrainContext();
212
214 static void Create(const TerrainSetupSettings& settings);
216 static void Discard();
217
219 static void SetupTerrain(
220 const Graphics::GraphicsEntityId entity,
221 const Resources::ResourceName& heightMap,
222 const Resources::ResourceName& decisionMap,
223 bool enableRayTracing);
224
227
229 static void SetBiomeSlopeThreshold(TerrainBiomeId id, float threshold);
231 static void SetBiomeHeightThreshold(TerrainBiomeId id, float threshold);
232
234 static void SetSun(const Graphics::GraphicsEntityId sun);
235
237 static void CullPatches(const Ptr<Graphics::View>& view, const Graphics::FrameContext& ctx);
239 static void UpdateLOD(const Ptr<Graphics::View>& view, const Graphics::FrameContext& ctx);
241 static void RenderUI(const Graphics::FrameContext& ctx);
243 static void ClearCache();
244
246 static void SetVisible(bool visible);
248 static bool GetVisible();
249
250#ifndef PUBLIC_DEBUG
252 static void OnRenderDebug(uint32_t flags);
253#endif
254
255private:
256
262
296
297 enum
298 {
301 };
302
303 typedef Ids::IdAllocator<
304 TerrainLoadInfo,
305 TerrainRuntimeInfo
308
309 enum
310 {
314 };
315
316 typedef Ids::IdAllocator<
318 uint32_t
321
325 static void Dealloc(Graphics::ContextEntityId id);
326};
327
328} // namespace Terrain
Definition graphicscontext.h:165
An ID allocator associates an id with a slice in an N number of arrays.
Definition idallocator.h:39
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Definition terraincontext.h:204
static void SetupTerrain(const Graphics::GraphicsEntityId entity, const Resources::ResourceName &heightMap, const Resources::ResourceName &decisionMap, bool enableRayTracing)
setup new terrain surface from texture and settings
Definition terraincontext.cc:1178
static void Dealloc(Graphics::ContextEntityId id)
deallocate a slice
Definition terraincontext.cc:2570
static Graphics::ContextEntityId Alloc()
allocate a new slice for this context
Definition terraincontext.cc:2561
static void CullPatches(const Ptr< Graphics::View > &view, const Graphics::FrameContext &ctx)
cull terrain patches
Definition terraincontext.cc:1668
static void Discard()
destroy terrain context
Definition terraincontext.cc:1165
static void SetBiomeHeightThreshold(TerrainBiomeId id, float threshold)
set biome height threshold
Definition terraincontext.cc:1650
static void SetBiomeSlopeThreshold(TerrainBiomeId id, float threshold)
set biome slope threshold
Definition terraincontext.cc:1641
TerrainContext()
constructor
Definition terraincontext.cc:261
@ TerrainBiome_MaskTexture
Definition terraincontext.h:313
@ TerrainBiome_Index
Definition terraincontext.h:312
@ TerrainBiome_Settings
Definition terraincontext.h:311
static TerrainAllocator terrainAllocator
Definition terraincontext.h:307
static void SetVisible(bool visible)
Definition terraincontext.cc:2422
static void SetSun(const Graphics::GraphicsEntityId sun)
Set the sun entity for terrain shadows.
Definition terraincontext.cc:1659
static void OnRenderDebug(uint32_t flags)
debug rendering
Definition terraincontext.cc:2541
Ids::IdAllocator< TerrainLoadInfo, TerrainRuntimeInfo > TerrainAllocator
Definition terraincontext.h:306
static bool GetVisible()
Definition terraincontext.cc:2413
virtual ~TerrainContext()
destructor
Definition terraincontext.cc:268
@ Terrain_RuntimeInfo
Definition terraincontext.h:300
@ Terrain_LoadInfo
Definition terraincontext.h:299
static TerrainBiomeAllocator terrainBiomeAllocator
Definition terraincontext.h:320
static void RenderUI(const Graphics::FrameContext &ctx)
render IMGUI
Definition terraincontext.cc:2431
static void UpdateLOD(const Ptr< Graphics::View > &view, const Graphics::FrameContext &ctx)
update sparse texture mips
Definition terraincontext.cc:2104
Ids::IdAllocator< BiomeSettings, uint32_t > TerrainBiomeAllocator
Definition terraincontext.h:319
static void Create(const TerrainSetupSettings &settings)
create terrain context
Definition terraincontext.cc:276
static TerrainBiomeId CreateBiome(const BiomeSettings &settings)
setup a new biome
Definition terraincontext.cc:1548
static void ClearCache()
clear the tile cache (use when we need to force update the terrain)
Definition terraincontext.cc:2532
Nebula's dynamic array class.
Definition array.h:60
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
A StringAtom.
Definition stringatom.h:22
bool IsValid() const
return true if valid (contains a non-empty string)
Definition stringatom.h:353
#define n_assert_msg(exp, msg)
Definition debug.h:52
#define ID_32_TYPE(x)
Definition id.h:16
The occupancy quad tree implements a tree which allows for a quick search.
Definition occupancyquadtree.h:15
Graphics::GraphicsEntityId sun
Definition terraincontext.cc:89
TerrainSetupSettings settings
Definition terraincontext.cc:70
SubTextureUpdateState
Definition terraincontext.h:185
A resource table declares a list of resources (ResourceTable in DX12, DescriptorSet in Vulkan)
Definition buffer.h:23
Definition graphicscontext.h:133
Definition graphicsserver.h:31
The graphics entity is only an Id, to which we can attach GraphicsContexts.
Definition graphicsentity.h:16
Definition scalar.h:112
Definition terraincontext.h:53
BiomeMaterial Finish()
Finish.
Definition terraincontext.h:76
BiomeMaterialBuilder & Albedo(const Resources::ResourceName &name)
Set albedo.
Definition terraincontext.h:55
BiomeMaterialBuilder & Normal(const Resources::ResourceName &name)
Set normal.
Definition terraincontext.h:62
BiomeMaterial material
Definition terraincontext.h:81
BiomeMaterialBuilder & Material(const Resources::ResourceName &name)
Set material.
Definition terraincontext.h:69
Definition terraincontext.h:46
Resources::ResourceName albedo
Definition terraincontext.h:47
Resources::ResourceName material
Definition terraincontext.h:49
Resources::ResourceName normal
Definition terraincontext.h:48
Definition terraincontext.h:37
float slopeThreshold
Definition terraincontext.h:38
bool useMaterialWeights
Definition terraincontext.h:41
float uvScaleFactor
Definition terraincontext.h:40
Resources::ResourceName weights
Definition terraincontext.h:42
float heightThreshold
Definition terraincontext.h:39
Definition terraincontext.h:101
BiomeSettings settings
Definition terraincontext.h:117
BiomeSettings Finish()
Finish.
Definition terraincontext.h:170
BiomeSettingsBuilder & Mask(const Resources::ResourceName &mask)
Builder for biome mask.
Definition terraincontext.h:162
BiomeSettingsBuilder & HeightSlopeMaterial(const BiomeMaterial &material)
Builder for height slope material.
Definition terraincontext.h:154
BuilderBits
Definition terraincontext.h:104
@ HeightSlopeMaterialBit
Definition terraincontext.h:110
@ HeightMaterialBit
Definition terraincontext.h:109
@ SlopeMaterialBit
Definition terraincontext.h:108
@ AllBits
Definition terraincontext.h:113
@ SettingsBit
Definition terraincontext.h:106
@ FlatMaterialBit
Definition terraincontext.h:107
@ BiomeMask
Definition terraincontext.h:111
@ NoBits
Definition terraincontext.h:105
BiomeSettingsBuilder & FlatMaterial(const BiomeMaterial &material)
Builder for flat material.
Definition terraincontext.h:130
BiomeSettingsBuilder & HeightMaterial(const BiomeMaterial &material)
Builder for height material.
Definition terraincontext.h:146
uint8 bits
Definition terraincontext.h:116
BiomeSettingsBuilder & Parameters(const BiomeParameters &settings)
Builder for settings.
Definition terraincontext.h:122
BiomeSettingsBuilder & SlopeMaterial(const BiomeMaterial &material)
Builder for slope material.
Definition terraincontext.h:138
Definition terraincontext.h:85
Resources::ResourceName biomeMask
Definition terraincontext.h:97
BiomeParameters biomeParameters
Definition terraincontext.h:95
BiomeMaterial materials[BiomeMaterialLayer::NumLayers]
Definition terraincontext.h:96
BiomeMaterialLayer
Definition terraincontext.h:87
@ Height
Definition terraincontext.h:90
@ Flat
Definition terraincontext.h:88
@ Slope
Definition terraincontext.h:89
@ NumLayers
Definition terraincontext.h:93
@ HeightSlope
Definition terraincontext.h:91
Definition terraincontext.h:194
SubTextureUpdateState updateState
Definition terraincontext.h:200
Math::uint2 oldCoord
Definition terraincontext.h:199
uint oldMaxMip
Definition terraincontext.h:197
IndexT index
Definition terraincontext.h:195
uint oldTiles
Definition terraincontext.h:196
float mipBias
Definition terraincontext.h:198
uint newMaxMip
Definition terraincontext.h:197
uint newTiles
Definition terraincontext.h:196
Definition terraincontext.h:178
uint maxMip
Definition terraincontext.h:180
uint physicalTileSize
Definition terraincontext.h:181
uint subTextureWorldSize
Definition terraincontext.h:179
Definition terraincontext.h:26
Definition terraincontext.h:258
float minHeight
Definition terraincontext.h:260
float maxHeight
Definition terraincontext.h:260
Resources::ResourceName texture
Definition terraincontext.h:259
Definition terraincontext.h:264
uint loadBits
Definition terraincontext.h:287
Util::Array< CoreGraphics::PrimitiveGroup > sectorPrimGroups
Definition terraincontext.h:266
Resources::ResourceId heightMap
Definition terraincontext.h:280
Util::FixedArray< CoreGraphics::ResourceTableId > patchTables
Definition terraincontext.h:291
Resources::ResourceId decisionMap
Definition terraincontext.h:281
Util::Array< Math::bbox > sectionBoxes
Definition terraincontext.h:265
bool enableRayTracing
Definition terraincontext.h:289
CoreGraphics::BufferId ibo
Definition terraincontext.h:294
Util::Array< Util::FixedArray< uint > > sectorTileOffsets
Definition terraincontext.h:269
CoreGraphics::BufferId vbo
Definition terraincontext.h:293
uint numTilesX
Definition terraincontext.h:278
Util::Array< Math::float2 > sectorUv
Definition terraincontext.h:271
Util::Array< bool > sectorVisible
Definition terraincontext.h:267
uint tileHeight
Definition terraincontext.h:279
Util::Array< bool > sectorUpdateTextureTile
Definition terraincontext.h:273
Util::Array< Math::uint3 > sectorAllocatedTile
Definition terraincontext.h:274
Util::Array< Util::FixedArray< uint > > sectorUniformOffsets
Definition terraincontext.h:268
Util::Array< float > sectorLod
Definition terraincontext.h:272
float worldWidth
Definition terraincontext.h:276
float maxHeight
Definition terraincontext.h:277
float worldHeight
Definition terraincontext.h:276
uint tileWidth
Definition terraincontext.h:279
float minHeight
Definition terraincontext.h:277
TextureLoadBits
Definition terraincontext.h:283
@ DecisionMapLoaded
Definition terraincontext.h:285
@ HeightMapLoaded
Definition terraincontext.h:284
uint lowresGenerated
Definition terraincontext.h:288
uint numTilesY
Definition terraincontext.h:278
Util::Array< Math::uint2 > sectorTextureTileSize
Definition terraincontext.h:270
Definition terraincontext.h:29
float tileHeight
Definition terraincontext.h:32
float quadsPerTileY
Definition terraincontext.h:33
float worldSizeX
Definition terraincontext.h:31
float worldSizeZ
Definition terraincontext.h:31
float quadsPerTileX
Definition terraincontext.h:33
float minHeight
Definition terraincontext.h:30
float tileWidth
Definition terraincontext.h:32
float maxHeight
Definition terraincontext.h:30
uint8_t uint8
Definition types.h:42
unsigned int uint
Definition types.h:31
int IndexT
Definition types.h:48