OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
pfxbucket.h
Go to the documentation of this file.
1#pragma once
2
3#include <Tempest/VertexBuffer>
4#include <vector>
5#include <random>
6
8#include "resources.h"
9
10class ParticleFx;
11class VisualObjects;
12
13class PfxBucket {
14 public:
16
17 PfxBucket(const ParticleFx &decl, PfxObjects& parent, const SceneGlobals& scene, VisualObjects& visual);
18 ~PfxBucket();
19
26
27 struct ImplEmitter final {
29 size_t block = size_t(-1);
30
31 Tempest::Vec3 pos = {};
32 Tempest::Vec3 direction[3] = {{1,0,0}, {0,1,0}, {0,0,1}};
33 bool isLoop = false;
34
35 const Npc* targetNpc = nullptr;
36
37 const PfxEmitterMesh* mesh = nullptr;
38 const Pose* pose = nullptr;
39
40 uint64_t waitforNext = 0;
41 std::unique_ptr<PfxEmitter> next;
42 };
43
44 struct PfxState {
45 Tempest::Vec3 pos;
46 uint32_t color = 0;
47 Tempest::Vec3 size;
48 uint32_t bits0 = 0;
49 Tempest::Vec3 dir;
50 uint32_t colorB = 0;
51 };
52
55
56 bool isEmpty() const;
57
58 void preFrameUpdate(const SceneGlobals& scene, uint8_t fId);
59 void drawGBuffer (Tempest::Encoder<Tempest::CommandBuffer>& cmd, const SceneGlobals &scene, uint8_t fId);
60 void drawShadow (Tempest::Encoder<Tempest::CommandBuffer>& cmd, const SceneGlobals &scene, uint8_t fId, int layer);
61 void drawTranslucent(Tempest::Encoder<Tempest::CommandBuffer>& cmd, const SceneGlobals &scene, uint8_t fId);
62
63 size_t allocEmitter();
64 void freeEmitter(size_t& id);
65
66 ImplEmitter& get(size_t id) { return impl[id]; }
67 void tick(uint64_t dt, const Tempest::Vec3& viewPos);
68 void buildSsbo();
69
70 private:
71 enum UboLinkpackage : uint8_t {
72 L_Scene = 0,
73 L_Payload = 1,
74 L_Instance = 2,
75 L_Pfx = L_Instance,
76 L_Bucket = 3,
77 L_Ibo = 4,
78 L_Vbo = 5,
79 L_Diffuse = 6,
80 L_Sampler = 7,
81 L_Shadow0 = 8,
82 L_Shadow1 = 9,
83 L_MorphId = 10,
84 L_Morph = 11,
85 L_SceneClr = 12,
86 L_GDepth = 13,
87 };
88
89 struct Block final {
90 bool allocated = false;
91 uint64_t timeTotal = 0;
92
93 size_t offset = 0;
94 size_t count = 0;
95
96 Tempest::Vec3 pos = {};
97 };
98
99 struct Trail final {
100 Tempest::Vec3 pos;
101 uint64_t time = 0;
102 };
103
104 struct ParState final {
105 uint16_t life=0, maxLife=1;
106 Tempest::Vec3 pos, dir;
107
108 std::vector<Trail> trail;
109
110 float lifeTime() const;
111 };
112
113 struct Draw {
114 const Tempest::RenderPipeline* pMain = nullptr;
115 const Tempest::RenderPipeline* pShadow = nullptr;
116
117 Tempest::StorageBuffer pfxGpu;
118 uint64_t timeShift = 0;
119
120 bool isEmpty() const;
121 };
122
123 void drawCommon(Tempest::Encoder<Tempest::CommandBuffer>& cmd, const SceneGlobals &scene, const Draw& itm,
124 SceneGlobals::VisCamera view, Material::AlphaFunc func, bool trl);
125
126 void tickEmit(Block& p, ImplEmitter& emitter, uint64_t emited);
127 bool shrink();
128
129 size_t allocBlock();
130 void freeBlock(size_t& s);
131
132 static float randf();
133 static float randf(float base, float var);
134
135 Block& getBlock(ImplEmitter& emitter);
136 Block& getBlock(PfxEmitter& emitter);
137
138 void init (Block& block, ImplEmitter& emitter, size_t particle);
139 void finalize (size_t particle);
140 void tick (Block& sys, ImplEmitter& emitter, size_t particle, uint64_t dt);
141 void tickTrail(ParState& ps, ImplEmitter& emitter, uint64_t dt);
142
143 void implTickCommon(uint64_t dt, const Tempest::Vec3& viewPos);
144 void implTickDecals(uint64_t dt, const Tempest::Vec3& viewPos);
145
146 void buildSsboTrails();
147 void buildBilboard(PfxState& v, const Block& p, const ParState& ps, const uint32_t color,
148 float szX, float szY, float szZ);
149 void buildTrailSegment(PfxState& v, const Trail& a, const Trail& b, float maxT);
150 uint32_t mkTrailColor(float clA) const;
151
152 VisualObjects& visual;
153
155 std::vector<PfxState> pfxCpu;
156
157 Draw itemTrl[Resources::MaxFramesInFlight];
158 std::vector<PfxState> trlCpu;
159
160 uint64_t maxTrlTime = 0;
161 size_t blockSize = 0;
162
163 std::vector<ParState> particles;
164 std::vector<ImplEmitter> impl;
165 std::vector<Block> block;
166 bool forceUpdate[Resources::MaxFramesInFlight] = {};
167
168 static std::mt19937 rndEngine;
169
170 friend class PfxEmitter;
171 };
172
Definition npc.h:25
bool isEmpty() const
Definition pfxbucket.cpp:76
void preFrameUpdate(const SceneGlobals &scene, uint8_t fId)
void tick(uint64_t dt, const Tempest::Vec3 &viewPos)
void drawGBuffer(Tempest::Encoder< Tempest::CommandBuffer > &cmd, const SceneGlobals &scene, uint8_t fId)
void buildSsbo()
void freeEmitter(size_t &id)
PfxObjects & parent
Definition pfxbucket.h:54
const ParticleFx & decl
Definition pfxbucket.h:53
void drawShadow(Tempest::Encoder< Tempest::CommandBuffer > &cmd, const SceneGlobals &scene, uint8_t fId, int layer)
ImplEmitter & get(size_t id)
Definition pfxbucket.h:66
size_t allocEmitter()
void drawTranslucent(Tempest::Encoder< Tempest::CommandBuffer > &cmd, const SceneGlobals &scene, uint8_t fId)
Definition pose.h:16
@ MaxFramesInFlight
Definition resources.h:48
Tempest::Vec3 pos
Definition pfxbucket.h:31
Tempest::Vec3 direction[3]
Definition pfxbucket.h:32
const Npc * targetNpc
Definition pfxbucket.h:35
std::unique_ptr< PfxEmitter > next
Definition pfxbucket.h:41
const Pose * pose
Definition pfxbucket.h:38
const PfxEmitterMesh * mesh
Definition pfxbucket.h:37
Tempest::Vec3 size
Definition pfxbucket.h:47
Tempest::Vec3 pos
Definition pfxbucket.h:45
Tempest::Vec3 dir
Definition pfxbucket.h:49