3 #include <BLIB/Cameras/2D/Camera2D.hpp>
4 #include <BLIB/Util/Random.hpp>
34 angle = bl::util::Random::get<float>(0.f, 2.f * bl::math::Pi);
35 angularVelocity = bl::math::degreesToRadians(bl::util::Random::get<float>(560.f, 820.f));
37 scale = bl::util::Random::get<float>(0.75f, 1.2f);
78 struct RenderConfigMap<
Sand> {
80 static constexpr
bool ContainsTransparency =
true;
82 static constexpr
bool CreateRenderPipeline =
true;
84 static constexpr std::initializer_list<std::uint32_t> RenderPassIds =
85 bl::pcl::RenderConfigDefaults<Sand>::RenderPassIds;
89 bl::pcl::RenderConfigDescriptorList<bl::rc::ds::TexturePoolFactory,
90 bl::rc::ds::Scene2DFactory,
91 bl::pcl::DescriptorSetFactory<Sand, Sand>>;
93 static constexpr
bool EnableDepthTesting =
true;
94 static constexpr VkPrimitiveTopology Topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
95 static constexpr
const char* VertexShader =
"Resources/Shaders/Particles/sand.vert.spv";
96 static constexpr
const char* FragmentShader =
97 bl::rc::Config::ShaderIds::Fragment2DRotatedParticle;
103 static constexpr
bool ContainsTransparency =
true;
105 static constexpr
bool CreateRenderPipeline =
true;
107 static constexpr std::initializer_list<std::uint32_t> RenderPassIds =
108 bl::pcl::RenderConfigDefaults<Swirl>::RenderPassIds;
112 bl::pcl::RenderConfigDescriptorList<bl::rc::ds::TexturePoolFactory,
113 bl::rc::ds::Scene2DFactory,
114 bl::pcl::DescriptorSetFactory<Swirl, GpuSwirl>>;
116 static constexpr
bool EnableDepthTesting =
true;
117 static constexpr VkPrimitiveTopology Topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
118 static constexpr
const char* VertexShader =
"Resources/Shaders/Particles/sandSwirl.vert.spv";
119 static constexpr
const char* FragmentShader =
120 bl::rc::Config::ShaderIds::Fragment2DRotatedParticle;
133 constexpr glm::vec2 SandVelocity(-1100.f * 0.8f, 345.f * 0.8f);
134 constexpr glm::vec2 SwirlVelocity(-680.f, 325.f);
135 constexpr
float MaxAlpha = 230.f / 256.f;
136 constexpr
float SwirlRatio = 0.5f;
137 constexpr
float AlphaRate = 85.f / 256.f;
138 constexpr
unsigned int SwirlCount = 40;
140 float computeAlpha(
float current,
float target,
float dt) {
141 const float rate = target > current ? AlphaRate : -AlphaRate;
142 const float na = current + rate * dt;
143 if (na < 0.f)
return 0.f;
144 if (na > 1.f)
return 1.f;
145 if (na > target && target > current)
return target;
159 virtual void update(Proxy& proxy, std::span<Sand> particles,
float,
float)
override {
162 for (
Sand& p : particles) { proxy.destroy(p); }
177 , prevArea(1.f, 1.f, 1.f, 1.f) {}
181 virtual void update(Proxy& proxy,
float,
float)
override {
182 bl::cam::Camera2D* cam = observer.getCurrentCamera<bl::cam::Camera2D>();
183 if (!cam) {
return; }
184 const sf::FloatRect area = cam->getVisibleArea();
186 if (proxy.getManager().getParticleCount() > 0) {
187 const float dx = area.width / prevArea.width;
188 const float dy = area.height / prevArea.height;
189 if (dx >= 1.25f || dy >= 1.25f) {
194 else { prevArea = area; }
198 bl::rc::RenderTarget& observer;
200 sf::FloatRect prevArea;
209 : observer(observer) {}
213 virtual void update(Proxy& proxy,
float dt,
float)
override {
214 bl::cam::Camera2D* cam = observer.getCurrentCamera<bl::cam::Camera2D>();
215 if (!cam) {
return; }
216 const sf::FloatRect area = cam->getVisibleArea();
218 const float leftBound = area.left + area.width * 0.5f -
wrapWidth * 0.5f;
219 const float rightBound = leftBound +
wrapWidth;
220 const float topBound = area.top + area.height * 0.5f -
wrapHeight * 0.5f;
221 const float bottomBound = topBound +
wrapHeight;
223 for (
Sand& s : proxy.particles()) {
224 s.pos += SandVelocity * dt;
225 if (s.pos.x < leftBound) { s.pos.x +=
wrapWidth; }
226 else if (s.pos.x > rightBound) { s.pos.x -=
wrapWidth; }
227 if (s.pos.y < topBound) { s.pos.y +=
wrapHeight; }
228 else if (s.pos.y > bottomBound) { s.pos.y -=
wrapHeight; }
233 bl::rc::RenderTarget& observer;
240 , txtrHalfSize(txtrSize / 1.6f) {}
244 virtual void update(Proxy& proxy,
float,
float)
override {
245 if (proxy.getManager().getParticleCount() == 0) {
246 bl::cam::Camera2D* cam = observer.getCurrentCamera<bl::cam::Camera2D>();
247 if (!cam) {
return; }
248 const sf::FloatRect area = cam->getVisibleArea();
250 const unsigned int width = std::ceil(area.width * 2.f / txtrHalfSize.x);
251 const unsigned int height = std::ceil(area.height * 2.f / txtrHalfSize.y);
253 wrapWidth =
static_cast<float>(width) * txtrHalfSize.x;
254 wrapHeight =
static_cast<float>(height) * txtrHalfSize.y;
255 const glm::vec2 corner(area.left + area.width * 0.5f -
wrapWidth * 0.5f,
256 area.top + area.height * 0.5f -
wrapHeight * 0.5f);
258 for (
unsigned int x = 0; x < width; ++x) {
259 for (
unsigned int y = 0; y < height; ++y) {
260 const glm::vec2 pos(x, y);
261 proxy.emit(corner + txtrHalfSize * pos);
268 bl::rc::RenderTarget& observer;
269 const glm::vec2 txtrHalfSize;
275 : observer(observer) {}
279 virtual void update(Proxy& proxy,
float dt,
float)
override {
280 bl::cam::Camera2D* cam = observer.getCurrentCamera<bl::cam::Camera2D>();
281 if (!cam) {
return; }
282 const sf::FloatRect area = cam->getVisibleArea();
284 const float leftBound = area.left - area.width * 0.5f;
285 const float rightBound = leftBound + area.width * 2.f;
286 const float topBound = area.top - area.height * 0.5f;
287 const float bottomBound = topBound + area.height * 2.f;
289 for (
Swirl& s : proxy.particles()) {
290 s.pos += SwirlVelocity * dt;
291 s.angle += s.angularVelocity * dt;
293 if (s.pos.x < leftBound || s.pos.y > bottomBound) {
294 s =
Swirl(bl::util::Random::get<float>(rightBound - 100.f, rightBound),
295 bl::util::Random::get<float>(topBound, bottomBound - 100.f));
301 bl::rc::RenderTarget& observer;
308 , txtrHalfSize(txtrSize / 1.6f) {}
312 virtual void update(Proxy& proxy,
float,
float)
override {
313 if (proxy.getManager().getParticleCount() == 0) {
314 bl::cam::Camera2D* cam = observer.getCurrentCamera<bl::cam::Camera2D>();
315 if (!cam) {
return; }
316 const sf::FloatRect area = cam->getVisibleArea();
317 const glm::vec2 corner(area.left - area.width * 0.5f, area.top - area.height * 0.5f);
318 const glm::vec2 otherCorner(corner + glm::vec2(area.width * 2.f, area.height * 2.f));
320 for (
unsigned int i = 0; i < SwirlCount; ++i) {
321 proxy.emit(bl::util::Random::get<float>(corner.x, otherCorner.x),
322 bl::util::Random::get<float>(corner.y, otherCorner.y));
328 bl::rc::RenderTarget& observer;
329 const glm::vec2 txtrHalfSize;
352 targetAlpha = MaxAlpha;
355 const auto sampler = e.renderer().vulkanState().samplerCache.noFilterBorderClamped();
366 sand->getRenderer().getGlobals().textureCenter =
367 sandTxtr->normalizeAndConvertCoord(sandTxtr->size() * 0.5f);
368 sand->getRenderer().getGlobals().textureId = sandTxtr.id();
369 sand->getRenderer().getGlobals().radius = glm::length(sandTxtr->size()) * 0.5f;
371 sand->addToScene(renderTarget.getCurrentScene());
372 sand->getRenderer().getComponent()->vertexBuffer.vertices()[0].pos.z = map.
getMinDepth() + 0.3f;
379 swirls->getRenderer().getGlobals().textureCenter =
380 swirlTxtr->normalizeAndConvertCoord(swirlTxtr->size() * 0.5f);
381 swirls->getRenderer().getGlobals().textureId = swirlTxtr.id();
382 swirls->getRenderer().getGlobals().radius = glm::length(swirlTxtr->size()) * 0.5f;
384 swirls->addToScene(renderTarget.getCurrentScene());
385 swirls->getRenderer().getComponent()->vertexBuffer.vertices()[0].pos.z = map.
getMinDepth();
391 if (alpha != targetAlpha) {
392 alpha = computeAlpha(alpha, targetAlpha, dt);
397 void Sandstorm::setAlpha() {
399 sand->getRenderer().getGlobals().alpha = alpha;
400 swirls->getRenderer().getGlobals().alpha = alpha * SwirlRatio;
Core classes and functionality for both the editor and game.
core::map::weather::sandstorm::GpuSwirl GpuSwirl
core::map::weather::fog::GlobalShaderInfo GlobalShaderInfo
core::map::weather::sandstorm::Swirl Swirl
core::map::weather::sandstorm::Sand Sand
The primary map class that represents a usable map in the game.
float getMinDepth() const
Returns the maximum depth possible for this map. Maximum is always 0.f. Minimum is negative,...
@ SandStorm
A sandstorm ravages you.
static const std::string & SandSwirlFile()
static const std::string & SandPatchFile()
static constexpr std::uint32_t SandstormSandPipelineId
static constexpr std::uint32_t SandstormSwirlPipelineId
Sand(const glm::vec2 &pos)
GpuSwirl & operator=(const Swirl &swirl)
bl::pcl::RenderConfigDescriptorList< bl::rc::ds::TexturePoolFactory, bl::rc::ds::Scene2DFactory, bl::pcl::DescriptorSetFactory< Sand, Sand > > DescriptorSets
bl::pcl::RenderConfigDescriptorList< bl::rc::ds::TexturePoolFactory, bl::rc::ds::Scene2DFactory, bl::pcl::DescriptorSetFactory< Swirl, GpuSwirl > > DescriptorSets
virtual ~SandSink()=default
virtual void update(Proxy &proxy, std::span< Sand > particles, float, float) override
virtual ~SandUpdater()=default
virtual void update(Proxy &proxy, float, float) override
SandUpdater(bl::rc::RenderTarget &observer, SandSink &sink)
virtual void update(Proxy &proxy, float dt, float) override
SandAffector(bl::rc::RenderTarget &observer)
virtual ~SandAffector()=default
virtual void update(Proxy &proxy, float, float) override
virtual ~SandEmitter()=default
SandEmitter(bl::rc::RenderTarget &observer, glm::vec2 txtrSize)
virtual void update(Proxy &proxy, float dt, float) override
virtual ~SwirlAffector()=default
SwirlAffector(bl::rc::RenderTarget &observer)
virtual void update(Proxy &proxy, float, float) override
virtual ~SwirlEmitter()=default
SwirlEmitter(bl::rc::RenderTarget &observer, glm::vec2 txtrSize)
virtual bool stopped() const override
Returns true if the sandstorm is fully stopped, false if stopping.
virtual void update(float dt) override
Updates the sandstorm.
virtual void start(bl::engine::Engine &engine, bl::rc::RenderTarget &renderTarget, Map &map) override
Starts the sandstorm.
Sandstorm()
Creates the sandstorm.
virtual void stop() override
Stops the sandstorm.
virtual ~Sandstorm()
Destroy the Sandstorm object.
virtual Weather::Type type() const override
Returns Sandstorm.