OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
lightgroup.h
Go to the documentation of this file.
1#pragma once
2
3#include <Tempest/CommandBuffer>
4#include <unordered_set>
5#include <zenkit/vobs/Light.hh>
6
7#include "lightsource.h"
8#include "resources.h"
9
10class DbgPainter;
11class SceneGlobals;
12class World;
13
14class LightGroup final {
15 public:
16 LightGroup(const SceneGlobals& scene);
17
18 class Light final {
19 public:
20 Light() = default;
21 Light(Light&& other);
22 Light& operator = (Light&& other);
23 ~Light();
24
25 void setPosition(float x, float y, float z);
26 void setPosition(const Tempest::Vec3& p);
27
28 void setEnabled(bool e);
29
30 void setRange (float r);
31 void setColor (const Tempest::Vec3& c);
32 void setColor (const std::vector<Tempest::Vec3>& c, float fps, bool smooth);
33 void setTimeOffset(uint64_t t);
34
35 uint64_t effectPrefferedTime() const;
36
37 private:
38 Light(LightGroup& l, size_t id):owner(&l), id(id) {}
39 LightGroup* owner = nullptr;
40 size_t id = 0;
41
42 friend class LightGroup;
43 };
44
45 Light add(const zenkit::LightPreset& vob);
46 Light add(const zenkit::VLight& vob);
47 Light add(std::string_view preset);
48 size_t size() const { return lightSourceData.size(); }
49
50 void tick(uint64_t time);
51 bool updateLights();
52 auto& lightsSsbo() const { return lightSourceSsbo; }
53
54 void prepareGlobals(Tempest::Encoder<Tempest::CommandBuffer> &cmd, uint8_t fId);
55
56 void dbgLights(DbgPainter& p) const;
57
58 private:
59 using Vertex = Resources::VertexL;
60
61 struct Path {
62 uint32_t dst;
63 uint32_t src;
64 uint32_t size;
65 };
66
67 struct LightSsbo {
68 Tempest::Vec3 pos;
69 float range = 0;
70 Tempest::Vec3 color;
71 float pading = 0;
72 };
73
74 struct VsmSsbo {
75 uint32_t mask[6];
76 };
77
78 size_t alloc(bool dynamic);
79 void free(size_t id);
80
81 void markAsDurty(size_t id);
82 void markAsDurtyNoSync(size_t id);
83 void resetDurty();
84
85 const zenkit::LightPreset& findPreset(std::string_view preset) const;
86
87 std::vector<zenkit::LightPreset> presets;
88
89 std::mutex sync;
90 std::vector<size_t> freeList;
91 std::vector<LightSource> lightSourceDesc;
92 std::vector<LightSsbo> lightSourceData;
93 std::unordered_set<size_t> animatedLights;
94 std::vector<uint32_t> duryBit;
95
96 Tempest::StorageBuffer lightSourceSsbo;
97 Tempest::StorageBuffer patchSsbo[Resources::MaxFramesInFlight];
98 };
99
uint64_t effectPrefferedTime() const
Light & operator=(Light &&other)
void setColor(const std::vector< Tempest::Vec3 > &c, float fps, bool smooth)
void setColor(const Tempest::Vec3 &c)
void setEnabled(bool e)
void setPosition(const Tempest::Vec3 &p)
void setRange(float r)
void setTimeOffset(uint64_t t)
void setPosition(float x, float y, float z)
auto & lightsSsbo() const
Definition lightgroup.h:52
size_t size() const
Definition lightgroup.h:48
bool updateLights()
Light add(const zenkit::LightPreset &vob)
void prepareGlobals(Tempest::Encoder< Tempest::CommandBuffer > &cmd, uint8_t fId)
void dbgLights(DbgPainter &p) const
void tick(uint64_t time)
@ MaxFramesInFlight
Definition resources.h:48
Definition world.h:31