Cogs.Core
OctComponent.h
1#pragma once
2
3
4#include "Resources/Resources.h"
5#include "Components/Core/RenderComponent.h"
6
7#include "Foundation/Geometry/BoundingBox.hpp"
8#include "Foundation/Memory/MemoryBuffer.h"
9
10#include <set>
11#include <vector>
12
13namespace Cogs
14{
15 namespace Core
16 {
17 namespace Volumetric
18 {
21 typedef uint64_t TileKey;
22
23 inline TileKey createTileKey(const glm::u16vec4& ix4, const glm::i16vec3& alignMinToZeroShift)
24 {
25 return (uint64_t(ix4.w) << 48)
26 | (uint64_t(uint16_t((ix4.z << ix4.w) + alignMinToZeroShift.z)) << 32)
27 | (uint64_t(uint16_t((ix4.y << ix4.w) + alignMinToZeroShift.y)) << 16)
28 | uint64_t(uint16_t((ix4.x << ix4.w) + alignMinToZeroShift.x));
29 }
30
32 typedef uint64_t RegionKey;
33
34
36 {
37 TileKey tileKey;
38 unsigned staleness;
39 };
40
42 {
43 TileKey tileKey;
44 size_t layoutHash;
45 uint32_t timestamp;
46 glm::vec3 min;
47 glm::vec3 max;
48 glm::uvec3 N;
49 std::set<RegionKey> regionKeys;
52 uint64_t clientData;
53 };
54
55 struct Region
56 {
57 RegionKey regionKey;
58 glm::vec3 min;
59 glm::vec3 max;
60 };
61
62 enum struct OctSource
63 {
64 Value,
65 ValueAge
66 };
67
68
70 {
71 bool forceWipe = false;
72 float tolerance = 0.1f;
73 glm::vec3 blockShift = glm::vec3(0.f);
74 glm::vec3 blockExtent = glm::vec3(1.f);
75
76
77 float valueMin = 0.f;
78 float valueMax = 1.f;
79 float turbidity = 100.f;
80 float ageScale = 0.1f;
81
82 uint32_t tileSize = 64u;
83 uint32_t gpuCacheSize = 5u; // Number of tiles along one dimension.
84
85 OctSource source = OctSource::Value;
86
87 TextureHandle transferTexture;
88
89 struct {
90 float(*func)(void* data, uint64_t clientData) = nullptr;
91 void* data = nullptr;
92 } alphaCallback;
93
95 bool clearAllRegions = false;
96
97 bool drawDebug = false;
98
100 std::vector<Region> regionsToAdd;
101
103 std::vector<RegionKey> regionsToRemove;
104
106 std::vector<TileRequest> tileRequests;
107
108 TileResponse* initTileResponse(const TileRequest* req);
109
110 void submitTileResponse(TileResponse* res, bool success);
111
112
113 struct OctSystem* system;
114
115 static void registerType();
116
117 };
118
119 }
120 }
121}
122
123template<> inline Cogs::StringView getName<Cogs::Core::Volumetric::OctComponent>() { return "VolOctComponent"; }
Base class for Component instances.
Definition: Component.h:143
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
bool clearAllRegions
If set to true, all current regions are discarded before regionsToAdd is processed.
Definition: OctComponent.h:95
std::vector< RegionKey > regionsToRemove
Set of regions to remove. Blocks with no regions are purged from the oct-tree.
Definition: OctComponent.h:103
float tolerance
Requested refinement tolerance, may be somewhat ignored when atlas size is insufficient.
Definition: OctComponent.h:72
glm::vec3 blockShift
Object space grid origin, tweak if block boundaries happen at unfortunate places.
Definition: OctComponent.h:73
bool forceWipe
Discard all processed data, but regions persist.
Definition: OctComponent.h:71
std::vector< TileRequest > tileRequests
Requests for tiles, populated by OctSystem::update, consumed by provider.
Definition: OctComponent.h:106
std::vector< Region > regionsToAdd
Regions to add this frame. It is OK to add a region multiple times, and this will invalidate regions ...
Definition: OctComponent.h:100
glm::vec3 max
Object space max corner of region bounding box.
Definition: OctComponent.h:59
RegionKey regionKey
User-defined key to keep track of regions.
Definition: OctComponent.h:57
glm::vec3 min
Object space min corner of region bounding box.
Definition: OctComponent.h:58
glm::uvec3 N
Number of samples expected along each dimension (total=N^3).
Definition: OctComponent.h:48
uint64_t clientData
Passed along to alpha-callback.
Definition: OctComponent.h:52
glm::vec3 max
Tile world-space bounding box max corner.
Definition: OctComponent.h:47
glm::vec3 min
Tile world-space bounding box min corner.
Definition: OctComponent.h:46
std::set< RegionKey > regionKeys
Regions present in that tile.
Definition: OctComponent.h:49