refactor and fix

This commit is contained in:
MihailRis
2025-02-26 02:24:16 +03:00
parent 5cb119cc4c
commit 64fd5d7504
+51 -102
View File
@@ -1,16 +1,16 @@
#include "PrecipitationRenderer.hpp" #include "PrecipitationRenderer.hpp"
#include "MainBatch.hpp"
#include "assets/Assets.hpp" #include "assets/Assets.hpp"
#include "assets/assets_util.hpp" #include "assets/assets_util.hpp"
#include "graphics/core/Shader.hpp" #include "graphics/core/Shader.hpp"
#include "graphics/core/Texture.hpp" #include "graphics/core/Texture.hpp"
#include "lighting/Lightmap.hpp" #include "lighting/Lightmap.hpp"
#include "maths/util.hpp" #include "maths/util.hpp"
#include "settings.hpp"
#include "voxels/Chunks.hpp"
#include "window/Camera.hpp" #include "window/Camera.hpp"
#include "world/Level.hpp" #include "world/Level.hpp"
#include "voxels/Chunks.hpp"
#include "MainBatch.hpp"
#include "settings.hpp"
PrecipitationRenderer::PrecipitationRenderer( PrecipitationRenderer::PrecipitationRenderer(
const Assets& assets, const Assets& assets,
@@ -28,7 +28,7 @@ PrecipitationRenderer::PrecipitationRenderer(
PrecipitationRenderer::~PrecipitationRenderer() = default; PrecipitationRenderer::~PrecipitationRenderer() = default;
int PrecipitationRenderer::getHeightAt(int x, int z) { int PrecipitationRenderer::getHeightAt(int x, int z) {
int y = CHUNK_H-1; int y = CHUNK_H - 1;
while (y > 0) { while (y > 0) {
if (auto voxel = chunks.get({x, y, z})) { if (auto voxel = chunks.get({x, y, z})) {
if (voxel->id == 0) { if (voxel->id == 0) {
@@ -77,104 +77,53 @@ void PrecipitationRenderer::render(const Camera& camera, float delta) {
float scale = 0.4f; float scale = 0.4f;
int quads = 0; int quads = 0;
float k = 21.41149; float k = 21.41149;
for (int lx = -radius; lx <= radius; lx++) {
for (int lz = -depth; lz < 0; lz++) { const struct {
glm::vec4 light = light_at(chunks, x + lx, y, z + lz); glm::vec3 right;
random.setSeed(lx + x, lz + z); glm::vec3 front;
float hspeed = (random.randFloat() * 2.0f - 1.0f) * horizontal; } faces[] {
glm::vec3 pos { {{-1, 0, 0}, {0, 0, 1}},
x + lx + 0.5f, {{1, 0, 0}, {0, 0, -1}},
glm::max(y - size.y / 2, getHeightAt(x + lx, z + lz)) + size.y / 2 + 1, {{0, 0, -1}, {-1, 0, 0}},
z + lz + 0.5f}; {{0, 0, 1}, {1, 0, 0}},
batch->quad( };
pos,
{1, 0, 0}, for (const auto& face : faces) {
{0, 1, 0}, for (int lx = -radius; lx <= radius; lx++) {
size, for (int lz = depth; lz > 0; lz--) {
light, glm::vec3 pos = face.right * static_cast<float>(lx) +
glm::vec3(1.0f), face.front * static_cast<float>(lz);
UVRegion( pos += glm::vec3(x, 0, z);
(lx + x) * scale + timer * hspeed, pos.y = glm::max(y - size.y / 2, getHeightAt(pos.x, pos.z)) +
timer + y * scale + (z + lz) * k, size.y / 2 + 1;
(lx + x + 1) * scale + timer * hspeed, pos += glm::vec3(0.5f, 0.0f, 0.5f);
timer + (size.y + y) * scale + (z + lz) * k
) float m = glm::sign(face.right.x + face.right.z);
); int ux = pos.x;
} int uz = pos.z;
}
for (int lx = -radius; lx <= radius; lx++) { if (glm::abs(face.right.x) < glm::abs(face.right.z)) {
for (int lz = depth; lz > 0; lz--) { std::swap(ux, uz);
glm::vec4 light = light_at(chunks, x + lx, y, z + lz); }
random.setSeed(lx + x, lz + z);
float hspeed = (random.randFloat() * 2.0f - 1.0f) * horizontal; glm::vec4 light = light_at(chunks, pos.x, y, pos.z);
glm::vec3 pos { random.setSeed(uz);
x + lx + 0.5f, float hspeed = (random.randFloat() * 2.0f - 1.0f) * horizontal;
glm::max(y - size.y / 2, getHeightAt(x + lx, z + lz)) + size.y / 2 + 1, batch->quad(
z + lz + 0.5f}; pos,
batch->quad( face.right,
pos, {0, 1, 0},
{-1, 0, 0}, size,
{0, 1, 0}, light,
size, glm::vec3(1.0f),
light, UVRegion(
glm::vec3(1.0f), ux * scale + timer * hspeed * -m,
UVRegion( timer + pos.y * scale + uz * k,
(lx + x) * scale + timer * hspeed, (ux + m) * scale + timer * hspeed * -m,
timer + y * scale + (z + lz) * k, timer + (size.y + pos.y) * scale + uz * k
(lx + x + 1) * scale + timer * hspeed, )
timer + (size.y + y) * scale + (z + lz) * k );
) }
);
}
}
for (int lz = -radius; lz <= radius; lz++) {
for (int lx = -depth; lx < 0; lx++) {
glm::vec4 light = light_at(chunks, x + lx, y, z + lz);
random.setSeed(lx + x, lz + z);
float hspeed = (random.randFloat() * 2.0f - 1.0f) * horizontal;
glm::vec3 pos {
x + lx + 0.5f,
glm::max(y - size.y / 2, getHeightAt(x + lx, z + lz)) + size.y / 2 + 1,
z + lz + 0.5f};
batch->quad(
pos,
{0, 0, -1},
{0, 1, 0},
size,
light,
glm::vec3(1.0f),
UVRegion(
(lz + z) * scale + timer * hspeed,
timer + y * scale + (x + lx) * k,
(lz + z + 1) * scale + timer * hspeed,
timer + (size.y + y) * scale + (x + lx) * k
)
);
}
}
for (int lz = -radius; lz <= radius; lz++) {
for (int lx = depth; lx > 0; lx--) {
glm::vec4 light = light_at(chunks, x + lx, y, z + lz);
random.setSeed(lx + x, lz + z);
float hspeed = (random.randFloat() * 2.0f - 1.0f) * horizontal;
glm::vec3 pos {
x + lx + 0.5f,
glm::max(y - size.y / 2, getHeightAt(x + lx, z + lz)) + size.y / 2 + 1,
z + lz + 0.5f};
batch->quad(
pos,
{0, 0, 1},
{0, 1, 0},
size,
light,
glm::vec3(1.0f),
UVRegion(
(lz + z) * scale + timer * hspeed,
timer + y * scale + (x + lx) * k,
(lz + z + 1) * scale + timer * hspeed,
timer + (size.y + y) * scale + (x + lx) * k
)
);
} }
} }
batch->flush(); batch->flush();