add particles lighting

This commit is contained in:
MihailRis
2024-11-03 02:23:37 +03:00
parent b944f257f7
commit 7abb1a88c7
10 changed files with 66 additions and 26 deletions
+22 -8
View File
@@ -8,16 +8,20 @@
#include "window/Camera.hpp"
#include "world/Level.hpp"
#include "voxels/Chunks.hpp"
#include "settings.hpp"
size_t ParticlesRenderer::visibleParticles = 0;
size_t ParticlesRenderer::aliveEmitters = 0;
ParticlesRenderer::ParticlesRenderer(const Assets& assets, const Level& level)
: batch(std::make_unique<MainBatch>(1024)), level(level) {
auto region = util::get_texture_region(assets, "blocks:bazalt", "");
emitters.push_back(std::make_unique<Emitter>(glm::vec3(0, 100, 0), Particle {
nullptr, glm::vec3(), glm::vec3(), 5.0f, region.region
ParticlesRenderer::ParticlesRenderer(
const Assets& assets, const Level& level, const GraphicsSettings* settings
)
: batch(std::make_unique<MainBatch>(1024)),
level(level),
settings(settings) {
auto region = util::get_texture_region(assets, "blocks:grass_top", "");
emitters.push_back(std::make_unique<Emitter>(glm::vec3(0, 80, 0), Particle {
nullptr, 0, glm::vec3(), glm::vec3(), 5.0f, region.region
},region.texture, 0.002f, -1));
}
@@ -42,6 +46,9 @@ void ParticlesRenderer::renderParticles(const Camera& camera, float delta) {
const auto& right = camera.right;
const auto& up = camera.up;
const auto& chunks = *level.chunks;
bool backlight = settings->backlight.get();
std::vector<const Texture*> unusedTextures;
for (auto& [texture, vec] : particles) {
@@ -57,14 +64,21 @@ void ParticlesRenderer::renderParticles(const Camera& camera, float delta) {
while (iter != vec.end()) {
auto& particle = *iter;
update_particle(particle, delta, *level.chunks);
update_particle(particle, delta, chunks);
glm::vec4 light(1, 1, 1, 0);
if (particle.emitter->behaviour.lighting) {
light = MainBatch::sampleLight(
particle.position, chunks, backlight
);
light *= 0.7f + (particle.random % 300) * 0.001f;
}
batch->quad(
particle.position,
right,
up,
glm::vec2(0.3f),
glm::vec4(1),
light,
glm::vec3(1.0f),
particle.region
);